Uberi/speech_recognition

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

開放

#334 建立於 2018年3月11日

 (12 則留言) (4 個反應) (0 位負責人)Python (2,330 個分叉)batch import
bughelp wanted

倉庫指標

星標
 (7,767 顆星)
PR 合併指標
 (平均合併 10天 3小時) (30 天內合併 3 個 PR)

描述

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

貢獻者指南