hmmmbob
hmmmbob

Reputation: 1177

recognize_google speech recognition broken pipe python

I have an audio file (30 seconds) and want to convert it into text using google.

I am following this guide :

https://realpython.com/python-speech-recognition/#working-with-audio-files

my code is the following :

cut=sr.AudioFile("cutsound.wav") with cut as source: audio = r.record(source) r.recognize_google(audio)

Now i get this endless error message :

---------------------------------------------------------------------------
BrokenPipeError                           Traceback (most recent call last)
~/anaconda3/envs/tf/lib/python3.6/urllib/request.py in do_open(self, http_class, req, **http_conn_args)
   1317                 h.request(req.get_method(), req.selector, req.data, headers,
-> 1318                           encode_chunked=req.has_header('Transfer-encoding'))
   1319             except OSError as err: # timeout error

~/anaconda3/envs/tf/lib/python3.6/http/client.py in request(self, method, url, body, headers, encode_chunked)
   1238         """Send a complete request to the server."""
-> 1239         self._send_request(method, url, body, headers, encode_chunked)
   1240 

~/anaconda3/envs/tf/lib/python3.6/http/client.py in _send_request(self, method, url, body, headers, encode_chunked)
   1284             body = _encode(body, 'body')
-> 1285         self.endheaders(body, encode_chunked=encode_chunked)
   1286 

~/anaconda3/envs/tf/lib/python3.6/http/client.py in endheaders(self, message_body, encode_chunked)
   1233             raise CannotSendHeader()
-> 1234         self._send_output(message_body, encode_chunked=encode_chunked)
   1235 

~/anaconda3/envs/tf/lib/python3.6/http/client.py in _send_output(self, message_body, encode_chunked)
   1064                         + b'\r\n'
-> 1065                 self.send(chunk)
   1066 

~/anaconda3/envs/tf/lib/python3.6/http/client.py in send(self, data)
    985         try:
--> 986             self.sock.sendall(data)
    987         except TypeError:

BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

URLError                                  Traceback (most recent call last)
~/anaconda3/envs/tf/lib/python3.6/site-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:

~/anaconda3/envs/tf/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 

~/anaconda3/envs/tf/lib/python3.6/urllib/request.py in open(self, fullurl, data, timeout)
    525 
--> 526         response = self._open(req, data)
    527 

~/anaconda3/envs/tf/lib/python3.6/urllib/request.py in _open(self, req, data)
    543         result = self._call_chain(self.handle_open, protocol, protocol +
--> 544                                   '_open', req)
    545         if result:

~/anaconda3/envs/tf/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:

~/anaconda3/envs/tf/lib/python3.6/urllib/request.py in http_open(self, req)
   1345     def http_open(self, req):
-> 1346         return self.do_open(http.client.HTTPConnection, req)
   1347 

~/anaconda3/envs/tf/lib/python3.6/urllib/request.py in do_open(self, http_class, req, **http_conn_args)
   1319             except OSError as err: # timeout error
-> 1320                 raise URLError(err)
   1321             r = h.getresponse()

URLError: <urlopen error [Errno 32] Broken pipe>

During handling of the above exception, another exception occurred:

RequestError                              Traceback (most recent call last)
<ipython-input-41-59c33ef07a2e> in <module>()
----> 1 r.recognize_google(audio)

~/anaconda3/envs/tf/lib/python3.6/site-packages/speech_recognition/__init__.py in recognize_google(self, audio_data, key, language, show_all)
    842             raise RequestError("recognition request failed: {}".format(e.reason))
    843         except URLError as e:
--> 844             raise RequestError("recognition connection failed: {}".format(e.reason))
    845         response_text = response.read().decode("utf-8")
    846 

RequestError: recognition connection failed: [Errno 32] Broken pipe

Upvotes: 7

Views: 14859

Answers (2)

natalie
natalie

Reputation: 1

yeah hi! In my case, I just connected the internet and it worked

Upvotes: -1

Nikolay Shmyrev
Nikolay Shmyrev

Reputation: 25220

The method described in your link uses hacks and not guaranteed to work reliably. Google blocks long files or excessive requests.

Google has an official API which you can use to recognize long files, it is paid though:

Upvotes: 3

Related Questions