Visitar URL original
changing the key fails · Issue #4 · realpython/python-speech-recognition · GitHub
Skip to content

changing the key fails #4

Description

@jzoudavy

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?

Activity

  1. somacdivad commented on May 15, 2018

    @somacdivad
    Contributor

    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.

  2. jzoudavy commented on May 16, 2018

    @jzoudavy
    Author

    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.

  3. somacdivad commented on May 21, 2018

    @somacdivad
    Contributor

    @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!

    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!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions