我尝试使用'短语'添加额外字词以供Google API识别的属性。当我在请求中设置它们时,我收到一条错误消息。 我收到带有此错误的响应400:"收到无效的JSON有效负载。未知名称\" speech_contexts \":无法找到字段。",
有人知道为什么吗?
@ May 19 08:30:41.72, conn = 0, URL = https://speech.googleapis.com/v1/speech:recognize?key=xxx
POST /v1/speech:recognize?key=xxx HTTP/1.1
Accept: */*
Host: speech.googleapis.com
User-Agent: OpenVXI/3.0 (compatible; Linux x86_64; Debian GNU/Linux 8 (jessie); Asterisk 11.22.0; BORJA) Voximal/14.0b
Connection: keep-alive
Content-Length: 51427
Content-Type: application/json
{"audio": {"content" : "UklGRiSWAABXQVZFZm10IBAAAAABAAEAQ...B8AAIA+AAACABAAZGF0YQCWAA
AAAAAAA="} , "config": {"encoding" : "LINEAR16" , "languageCode" : "en-US" , "sampleRateHertz" : "8000"} , "speechContexts": {"phrases" : [ "borja" ]}}
@ May 19 08:30:41.83, conn = 0, URL = https://speech.googleapis.com/v1/speech:recognize?key=AIzaSyDsK4BVecut8hce-DtwVkZB54QvBz8vRvA
HTTP/1.1 400 Bad Request
Vary: X-Origin
Vary: Referer
Content-Type: application/json; charset=UTF-8
Date: Fri, 19 May 2017 08:30:41 GMT
Server: ESF
Cache-Control: private
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
Alt-Svc: quic=":443"; ma=2592000; v="37,36,35"
Accept-Ranges: none
Vary: Origin,Accept-Encoding
Transfer-Encoding: chunked
1c3
{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"speech_contexts\": Cannot find field.",
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"description": "Invalid JSON payload received. Unknown name \"speech_contexts\": Cannot find field."
}
]
}
]
}
}
答案 0 :(得分:1)
我认为您需要将speechContexts
参数作为config
结构的一部分。有效负载应该看起来像这样:
{
"audio": {
"content": "UklGRiSWAABXQVZFZm10IBAAAAABAAEAQ...B8AAIA+AAACABAAZGF0YQCWAAAAAAAAA="
},
"config": {
"encoding": "LINEAR16",
"languageCode": "en-US",
"sampleRateHertz": "8000",
"speechContexts": {
"phrases": [
"borja"
]
}
}
}