Convert an AUDIO FILE into TEXT using Google Speech Recognition in Python


Hello World, it’s Ritesh! And Today We are going to convert an AUDIO File into Text as in the last program Speech2Text.py, we had converted our live Speech into Text, So in this video, we are going to convert an audio file into text! So, let’s start and right jump into it! so for this purpose You’ll need the last program which is available on… GitHub. I’ll be providing a link in the… description. So, check that So, huh for following that, we will need an Audio File… in WAV Format, in .wav format… or in FLAC Format. So, huh AUDIO: ‘Hello dear, we are going to convert an Audio File into… Text’… I don’t know why but this is so So this was the… Audio File So, Open the ‘Speech2Text.py’ program AND Instead of sr.Microphone, we will be… …using – with sr.AudioFile() with sr.AudioFile() for converting the audio file into text! AudioFile(), and here will be… …the name of the Audio FIle, let’s say audio and we have not defined audio yet, so we will define it here like audio… …audio equals what was the name of the file, we just created? It was audio… audio.wav OK! audio equals ‘audio.wav’ Now, as Source, instead of r.listen() as source, we are going to say r… r.record() from the Source. It means, it will record …that audio file And, it’ll send it to the sr… …sr.AudioFile(), for converting… …the speech to text. Not Speech but the Recorded Speech, means the Audio File So, after that, we have just said, try : print (text) text equals r.recognize_google and this is the audio And Except any Exception as e, print the the exception (e). So, let’s run the program and see what happens OK, Save that! Hello Dear we are going to convert an audio file into text it is what we said in the Audio File. So, guys in this way… …you can convert any audio file into text. Notice one thing that …If you will give larger audio… … files, then it will (huh) not work It will give us a Bad GateWay Exception, because it will take some smaller parts of the file like packets… …of the audio file And then, convert it into text. So… Notice one thing to give it a smaller audio file. So, guys Thanks for watching this video, And don’t forget to SUBSCRIBE. Bye Bye and ahve a nice day!

