I am trying Google Cloud's Text-to-Speech using REST. It works fine while using Google's API explorer.
But when I try to make a post call, it returns the following error (The API key I'm using has no restrictions):
{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"{\r\n \"audioConfig\": {\r\n \"audioEncoding\": \"MP3\"\r\n },\r\n \"input\": {\r\n \"text\": \"This is a text to speak\"\r\n },\r\n \"voice\": {\r\n \"languageCode\": \"en-US\",\r\n \"name\": \"en-US-Standard-B\"\r\n }\r\n}\": Cannot bind query parameter. Field '{\r\n \"audioConfig\": {\r\n \"audioEncoding\": \"MP3\"\r\n },\r\n \"input\": {\r\n \"text\": \"This is a text to speak\"\r\n },\r\n \"voice\": {\r\n \"languageCode\": \"en-US\",\r\n \"name\": \"en-US-Standard-B\"\r\n }\r\n}' could not be found in request message.",
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"description": "Invalid JSON payload received. Unknown name \"{\r\n \"audioConfig\": {\r\n \"audioEncoding\": \"MP3\"\r\n },\r\n \"input\": {\r\n \"text\": \"This is a text to speak\"\r\n },\r\n \"voice\": {\r\n \"languageCode\": \"en-US\",\r\n \"name\": \"en-US-Standard-B\"\r\n }\r\n}\": Cannot bind query parameter. Field '{\r\n \"audioConfig\": {\r\n \"audioEncoding\": \"MP3\"\r\n },\r\n \"input\": {\r\n \"text\": \"This is a text to speak\"\r\n },\r\n \"voice\": {\r\n \"languageCode\": \"en-US\",\r\n \"name\": \"en-US-Standard-B\"\r\n }\r\n}' could not be found in request message."
}
]
}
]
}
}
Request body:
{
"audioConfig": {
"audioEncoding": "MP3"
},
"input": {
"text": "This is a text to speak"
},
"voice": {
"languageCode": "en-US",
"name": "en-US-Standard-B"
}
}
Post link: https://texttospeech.googleapis.com/v1beta1/text:synthesize?fields=audioContent&key={MY_API_KEY}