[英]ModuleNotFoundError: No module named 'speech_recognition' (windows COMPUTER)
My installation command was:我的安装命令是:
pip install speechrecognition
pip install pyAudio
In my file it raise this error:在我的文件中,它引发了这个错误:
Traceback (most recent call last):
File "e:/Projects/Python/Assistant/main.py", line 1, in <module>
import speech_recognition as sr
ModuleNotFoundError: No module named 'speech_recognition'
And my code was:我的代码是:
import speech_recognition as sr
As said earlier, the correct command is pip install SpeechRecognition
and then import like so... import speech_recognition as sr
then when ready to use it, implement it like this...如前所述,正确的命令是
pip install SpeechRecognition
然后像这样导入... import speech_recognition as sr
然后准备好使用它时,像这样实现它...
def takeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = .5
audio = r.listen(source)
try:
print("Recognizing...")
query = r.recognize_google(audio, language='en-us')
print("User said: {query}\n")
except Exception as e:
print(e)
print("Unable to understand.")
return "None"
return query
You want to make sure that exception handler is in there.您要确保异常处理程序在那里。 This is done from documentation.
这是从文档中完成的。
EDIT编辑
The issue may also be the version of Python.问题也可能是 Python 的版本。 SpeechRecognition isn't supported for Python 3.7 and above.
Python 3.7 及更高版本不支持 SpeechRecognition。 I tested it for Python 3.6 and it worked perfectly.
我针对 Python 3.6 对其进行了测试,它运行良好。 They do need to release a working version for the newer Python versions.
他们确实需要为较新的 Python 版本发布工作版本。
I fixed my bug!我修复了我的错误! I don't know what the error was but it's fixed!
我不知道错误是什么,但它已修复!
I had the same issue.我遇到过同样的问题。 Using Visual Studio Code.
使用 Visual Studio 代码。 Found out that my python interpreter was looking at the wrong virtual environment.
发现我的 python 解释器正在查看错误的虚拟环境。 I changed the location using
control + shift + P
to the location of my current files that I installed speech recognition.我使用
control + shift + P
将位置更改为我安装语音识别的当前文件的位置。 I am using version 3.9 by the way.顺便说一句,我使用的是 3.9 版。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.