Uberi/speech_recognition

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

Open

#334 aberto em 11 de mar. de 2018

Ver no GitHub
 (12 comments) (4 reactions) (0 assignees)Python (2.330 forks)batch import
bughelp wanted

Métricas do repositório

Stars
 (7.767 stars)
Métricas de merge de PR
 (Mesclagem média 10d 3h) (3 fundiu PRs em 30d)

Description

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 ']

Guia do colaborador