Google Cloud Speech : "Invalid JSON payload received. Unknown name "speech_context" at 'config': Cannot find field."
#334 建立於 2018年3月11日
描述
Steps 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 ']