语音识别:AttributeError:模块"speech_recognition"没有属性"Recognizer" [英] Speech Recognition: AttributeError: module 'speech_recognition' has no attribute 'Recognizer'

查看:334
本文介绍了语音识别:AttributeError:模块"speech_recognition"没有属性"Recognizer"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用语音识别项目

我如图所示安装了SpeechRecognition.我的代码正确运行了几次.

I installed SpeechRecognition as illustrated. My code ran correctly for a few times.

我试图输入其他文件.现在,我开始出现以下错误:

I was trying to input different files. Now I started getting the following error:

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'

令人困惑的是,我只执行代码的第一行,即导入库.并返回错误.

The confusing thing is that I'm only executing the first line of the code, which is to import the library. And it returns the error.

import speech_recognition as sr

该错误似乎与我尚未执行的下一行代码相对应:

And the error seems to be corresponding to the next line of code, which I've not yet executed:

r = sr.Recognizer()

我对编程和python都是新手.我正在使用spyder3.我已经重启了几次内核.我尝试再次在终端上安装SpeechRecognition.我也关闭和打开了spyder几次,但现在却一次又一次地遇到相同的错误.

I'm new to both programming as well as to python. I'm using spyder3. I've restarted the kernel a few times. I tried to install SpeechRecognition again on terminal. I closed and opened spyder also a few times, but now facing the same error again and again.

请帮助.

完整代码:

# 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)

推荐答案

文件

您的文件名为speech_recognition.py,而python不在查找speech_recognition模块,而是在模块(文件)中搜索Recognizer.

Your name of the file is speech_recognition.py and python is looking not to the speech_recognition module but search the Recognizer in your module (file).

您只需简单地重命名模块(文件)即可.

You need simple to rename your module (file).

例如从speech_recognition.pysp_recog.py

这篇关于语音识别:AttributeError:模块"speech_recognition"没有属性"Recognizer"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