Search code examples
pythonspeech-recognitionwav

Python speech_recognition can't not read wav file


I want to use recognize_google to analyze the number in the wav file

 try:
   temp = r.recognize_google(".//splitAudio//split.wav",language="zh-TW")
   print("You have said \n" + temp )
   print("Audio Recorded Successfully \n ")
 except Exception as e:
   print("Error :  " + str(e))

but I got the following error: Error : audio_data must be audio data

I have found this answer for a while, but I don't figure out.

Who can help me,i really appreciate it,thanks.


Solution

  • I do not have time to install stuff and find a WAV file but here's what The Ultimate Guide To Speech Recognition With Python says re "Using record() to Capture Data From a File"

    import speech_recognition as sr
    r = sr.Recognizer()
    harvard = sr.AudioFile('harvard.wav')
    with harvard as source:
        audio = r.record(source)
    
    r.recognize_google(audio)