简体   繁体   English

ModuleNotFoundError:没有名为“speech_recognition”的模块(Windows 计算机)

[英]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.

相关问题 ModuleNotFoundError:没有名为“ speech_recognition”的模块 - ModuleNotFoundError: No module named 'speech_recognition' ImportError:python IDLE 中没有名为“speech_recognition”的模块 - ImportError: No module named 'speech_recognition' in python IDLE 我没有安装名为“Speech_Recognition”的模块,但仍然显示找不到模块 - No module named 'Speech_Recognition' I have installed but still showing module not found python speech_recognition模块占用麦克风 - python speech_recognition module occupies microphone 语音识别:AttributeError:模块“ speech_recognition”没有属性“ Recognizer” - Speech Recognition: AttributeError: module 'speech_recognition' has no attribute 'Recognizer' speech_recognition无法导入pyaudio; ModuleNotFoundError - speech_recognition can't import pyaudio; ModuleNotFoundError 属性错误:模块“ speech_recognition”没有属性“ Recognizer” - Attribute error:module 'speech_recognition' has no attribute 'Recognizer' 如何使用 Speech_recognition 修复模块导入错误? - How to fix Module Import Error with speech_recognition? 使用语音识别模块 PYTHON 中的麦克风()时出错 - Error using Microphone() from speech_recognition module PYTHON speech_recognition模块卡在“说些什么”中-python - speech_recognition module stuck in “say something” - python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM