Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Cloud Speech : "Invalid JSON payload received. Unknown name "speech_context" at 'config': Cannot find field." #334

Open
avinashs24 opened this issue Mar 11, 2018 · 11 comments

Comments

@avinashs24
Copy link

avinashs24 commented Mar 11, 2018

Steps to reproduce

  1. The error occurs when recognize_google_cloud method is used with preferred_phrases parameter.
  2. 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 ']

@avinashs24 avinashs24 changed the title Google Cloud Speech : "Invalid JSON payload received. Unknown name "speech_context" at 'config': Cannot find field." when preferred phases parameter is used Google Cloud Speech : When preferred phases parameter is used, this error occurs "Invalid JSON payload received. Unknown name "speech_context" at 'config': Cannot find field." Mar 11, 2018
@avinashs24 avinashs24 changed the title Google Cloud Speech : When preferred phases parameter is used, this error occurs "Invalid JSON payload received. Unknown name "speech_context" at 'config': Cannot find field." Google Cloud Speech : "Invalid JSON payload received. Unknown name "speech_context" at 'config': Cannot find field." Mar 11, 2018
@dcam0050
Copy link
Contributor

This issue was solved with pull request #304. Seems it is still present when installing via pip rather than from sources

@partounian
Copy link

@dcam0050 I install from sources but still have the issue somehow, I don't see that in the code. The issue not speechContexts over speechContext at the moment. It is something else, looking into it.

@lichengunc
Copy link

I believe the issue is "speechContexts" over "speechContext", please check your pip installed code again. :-)

@avinashs24
Copy link
Author

This must be updated in pypi as well. When will it be done?

@pranjaldaga
Copy link

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.

@gotjazz
Copy link

gotjazz commented May 27, 2018

same here - changed it locally meanwhile but I'm sure havign this packaged would be nice for a lot of people since you stumble upon this pretty quickly when using google cloud speech

@jamilfaisal
Copy link

Bug is still here. Downloaded the latest speech_recognition package (Version 3.8.1) from pip. Had to manually change it from speechContext to SpeechContexts in the speech_recognition init file.

@jonahbrennan
Copy link

jonahbrennan commented Feb 17, 2020

After the DYI fix on the init file, passphrase doesn't error anymore but I haven't noticed any increase in response time for the short one word commands I'm shouting. shouting doesn't help either

Does anyone have any tips for speeding up these one word requests?
preferred_phrases=['yes','no','stop']

@ghost
Copy link

ghost commented Dec 31, 2020

Is it really fixed?

"Invalid JSON payload received. Unknown name "speechContext" at 'config': Cannot find field.". Details: "[{'@type': 'type.googleapis.com/google.rpc.BadRequest', 'fieldViolations': [{'field': 'config', 'description': 'Invalid JSON payload received. Unknown name "speechContext" at \'config\': Cannot find field.'}]"

I see that it was merged, but it was sent to PyPi? (or better, will it be sent?)

image

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!

@hiroono
Copy link

hiroono commented Dec 24, 2021

@dcam0050 I installed the latest version from source (as suggested above) and ran r.recognize_google_cloud(audio, credentials_json=GOOGLE_CLOUD_SPEECH_CREDENTIALS)

Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.9/site-packages/speech_recognition/__init__.py", line 933, in recognize_google_cloud
    from google.cloud.speech import enums
ImportError: cannot import name 'enums' from 'google.cloud.speech' (/opt/homebrew/lib/python3.9/site-packages/google/cloud/speech/__init__.py)

Perhaps version incompatibility?

@brandonbarringer
Copy link

Was having the same issue. I fixed locally by changing it to speech_contexts
On line 979 of init.py: config['speech_contexts'] = [speech.SpeechContext(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests