我正在尝试使用语音识别库将语音转换为文本。 但是当我运行代码时,它显示关于音频类型的值错误,我试图通过重命名文件扩展名将文件格式更改为许多音频格式,如:“PCM、WAV、AIFF、AIFF-C、Mp3、Mp4、FLAC、WebM、WAV…”。但是,它仍然显示相同的错误
错误:
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
守则:
import speech_recognition as sr
filename = "hello.mp3"
r = sr.Recognizer()
with sr.AudioFile(filename) as source:
audio = r.record(source)
text = r.recognize_google(audio)
print(text)
我不认为重命名文件扩展名会对你有所帮助,你应该使用文件转换器来确保音频数据以另一种格式正确编码。尝试使用SoundConverter
相关问题 更多 >
编程相关推荐