Google Cloud Speech : "Invalid JSON payload received. Unknown name "speech_context" at 'config': Cannot find field."
See original GitHub issueSteps to reproduce
- The error occurs when recognize_google_cloud method is used with preferred_phrases parameter.
- Use the google cloud speech recognition like this,
r.recognize_google_cloud(audio, credentials_json=GOOGLE_CLOUD_SPEECH_CREDENTIALS,preferred_phrases=['hi, hello']))
Expected behaviour
The request should be processed successfully and the audio input from microphone should be recognized as text.
Actual behaviour
Received the following exception,
Could not request results from Google Cloud Speech service; <HttpError 400 when requesting https://speech.googleapis.com/v1/spee
ch:recognize?alt=json returned "Invalid JSON payload received. Unknown name "speech_context" at 'config': Cannot find field.">
I looked into the source of the recognize_google_cloud method,
if preferred_phrases is not None: speech_config["speechContext"] = {"phrases": preferred_phrases}
The key where preferred_phrases is included is given as speechContext, but when referred to official google cloud speech docs, its actually speechContexts. Below is the sample request json obtained from docs,
{ "config": { "encoding":"FLAC", "sampleRateHertz": 16000, "languageCode":"en-US", "speechContexts": { "phrases":["hoful","shwazil"] } }, "audio":{ "uri":"gs://speech-demo/shwazil_hoful.flac" } }
System information
My system is Windows 10 x64. My Python version is 3.6.4. My Pip version is 9.0.1
My SpeechRecognition library version is 3.8.1
My PyAudio library version is 0.2.11
My microphones are: [‘Microsoft Sound Mapper - Input’, ‘Microphone (Realtek Audio)’, ‘Microsoft Sound Mapper - Output’, 'Speakers / Headphones (Realtek ']
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:10 (1 by maintainers)
Is it really fixed?
I see that it was merged, but it was sent to PyPi? (or better, will it be sent?)
Speech Recognition 3.8.1 (holy shit, last release in 2017 ^ - ^ - it looks that the native client can be a good choice for context fine-tune)
This package is just dead!
Thanks, @avinashs24 for asking this! I was having the same trouble but on the suggestion of @lichengunc I changed from “SpeechContext” to “SpeechContexts” in the speech_recognition init file and it works fine.