Uberi / speech_recognition

Speech recognition module for Python, supporting several engines and APIs, online and offline.
https://pypi.python.org/pypi/SpeechRecognition/
BSD 3-Clause "New" or "Revised" License
8.35k stars 2.4k forks source link

PYNQ HTTPError: HTTP Error 400: Bad Request #438

Open rafferino opened 5 years ago

rafferino commented 5 years ago

System information

My system is PYNQ Linux, based on Ubuntu 18.04

My Python version is 3.6.5

My Pip version is 9.0.1

My SpeechRecognition library version is 3.8.1

My PyAudio library version is 0.2.11

I am attempting to get speech recognition to run on Xilinx's PYNQ-Z1 and I am getting the following error:


HTTPError                                 Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/speech_recognition/__init__.py in recognize_google(self, audio_data, key, language, show_all)
    839         try:
--> 840             response = urlopen(request, timeout=self.operation_timeout)
    841         except HTTPError as e:

/usr/lib/python3.6/urllib/request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
    222         opener = _opener
--> 223     return opener.open(url, data, timeout)
    224 

/usr/lib/python3.6/urllib/request.py in open(self, fullurl, data, timeout)
    531             meth = getattr(processor, meth_name)
--> 532             response = meth(req, response)
    533 

/usr/lib/python3.6/urllib/request.py in http_response(self, request, response)
    641             response = self.parent.error(
--> 642                 'http', request, response, code, msg, hdrs)
    643 

/usr/lib/python3.6/urllib/request.py in error(self, proto, *args)
    569             args = (dict, 'default', 'http_error_default') + orig_args
--> 570             return self._call_chain(*args)
    571 

/usr/lib/python3.6/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args)
    503             func = getattr(handler, meth_name)
--> 504             result = func(*args)
    505             if result is not None:

/usr/lib/python3.6/urllib/request.py in http_error_default(self, req, fp, code, msg, hdrs)
    649     def http_error_default(self, req, fp, code, msg, hdrs):
--> 650         raise HTTPError(req.full_url, code, msg, hdrs, fp)
    651 

HTTPError: HTTP Error 400: Bad Request

During handling of the above exception, another exception occurred:

RequestError                              Traceback (most recent call last)
<ipython-input-8-016a643eec9b> in <module>()
      8 with sr.AudioFile(b) as src:
      9     audio = r.record(src)
---> 10 print(r.recognize_google(audio))
     11 # sr.AudioData(frame_data=pAudio.buffer, sample_rate=round(pAudio.sample_rate), sample_width=2)

/usr/local/lib/python3.6/dist-packages/speech_recognition/__init__.py in recognize_google(self, audio_data, key, language, show_all)
    840             response = urlopen(request, timeout=self.operation_timeout)
    841         except HTTPError as e:
--> 842             raise RequestError("recognition request failed: {}".format(e.reason))
    843         except URLError as e:
    844             raise RequestError("recognition connection failed: {}".format(e.reason))

RequestError: recognition request failed: Bad Request

The PYNQ does not have a microphone in port, but it does have a on-board microphone. This is interfaced through the PYNQ's API. A possible problem is that the PYNQ's record output is recorded at a sampling rate of 192000 Hz, which is different than the standard sampling rate. Here is the code I am using that produces this error:

r = sr.Recognizer()
b = "buffer.wav"
pAudio.record(3)
pAudio.save(b)
with sr.AudioFile(b) as src:
    audio = r.record(src)
print(r.recognize_google(audio))

What could possible be causing this HTTPError?

CraftInsights commented 4 years ago

I too am receiving this error, has anyone figured out what is going on? My code was working fine yesterday, and all of a sudden it doesn't work. Any help would be greatly appreciated.

Error_Capture

MT-1963 commented 4 years ago

Maybe the length of your audio data might be an issue... https://cloud.google.com/speech-to-text/quotas