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