Transcribing mp3 to text (python) –> "RIFF id" error

Question:

I am trying to turn mp3 file to text, but my code returns the error outlined below. Any help is appreciated!

This is a sample mp3 file. And below is what I have tried:

import speech_recognition as sr
print(sr.__version__)
r = sr.Recognizer()

file_audio = sr.AudioFile(r"C:UsersAndrewPodcast.mp3")

with file_audio as source:
    audio_text = r.record(source)

print(type(audio_text))
print(r.recognize_google(audio_text))

The full error I get. Appears to be:

Error: file does not start with RIFF id

Thank you for your help!

Asked By: Andrew

||

Answers:

One thing you can do is to convert your mp3 to wav. When testing with an mp3 file I’ve got the same error as you. But after converting, your code runs fine. Might be possible to also write your code so you can use mp3s but there my knowledge ends.

Maybe someones else knows more than me than he could post it. But if you just wan’t to test you can use something like audacity to convert it for now.

Also you might have problems if you go with large files read something online about that. But theres nothing stopping you trying.

Here is the website for that:

https://www.geeksforgeeks.org/python-speech-recognition-on-large-audio-files/

Answered By: Andreas B

You need to first convert the mp3 to wav, and then you can transcribe it, below is the modified version of your code.

import speech_recognition as sr
from pydub import AudioSegment

# convert mp3 file to wav  
src=(r"C:UsersAndrewPodcast.mp3")
sound = AudioSegment.from_mp3(src)
sound.export("C:UsersAndrewpodcast.wav", format="wav")

file_audio = sr.AudioFile(r"C:UsersAndrewPodcast.wav")

# use the audio file as the audio source                                        
r = sr.Recognizer()
with file_audio as source:
audio_text = r.record(source)

print(type(audio_text))
print(r.recognize_google(audio_text))

In above modified code, first mp3 file being converted into wav and then transcribing processes.

Answered By: Meghshyam Sonar

When I run this code python using vs code… I already installed speech recognition and pydub both but I got this error any one can help…

Exception has occurred: RequestError
recognition request failed: Bad Request

During handling of the above exception, another exception occurred:

File "D:Project1Bgnr.py", line 173, in
print(r.recognize_google(audio_text))


import speech_recognition as sr
from pydub import AudioSegment

file_audio = sr.AudioFile(r"D:Projectsample.wav")

r = sr.Recognizer()
with file_audio as source:

audio_text = r.record(source)

print(type(audio_text))
print(r.recognize_google(audio_text))

Answered By: Alishan Khan