我正在尝试使用以下代码从语音生成文本:
def genText(path, dataholder = {}):
for filename in os.listdir(path):
if filename != '.DS_Store':
print filename
eg = sr.AudioFile(path + "/" + filename)
# print eg
with eg as source:
audio = r.record(source)
try:
print r.recognize_google(audio)
#s_audio.append(r.recognize_google(audio))
dataholder[filename] = r.recognize_google(audio)
except sr.UnknownValueError:
pass
return dataholder
s9_corpus = genText(path9) # path to my audio files' directory
但是会出现以下错误(它适用于其他几个音频文件的目录,但不适用于s9目录):
Audio file could not be read as PCM WAV, AIFF/AIFF-C, or Native FLAC; check if file is corrupted or in another format
但是,当我在Mac计算机上打开这些音频时,这些音频将显示为.wav。例如,查看所附图片
将不胜感激。