Hi! I'm making a React Native app and want to fetch TTS data from the following endpoint: https://texttospeech.googleapis.com/v1beta1/text:synthesize
However, when I run my code, I get the following error: {"error": {"code": 400, "message": "Input type has to be text or SSML. Maybe the input is empty?", "status": "INVALID_ARGUMENT"}}
My code is below:
const API_KEY = "...";
const API_URL = `https://texttospeech.googleapis.com/v1beta1/text:synthesize?key=${API_KEY}`;
const speak = async (text) => {
try {
console.log("sup");
const response = await fetch(`${API_URL}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: {
input: {
text: "Hello world",
},
voice: {
languageCode: "en-US",
name: "en-US-Wavenet-A",
ssmlGender: "MALE",
},
audioConfig: {
audioEncoding: "MP3",
},
},
});
const result = await response.json();
console.log(result);
} catch (error) {
console.error("Error:", error);
}
};
As you can see, the input type is text. I've also tried changing the type to SSML, but with no luck (I get the same error). What can I do? Any help would be much appreciated!