我正在尝试使用Speech Recognition Project
进行语音识别我如图所示安装了SpeechRecognition。我的代码正确运行了几次。
我试图输入其他文件。现在,我开始出现以下错误:
import speech_recognition as sr
Traceback (most recent call last):
File "<ipython-input-1-a4d5c9aae5d0>", line 1, in <module>
import speech_recognition as sr
File "/Users/Sashank/Documents/Deep_Learning_A_Z/Personal Projects/Speech recognition/speech_recognition.py", line 7, in <module>
r = sr.Recognizer()
AttributeError: module 'speech_recognition' has no attribute 'Recognizer'
令人困惑的是,我只执行代码的第一行,即导入库。并返回错误。
import speech_recognition as sr
错误似乎与我尚未执行的下一行代码相对应:
r = sr.Recognizer()
我对编程和python都是新手。我正在使用spyder3。我已经重启了几次内核。我尝试再次在终端上安装SpeechRecognition。我也关闭和打开了spyder几次,但现在却一次又一次地遇到相同的错误。
请帮助。
完整代码:
# Speech Recognition
# Importing Library
import speech_recognition as sr
# Creating a recognition object
r = sr.Recognizer()
# Extracting the audio & removing ambient noice
audio_file = sr.AudioFile('ambient_noise_recording.wav')
with audio_file as source:
r.adjust_for_ambient_noise(source)
audio = r.record(source)
# Recognize the audio
r.recognize_google(audio)
答案 0 :(得分:4)
文件
中的第7行,“文件//用户/ Sashank /文档/ Deep_Learning_A_Z /个人项目/语音识别/ speech_recognition.py ”。
您的文件名为speech_recognition.py
,而python不在寻找speech_recognition
模块,而是在您的模块(文件)中搜索Recognizer
。
您只需简单地重命名模块(文件)。
例如,从speech_recognition.py
到sp_recog.py