good evening,my little project is related to the extraction of text from the mp3 file for the farther analysis, for this purpose i have used two library :
- speech_recognition
- pydub
as i have read through internet, i need to convert mp3 to wav file and then read wav file,the file was chosen from the given link : https://pixabay.com/music/search/lyrics/ , name of the file is : Good To You, duration is : 3:15 , my efford was only successfull for first fragment and text is given here :
why did you talk like on the photo of this bad girl fat girl only do by my side by you better text to don't stop to me a Morrison Ford Avenue
but i want to extract each text and seperation should be silence or given time periods, for the last option i found another link :
Using pyDub to chop up a long audio file
Based on the all this information, i have tried following code :
import speech_recognition as sr
from pydub import AudioSegment
from pydub.silence import split_on_silence
r = sr.Recognizer()
#convert mp3 to wav
sound = AudioSegment.from_mp3("example.mp3")
chunks =split_on_silence(sound,min_silence_len=500,silence_thresh=-16)
for _, chunk in enumerate(chunks):
chunk.export("example.wav", format="wav")
# sound.export("example.wav", format="wav")
temp = 'example.wav'
with sr.AudioFile(temp) as source:
audio = r.record(source)
text = r.recognize_google(audio, language="en-US")
print(text)
but i have got following error :speech_recognition.exceptions.UnknownValueError
could you help me please what is wrong with my code?
AI_Science is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.