1

speech_recognition.AudioFile在 Python 3.6 中使用过,但是提示了这个错误:

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

另外我正在使用speech_recognition 3.1.3.

4

3 回答 3

2

您可以更改为更新版本的 SpeechRecognition 吗?您的代码使用最新版本可以顺利运行,但版本 3.1.3 似乎还没有该功能,并且也触发了我的错误。

或者,您的脚本文件名是否称为 Speech_recognition.py?有人遇到了这个问题: 语音识别:AttributeError:模块'speech_recognition'没有属性'Recognizer'

于 2019-12-04T13:12:47.187 回答
0

相反,尝试输入更少的命令

将 .wav 文件粘贴到当前工作目录中

然后删除 AUDIO_FILE

并输入:

以 sr.AudioFile("english.wav") 作为源

于 2019-12-31T08:52:55.633 回答
0
#!/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
于 2020-02-24T13:41:11.093 回答