400 неверный запрос запроса в Google Ajax Call для распознавания речи
Я получаю ответное сообщение как Invalid JSON payload received. Unknown name "config[encoding]": Cannot bind query parameter. Field 'config[encoding]' could not be found in request message. Invalid JSON payload received. Unknown name "config[languageCode]": Cannot bind query parameter. Field 'config[languageCode]' could not be found in request message. Invalid JSON payload received. Unknown name "audio[content]": Cannot bind query parameter. Field 'audio[content]' could not be found in request message. Invalid JSON payload received. Unknown name "config[sampleRateHertz]": Cannot bind query parameter. Field 'config[sampleRateHertz]' could not be found in request message.
Но та же полезная нагрузка JSON и URL с ключом токена отлично работает в почтальоне.
var jsonObjects ={ "audio": {
"content": mainStringBuf
},
"config": {
"encoding":"FLAC",
"sampleRateHertz":16000,
"languageCode":"en-US"
}
};
$(document).ready(function(){
$('#speechID').click(function(){
jQuery.ajax({
url: "https://speech.googleapis.com/v1/speech:recognize?key=myKey" ,
type: "POST",
data: jsonObjects,
dataType: "json",
beforeSend: function(x) {
if (x && x.overrideMimeType) {
x.overrideMimeType("Content-Type:application/json");
alert("beforeSend");
}
},
success: function(result) {
alert("result");
},
error: function(error){
alert("error");
}
});
});
});