2

Has anyone gotten this error for the following code. I have seen many solution but none of them are working. Is there any solutions? I rememeber that I export the path of the python to somewhere else. Would this cause the problem?

import speech_recognition as sr

r = sr.Recognizer()

with sr.Microphone() as source:
    print('say something')
    audio = r.listen(source)
    voice_data = r.recognize_google(audio)
    print(voice_data)
Traceback (most recent call last):
  File "/research/venv/lib/python3.9/site-packages/speech_recognition/__init__.py", line 840, in recognize_google
    response = urlopen(request, timeout=self.operation_timeout)
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 214, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 523, in open
    response = meth(req, response)
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 632, in http_response
    response = self.parent.error(
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 561, in error
    return self._call_chain(*args)
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 494, in _call_chain
    result = func(*args)
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 641, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: Bad Request

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/research/main.py", line 8, in <module>
    voice_data = r.recognize_google(audio)
  File "/venv/lib/python3.9/site-packages/speech_recognition/__init__.py", line 842, in recognize_google
    raise RequestError("recognition request failed: {}".format(e.reason))
speech_recognition.RequestError: recognition request failed: Bad Request
StudentCSE
  • 31
  • 4
  • 2
    Do you have active internet connection? – arshovon Jul 24 '21 at 04:33
  • 1
    you have problem with internet connection - it has to send audio to Google Servers which will convert it to text. Maybe it only your connection or maybe Google servers have temporary problem and you should try few hours later. Or maybe Google changed something on servers and you have to install newer version – furas Jul 24 '21 at 07:21
  • @arsho I do have an active internet connection – StudentCSE Jul 26 '21 at 05:15
  • @furas I've been trying this for couple of days and I keep having the problem. – StudentCSE Jul 26 '21 at 05:15
  • do you have acctive connection to Google ? Sometimes problem can be when they change code on servers - and then modules needs new code and you have to install the newest version. – furas Jul 26 '21 at 05:23
  • Could you provide some overview what you want to achieve and your environment? Are you trying to run it from your local machine or from GCP? Do you have any specific configuration of firewall or using corporate network? How do you authenticate with GCP? – PjoterS Jul 26 '21 at 08:02
  • @furas I believe so because Google is working on my computer. – StudentCSE Jul 27 '21 at 00:07
  • @PjoterS What I want to achieve is to turn speech into text by using google speech recognition in Python. I am currently using visual studio code and I am running my program inside a virtual environment I created in my local machine. I believe that I don't have autentication with GCP. – StudentCSE Jul 27 '21 at 00:09
  • Could you try to run it in GCP and follow [Speech-to-Text client libraries](https://cloud.google.com/speech-to-text/docs/libraries#client-libraries-install-python) documentation? Also did you try some official [samples](https://cloud.google.com/speech-to-text/docs/samples) ? Is it possible to provide more details to replicate it for test purpose? – PjoterS Jul 27 '21 at 10:14

0 Answers0