42 thoughts on “Convert an AUDIO FILE into TEXT using Google Speech Recognition in Python

  1. This program is very useful for making subtitles and Captions, with the help of which I added Closed Captions to this video!
    What do you think about it???

  2. Bro all is fine, But trust me, Hindi bol lo bhaai. Aapke English pronunciation sun kar aadhe log aapke video bandd kar denge yaar. Trust Indian Developer Fraternity bro, 1 Billion viewers anyhow understand hindi.

  3. bro it is taking so much time to recognize to voice instead of high speed internet,can you help to make is more faster

  4. This is cool. I'm looking to get someone to work with a small project that uses related technologies. If you are interested drop me a reply.

  5. any suggestion related to final project which can be made using python with machine learning or something…please help related to that

  6. Plz let me know the all require PIP installation for this project, I mean to say the screen shot of require pip.

  7. Hello rithesh I am trying with this code. My audio file is less than 10sec and its in. Wav formate and when I am. Trying to run its asking FLAC conversion utility not available – Consider installing the FLAC command line e application by running 'apt-get-install flac' or your operating system equivalent

  8. I am getting
    ValueError: Audio file could not be read as PCM WAV, AIFF/AIFF-C or Native FLAC; check if file is corrupted or in another format

    The file is in WAV format, I can listen to it on window media player

  9. I am getting a unicode decode error with response_text=response.read.decode('utf-8'), utf-8 codec can't decode byte

  10. Hi ., please help me💔
    My microphone is working with record test
    But with speech recognition not work.

    How can i fix this problem ☹️

  11. how to save the output in a text file? and what if i want to load multiple audios together and save each of them in different text files??

  12. Bhai or aache acche video dalo like this i m beginner in python and really i don't know the this module thanks dear

  13. Bro by default speech recognition comes with english how to change to hindi or kannada or different languages other than english?

  14. Hi Ritesh, what is the way around for bigger files? I have been trying to convert hindi speech audio files and which are much bigger than the one you discussed. Request your help

  15. Traceback (most recent call last):

    File "C:UserspeterAppDataLocalProgramsPythonPython37-32libsite-packag

    esspeech_recognition_init__.py", line 203, in __enter_

    self.audio_reader = wave.open(self.filename_or_fileobject, "rb")

    File "C:UserspeterAppDataLocalProgramsPythonPython37-32libwave.py", l

    ine 510, in open

    return Wave_read(f)

    File "C:UserspeterAppDataLocalProgramsPythonPython37-32libwave.py", l

    ine 164, in _init_

    self.initfp(f)

    File "C:UserspeterAppDataLocalProgramsPythonPython37-32libwave.py", l

    ine 131, in initfp

    raise Error('file does not start with RIFF id')

    wave.Error: file does not start with RIFF id

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):

    File "C:UserspeterAppDataLocalProgramsPythonPython37-32libsite-packag

    esspeech_recognition_init__.py", line 208, in __enter_

    self.audio_reader = aifc.open(self.filename_or_fileobject, "rb")

    File "C:UserspeterAppDataLocalProgramsPythonPython37-32libaifc.py", l

    ine 917, in open

    return Aifc_read(f)

    File "C:UserspeterAppDataLocalProgramsPythonPython37-32libaifc.py", l

    ine 352, in _init_

    self.initfp(file_object)

    File "C:UserspeterAppDataLocalProgramsPythonPython37-32libaifc.py", l

    ine 316, in initfp

    raise Error('file does not start with FORM id')

    aifc.Error: file does not start with FORM id

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):

    File "C:UserspeterAppDataLocalProgramsPythonPython37-32libsite-packag

    esspeech_recognition_init__.py", line 234, in __enter_

    self.audio_reader = aifc.open(aiff_file, "rb")

    File "C:UserspeterAppDataLocalProgramsPythonPython37-32libaifc.py", l

    ine 917, in open

    return Aifc_read(f)

    File "C:UserspeterAppDataLocalProgramsPythonPython37-32libaifc.py", l

    ine 358, in _init_

    self.initfp(f)

    File "C:UserspeterAppDataLocalProgramsPythonPython37-32libaifc.py", l

    ine 314, in initfp

    chunk = Chunk(file)

    File "C:UserspeterAppDataLocalProgramsPythonPython37-32libchunk.py",

    line 63, in _init_

    raise EOFError

    EOFError

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):

    File "C:UserspeterDocumentsGitHubvidudautienvidu13.py", line 7, in <modu

    le>

    with sr.AudioFile(audio) as source:

    File "C:UserspeterAppDataLocalProgramsPythonPython37-32libsite-packag

    esspeech_recognition_init__.py", line 236, in __enter_

    raise ValueError("Audio file could not be read as PCM WAV, AIFF/AIFF-C, or N

    ative FLAC; check if file is corrupted or in another format")

    ValueError: Audio file could not be read as PCM WAV, AIFF/AIFF-C, or Native FLAC

    ; check if file is corrupted or in another format

  16. where to add language parameter in this program??..i want to convert english language file to Hindi or any other language

  17. I am applying the same code and when i am running it , the error is :
    say something
    Done!
    recognition request failed: Service UnavailableService Unavailable

    PLEASE HELP ASAP

  18. hello, I have a 2hr long conference video recorded vi zoom and I need help converting it to text for easy search purposes of my students. Will this work?

  19. can you also make video on installing all necessary dependencies .. and how to install google api key.

    good video but not able to run on python 3.7

  20. brother i convert a audio file into text, its a 3 minutes of wav audio file but it only converts into text of 10 sec not more than that BTW i am using Pycharm 2019 version. Please help

  21. Hello, Great video tutorial. May I know how to convert a speech to text that is not in English?? I tried your code but it just doesn't work when I try other languages for example Dutch language.

Leave a Reply

Your email address will not be published. Required fields are marked *