我正在做一个演讲到文本的作业。我有一个使用示例音频文件的示例,但当我尝试自己的音频文件时,收到以下错误:
Traceback (most recent call last):
File "<ipython-input-27-43c56c192b14>", line 1, in <module>
with input_audio as source:
File "C:\Users\AppData\Local\Continuum\anaconda3\lib\site-packages\speech_recognition\__init__.py", line 236, in __enter__
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 or in another format
我的问题:我能做些什么来分析我的音频文件?因为它看起来格式正确。
我搜索了一下,在Stackoverflow上找到了另一个问题。作者提到,可能是WAV文件的类型不对。但是,当我检查我的音频类型时,它看起来是正确的:
^{pr2}$到目前为止我的代码(与the Ultimate Guide To Speech Recognition相同)
import os
import speech_recognition as sr
os.chdir(r'C:\Desktop\Speech_to_Text')
r = sr.Recognizer()
input_audio = sr.AudioFile('harvard.wav') # The example works!
input_audio = sr.AudioFile('my_own_audio.wav') # Will throw the error!
type(input_audio) # For both, it will print Out[29]: speech_recognition.AudioFile
# This chunk will throw the error!
with input_audio as source:
# If the data has a lot of noise.
r.adjust_for_ambient_noise(source)
audio = r.record(source)
r.recognize_google(audio, show_all = True)
目前没有回答
相关问题 更多 >
编程相关推荐