如何在Python的SpeechRecognition中使用音频文件作为音频源?
我在Python 3.6中使用了如何在Python的SpeechRecognition中使用音频文件作为音频源?,python,signal-processing,speech-recognition,avaudiofile,audio-source,Python,Signal Processing,Speech Recognition,Avaudiofile,Audio Source,我在Python 3.6中使用了speech\u recognition.AudioFile,但指出了这个错误: AttributeError: module 'speech_recognition' has no attribute 'AudioFile' 这是我的代码: #!/usr/bin/env python3 import speech_recognition as sr # obtain path to "english.wav" in the same folder as t
speech\u recognition.AudioFile
,但指出了这个错误:
AttributeError: module 'speech_recognition' has no attribute 'AudioFile'
这是我的代码:
#!/usr/bin/env python3
import speech_recognition as sr
# obtain path to "english.wav" in the same folder as this script
from os import path
AUDIO_FILE = path.join(path.dirname(path.realpath(__file__)), "english.wav")
# AUDIO_FILE = path.join(path.dirname(path.realpath(__file__)), "french.aiff")
# AUDIO_FILE = path.join(path.dirname(path.realpath(__file__)), "chinese.flac")
# use the audio file as the audio source
r = sr.Recognizer()
with sr.AudioFile(AUDIO_FILE) as source:
audio = r.record(source) # read the entire audio file
此外,我正在使用
语音识别3.1.3
您可以更改为新版本的SpeechRecognition吗?您的代码在使用最新版本时运行顺利,但3.1.3版似乎还没有该功能,并为我触发了错误
或者,脚本的文件名是否为speech_recognition.py?有人有这个问题:
相反,尝试键入更少的命令 将.wav文件粘贴到当前工作目录中 然后删除音频文件 和类型:
使用sr.AudioFile(“english.wav”)作为源代码Hi,您应该提供代码的解释以及代码片段,以改进您的答案
#!/usr/bin/env python3
import speech_recognition as sr
# obtain path to "english.wav" in the same folder as this script
#from os import path
#AUDIO_FILE = path.join(path.dirname(path.realpath(__file__)), "english.wav")
# AUDIO_FILE = path.join(path.dirname(path.realpath(__file__)), "french.aiff")
# AUDIO_FILE = path.join(path.dirname(path.realpath(__file__)), "chinese.flac")
# use the audio file as the audio source
# paste the .wav file int current working directory
r = sr.Recognizer()
with sr.AudioFile("english.wav") as source:
audio = r.record(source) # read the entire audio file