You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I got a new GCP API key, and I tried to use it but I keep getting broken connection:
Traceback (most recent call last): File "main.py", line 13, in <module> speech=r.recognize_google(audio,key='A...........8g') File "/home/davy/anaconda3/lib/python3.6/site-packages/speech_recognition/__init__.py", line 845, in recognize_google raise RequestError("recognition connection failed: {}".format(e.reason)) speech_recognition.RequestError: recognition connection failed: [Errno 32] Broken pipe
I don't really understand why that is. I noticed that in the init.py file the key is set as follows:
if key is None: key = "AIz...bla...bla..bla...gw" url = "http://www.google.com/speech-api/v2/recognize?{}".format(urlencode({ "client": "chromium", "lang": language, "key": key, }))
Do i need to change the client? but it is just an API key client shouldn't matter right?
You might have gotten a key for the Google Cloud Speech API, which is different from the Google Web Speech API that .recognize_google() uses. There is an alternative recognizer in the SpeechRecognition package for using the Google Cloud APIs. That is the .recognize_google_cloud() method (docs here). In that case, you actually store the key in a JSON file.
The credentials_json it takes a string right? so i should just read the json file as a string and pass it on? The json.load method returns dicts and it seems the method doesn't like that.
@jzoudavy Sorry for delayed response. You are correct, credentials_json takes a string, but json.load() returns a dict. If you use json.loads(), you will get a string and it should work. Hope that helps!
Activity
somacdivad commentedon May 15, 2018
Hi @jzoudavy ,
You might have gotten a key for the Google Cloud Speech API, which is different from the Google Web Speech API that
.recognize_google()uses. There is an alternative recognizer in the SpeechRecognition package for using the Google Cloud APIs. That is the.recognize_google_cloud()method (docs here). In that case, you actually store the key in a JSON file.jzoudavy commentedon May 16, 2018
Hi
Thanks for answering my questions.
The credentials_json it takes a string right? so i should just read the json file as a string and pass it on? The json.load method returns dicts and it seems the method doesn't like that.
somacdivad commentedon May 21, 2018
@jzoudavy Sorry for delayed response. You are correct,
credentials_jsontakes a string, butjson.load()returns a dict. If you usejson.loads(), you will get a string and it should work. Hope that helps!For more info on working with JSON data, check out Real Python's guide to Working with JSON Data in Python.
Let me know how it works for you!