Google 语音 API,选项 [phrases] 使用
Google Speech API, the option [phrases] using
我尝试使用 'phrases' 属性 添加额外的单词以供 Google API 识别。当我在我的请求中设置它们时,我收到一条错误消息。
我收到带有此错误的响应 400:"Invalid JSON payload received. Unknown name \"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."
}
]
}
]
}
}
我认为您需要将 speechContexts
参数作为 config
结构的一部分。负载应该看起来像这样:
{
"audio": {
"content": "UklGRiSWAABXQVZFZm10IBAAAAABAAEAQ...B8AAIA+AAACABAAZGF0YQCWAAAAAAAAA="
},
"config": {
"encoding": "LINEAR16",
"languageCode": "en-US",
"sampleRateHertz": "8000",
"speechContexts": {
"phrases": [
"borja"
]
}
}
}
我尝试使用 'phrases' 属性 添加额外的单词以供 Google API 识别。当我在我的请求中设置它们时,我收到一条错误消息。 我收到带有此错误的响应 400:"Invalid JSON payload received. Unknown name \"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."
}
]
}
]
}
}
我认为您需要将 speechContexts
参数作为 config
结构的一部分。负载应该看起来像这样:
{
"audio": {
"content": "UklGRiSWAABXQVZFZm10IBAAAAABAAEAQ...B8AAIA+AAACABAAZGF0YQCWAAAAAAAAA="
},
"config": {
"encoding": "LINEAR16",
"languageCode": "en-US",
"sampleRateHertz": "8000",
"speechContexts": {
"phrases": [
"borja"
]
}
}
}