0

So I have the WAV file that I need to turn into the text using SpeechRecognition.

import speech_recognition as sr

r = sr.Recognizer()
sample_audio = sr.AudioFile('voice.wav')
print(type(sample_audio))
with sample_audio as audio_file:
     audio_content = r.record(audio_file)
print(type(audio_content))
q = r.recognize_google(audio_content)
print(f"You've said: {q}")

But intead of succes I get an error:

raise 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")
ValueError: Audio file could not be read as PCM WAV, AIFF/AIFF-C, or Native FLAC; check if file is corrupted
  • maybe it is not WAV (maybe you only changed extension but it doesn't change file) OR maybe it uses different encoding inside file and you would have to convert it with some tool. You could use some tool to check what really is in this file - ie. `ffprobe voice.wav` (if you have installed [ffmpeg](http://ffmpeg.org/)) – furas Apr 10 '22 at 16:47

0 Answers0