ModuleNotFoundError: No module named 'speech_recognition' (windows COMPUTER)

ModuleNotFoundError: No module named 'speech_recognition' (windows COMPUTER)

我的安装命令是:

pip install speechrecognition
pip install pyAudio

在我的文件中它引发了这个错误:

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'

我的代码是:

import speech_recognition as sr

如前所述,正确的命令是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

您想确保异常处理程序在那里。这是根据文档完成的。

编辑

问题也可能是 Python 的版本。 Python 3.7 及更高版本不支持 SpeechRecognition。我针对 Python 3.6 对其进行了测试,它运行良好。他们确实需要为较新的 Python 版本发布工作版本。

我修复了错误! 我不知道错误是什么,但它已修复!

我遇到了同样的问题。使用 Visual Studio 代码。发现我的 python 解释器查看了错误的虚拟环境。我使用 control + shift + P 将位置更改为我安装语音识别的当前文件的位置。顺便说下我用的是3.9版本