I'm trying to call the Google Cloud text-to-speech API from javascript based browser app. I'm getting this error response for my REST call:
error: Object { code: 400, message: "Empty language code.", status: "INVALID_ARGUMENT" }
the language code is correct according to the docs... i could be doing something else wrong if anyone can point me in the right direction? Here is my code:
const config = {
method: 'POST',
async: true,
crossDomain: true,
url: "https://texttospeech.googleapis.com/v1beta1/text:synthesize?fields=audioContent&key="+API_KEY,
headers: {
"x-goog-api-key": API_KEY,
"Content-Type": "application/json; charset=utf-8",
"cache-control": "no-cache"
},
processData: false,
data: {
'input':{
'text':'This is a text to speak'
},
'voice':{
'languageCode':'en-US',
'name':'en-US-Standard-B'
},
'audioConfig':{
'audioEncoding':'MP3'
}
}
}
let response = await window.fetch(config.url, config)
let data = await response.json()
console.log("got buffer", data)