Search code examples
google-speech-api

Google Speech API, the option [phrases] using


I try to use the 'phrases' property to add extra words to be recognized by the Google API. When I set them in my request, I receive an error message. I receive the response 400 with this error : "Invalid JSON payload received. Unknown name \"speech_contexts\": Cannot find field.",

Do someone know why ?

@ 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."
          }
        ]
      }
    ]
  }
}

Solution

  • I think you need to include the speechContexts argument as part of the config structure. The payload should look something like this instead:

    {
      "audio": {
        "content": "UklGRiSWAABXQVZFZm10IBAAAAABAAEAQ...B8AAIA+AAACABAAZGF0YQCWAAAAAAAAA="
      },
      "config": {
        "encoding": "LINEAR16",
        "languageCode": "en-US",
        "sampleRateHertz": "8000",
        "speechContexts": {
          "phrases": [
            "borja"
          ]
        }
      }
    }