Speech audio file wav to Text - getting timed out

+1 vote

I am trying to read a wav file of size 24.4MB, 9 mins 33  secs. using a simple python speech_recogniton code, i am getting below mentioned error. any suggestions would be great help.

Error: Could not request results from google Speech Recognition service; recognition connection failed: [Errno 32] Broken pipe

def readAudioFile(audio_file):
    r = sr.Recognizer()
    file = sr.AudioFile(audio_file)
    with file as source:

        audio = r.record(source)
        type(audio)
    try:
        message = r.recognize_google(audio)
        print(message)
        print("Data extracted from phone conversation:\n" + message)
    except sr.UnknownValueError:
        print("Google Speech Recognition could not understand audio")
    except sr.RequestError as e:
        print("Could not request results from google Speech Recognition service; {0}".format(e))

parser = argparse.ArgumentParser()
parser.add_argument("--file", "-f", type=str, required=True)
args = parser.parse_args()
audio_file = args.file
print(audio_file)
readAudioFile(audio_file)
Nov 27, 2018 in Python by Shobha
• 170 points
5,826 views

I have a similar code and I get this error:

Could not request results from Google Speech Recognition service; recognition request failed: Bad Gateway

2 answers to this question.

+2 votes
Best answer
I think the error you are getting is because the file you are using crosses the API limit. Please check the limits of the API from the below mentioned link and see if the audio you are using is crossing the limit:

https://cloud.google.com/speech-to-text/quotas
answered Nov 27, 2018 by Omkar
• 69,220 points

selected Nov 30, 2018 by Omkar
Yes this is the problem, as i tried using it with smaller files and it worked fine.
thanks for the reply. ,as mentioned above, the code is working fine if the audio length is small. I am new to python, is there any example of how to do it with uri?

Hey @Shobha. To use uri, you have to first upload your file to Google Cloud Storage. You can refer the following link to know how to do this: https://www.youtube.com/watch?v=kdRuDaDyyBo

Then in you code, instead of the audio file path, use the uri pointing to your audio file in Google Cloud Storage. 

audio_file = gs://bucket-name/path_to_audio_file
Thank you so much for your reply :)
@Shobha Did it work for you?
You're Welcome :-) Shobha
0 votes
@Omkar @Shobha

I tried doing it for a 2 minute audio file. It worked fine. I am not storing it in a text file i am simply printing the text.

The file is 3 MB.

https://www.edureka.co/community/31551/error-speech-to-text-codec-cannot-decode-the-bytes-position

Here you can have a look at the code.
answered Nov 27, 2018 by Nitesh
• 3,080 points

Related Questions In Python

0 votes
0 answers

how to print string to text file?

can you give an example? READ MORE

Apr 3, 2019 in Python by Waseem
• 4,540 points
634 views
0 votes
1 answer

How to read data from a text file using Python?

Refer to the below example where the ...READ MORE

answered May 13, 2019 in Python by Sushma
1,508 views
0 votes
0 answers
0 votes
1 answer

Is it possible to read a text file into a string variable and then scrap the newlines?

This can be done easily in Python. ...READ MORE

answered Aug 7, 2019 in Python by Arvind
• 3,050 points
1,729 views
0 votes
2 answers

Error: Speech to Text Codec cannot decode the bytes in position

import speech_recognition as sr r = sr.Recognizer() audio ='C\Users\Desktop\audiofile1.wav' with ...READ MORE

answered Nov 28, 2018 in Python by Nabarupa Das
2,936 views
0 votes
3 answers

Python error "NameError: name 'sr' is not defined"

NameError: name 'xx' is not defined Python knows ...READ MORE

answered Mar 19, 2020 in Python by rahul
• 360 points
42,576 views
0 votes
1 answer

Need help with Python Text-to-Speech usage

Hi. Just before I begin my answer I ...READ MORE

answered Jan 16, 2019 in Python by Nymeria
• 3,560 points
1,029 views
+1 vote
2 answers

Appending data to a file

First open the file that you want ...READ MORE

answered Jul 23, 2018 in Python by Omkar
• 69,220 points
1,052 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP