Speech recognition google语音识别ajax调用中的400错误请求错误 google语音识别ajax调用中的400错误请求错误
我收到响应消息,因为收到了无效的JSON负载。未知名称“配置[编码]”:无法绑定查询参数。在请求消息中找不到字段“config[encoding]”。接收到无效的JSON负载。未知名称“config[languageCode]”:无法绑定查询参数。在请求消息中找不到字段“config[languageCode]”。接收到无效的JSON负载。未知名称“音频[内容]”:无法绑定查询参数。在请求消息中找不到字段“音频[内容]”。接收到无效的JSON负载。未知名称“config[sampleRateHertz]”:无法绑定查询参数。在请求消息中找不到字段“config[sampleRateHertz]”。 但是相同的JSON负载和带有令牌密钥的URL在postman中运行良好Speech recognition google语音识别ajax调用中的400错误请求错误 google语音识别ajax调用中的400错误请求错误,speech-recognition,http-status-code-400,bad-request,Speech Recognition,Http Status Code 400,Bad Request,我收到响应消息,因为收到了无效的JSON负载。未知名称“配置[编码]”:无法绑定查询参数。在请求消息中找不到字段“config[encoding]”。接收到无效的JSON负载。未知名称“config[languageCode]”:无法绑定查询参数。在请求消息中找不到字段“config[languageCode]”。接收到无效的JSON负载。未知名称“音频[内容]”:无法绑定查询参数。在请求消息中找不到字段“音频[内容]”。接收到无效的JSON负载。未知名称“config[sampleRateHe
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");
}
});
});
});
使用acount()中的Google Cloud API密钥,尝试下面的代码,替换脚本中的API密钥:
$( document ).ready(function() {
// The settings for the Ajax Request
var settings = {
"async": true,
"crossDomain": true,
"url": "https://speech.googleapis.com/v1/speech:recognize",
"method": "POST",
"headers": {
"x-goog-api-key": "**your-api-key**",
"content-type": "application/json",
"cache-control": "no-cache",
},
"processData": false,
"data": "{'audio':{'content':'"+mainStringBuf+"'},'config': {'encoding':'FLAC','sampleRateHertz':'16000','languageCode':'en-US'}}"
}
// The Ajax Request, on success play the speech
$.ajax(settings).done(function (response) {
console.log(response);
});
});