在Python中将语音转换为文本时出错

2024-06-26 00:16:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用语音识别库将语音转换为文本。 但是当我运行代码时,它显示关于音频类型的值错误,我试图通过重命名文件扩展名将文件格式更改为许多音频格式,如:“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)

Tags: ortext文本sourceas错误语音filename