speech_recognition: Speech_recognition broken for new Bing API

Steps to reproduce

  1. Register for a Bing Speech API key
  2. Try to use sr.recognize_bing()

Expected behaviour

Speech recognition (speech to text)

Actual behaviour

Error - tried two different keys, multiple machines - Bing API has been updated, appears to no longer authenticate correctly with Speech_recognition 3.8.x - worked a few months ago - only thing I changed was getting a new API key.

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/speech_recognition/__init__.py", line 935, in recognize_bing
    credential_response = urlopen(credential_request, timeout=60)  # credential response can take longer, use longer timeout instead of default one
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 532, in open
    response = meth(req, response)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 642, in http_response
    'http', request, response, code, msg, hdrs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 570, in error
    return self._call_chain(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 504, in _call_chain
    result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 650, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 401: Access Denied

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/bpayne/Downloads/voice_control_mac_2018-11.py", line 22, in <module>
    MY_API_KEY,"en-US")
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/speech_recognition/__init__.py", line 937, in recognize_bing
    raise RequestError("credential request failed: {}".format(e.reason))
speech_recognition.RequestError: credential request failed: Access Denied

System information

My system is Mac OS X 10.13.6 High Sierra, and Win 10 Pro/Enterprise - tested on 3 machines.

My Python version is 3.6.3 to 3.6.7, tested across 3 machines/versions. (You can check this by running python -V.)

My Pip version is 18.1

My SpeechRecognition library version is 3.8.1

My PyAudio library version is 0.2.11

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Comments: 16 (3 by maintainers)

Most upvoted comments

I realized the answer to the below note was that this was resolved in Oct 2018 via https://github.com/Uberi/speech_recognition/commit/036a53c442b325e847df94854ae0eeafb7a6ed13 - when is this scheduled to be live on PyPI?

When I try using recognize_azure, I’m getting the following error: AttributeError: 'Recognizer' object has no attribute 'recognize_azure'

I noticed when I run the following, the other methods (e.g. recognize_google) show up, but not recognize_azure:

import speech_recognition as sr
import inspect
r = sr.Recognizer()
print(inspect.getmembers(r, predicate=inspect.ismethod))

Output:

[
('__enter__', <bound method AudioSource.__enter__ of <speech_recognition.Recognizer object at 0x10e65a5f8>>), 
('__exit__', <bound method AudioSource.__exit__of <speech_recognition.Recognizer object at 0x10e65a5f8>>), 
('__init__', <bound method Recognizer.__init__ of <speech_recognition.Recognizer object at 0x10e65a5f8>>), 
('adjust_for_ambient_noise', <bound method Recognizer.adjust_for_ambient_noise of <speech_recognition.Recognizer object at 0x10e65a5f8>>), 
('listen', <bound method Recognizer.listen of <speech_recognition.Recognizer object at 0x10e65a5f8>>), 
('listen_in_background', <bound method Recognizer.listen_in_background of <speech_recognition.Recognizer object at 0x10e65a5f8>>), 
('recognize_api', <bound method recognize_api of <class 'speech_recognition.Recognizer'>>), 
('recognize_bing', <bound method Recognizer.recognize_bing of <speech_recognition.Recognizer object at 0x10e65a5f8>>), 
('recognize_google', <bound method Recognizer.recognize_google of <speech_recognition.Recognizer object at 0x10e65a5f8>>), 
('recognize_google_cloud', <bound method Recognizer.recognize_google_cloud of <speech_recognition.Recognizer object at 0x10e65a5f8>>), 
('recognize_houndify', <bound method Recognizer.recognize_houndify of <speech_recognition.Recognizer object at 0x10e65a5f8>>), 
('recognize_ibm', <bound method Recognizer.recognize_ibm of <speech_recognition.Recognizer object at 0x10e65a5f8>>), 
('recognize_sphinx', <bound method Recognizer.recognize_sphinx of <speech_recognition.Recognizer object at 0x10e65a5f8>>), 
('recognize_wit', <bound method Recognizer.recognize_wit of <speech_recognition.Recognizer object at 0x10e65a5f8>>), 
('record', <bound method Recognizer.record of <speech_recognition.Recognizer object at 0x10e65a5f8>>), 
('snowboy_wait_for_hot_word', <bound method Recognizer.snowboy_wait_for_hot_word of <speech_recognition.Recognizer object at 0x10e65a5f8>>)
]

I found the issue - as MS phases out the Bing Speech API in favor of Cognitive Speech Services, it’s changing its servers. It was an issue in the Authentication and Recognition in the Bing section (Lines 1010 and 1040) of init.py. An updated copy of init.py is attached - just have to unzip and replace it in your C:\Users\{your_user_name}\AppData\Local\Programs\Python\Python36\Lib\site-packages\speech_recognition folder on a PC or /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/speech_recognition folder on Mac. Hope it’s of help. Bryson init.zip

For anyone else who went down the rabbit hole to solve a bug in the second lab in Microsoft’s AI Program (second lab of the first course), it still refers to the Bing Speech API and links to this speech_recognition library.

It looks like once #389 is merged, theoretically the line in MS’s Jupyter notebook can be changed from transcription = r.recognize_bing(audio, key=speechKey) to transcription = r.recognize_azure(audio, key=speechKey)

For anyone interested, I fixed this in my branch. As this repo seems to be abandoned, and my past PRs have been ignored, it’s unlikely it will ever be fixed here. That said, I’m not using Bing anymore myself (as it’s enormously expensive), but it’s accuracy is fantastic.

Yes, you are right. However, I found a question is that directly using your modified code may still fail. From the code, I see that you are in west US. But, I’m in East US. Thus, I failed too. I modified your code to East US. Success! So, other people should pay attention on this.

Thanks @brysonpayne

I’ve created a PR to add the new Azure Speech API (now that the Bing API is not working).

https://github.com/Uberi/speech_recognition/pull/389

If the Bing API definitely doesn’t work, I can delete that code as well in the PR.

For anyone else who went down the rabbit hole to solve a bug in the second lab in Microsoft’s AI Program (second lab of the first course), it still refers to the Bing Speech API and links to this speech_recognition library.

It looks like once #389 is merged, theoretically the line in MS’s Jupyter notebook can be changed from transcription = r.recognize_bing(audio, key=speechKey) to transcription = r.recognize_azure(audio, key=speechKey)

You, sir, are the best kind of human. I came here for just such a thing.