【问题标题】:ImportError: No module named SpeechRecognitionImportError:没有名为 SpeechRecognition 的模块
【发布时间】:2021-09-14 23:54:29
【问题描述】:

我的代码是

import SpeechRecognition as sr

# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
    print("Say something!")
    audio = r.listen(source)

# recognize speech using Microsoft Bing Voice Recognition
BING_KEY = "Somevalue"  # Microsoft Bing Voice Recognition API keys 32-character lowercase hexadecimal strings
try:
    print("Microsoft Bing Voice Recognition thinks you said " + r.recognize_bing(audio, key=BING_KEY))
except sr.UnknownValueError:
    print("Microsoft Bing Voice Recognition could not understand audio")
except sr.RequestError as e:
    print("Could not request results from Microsoft Bing Voice Recognition service; {0}".format(e))

当我运行它时,我得到了

ImportError: No module named SpeechRecognition

我想我确实安装了这个模块:

>pip list
SpeechRecognition (3.6.5)

git仓库给出的代码是这样的

import speech_recognition as sr

但它也不起作用

【问题讨论】:

  • 您确定使用相同的环境来安装软件包并运行您的脚本?您是否可能使用 pip 安装和 python3 运行它或 pip3 安装和 python(符号链接到 python2)运行?
  • @Daniel 我用 pip 安装并作为 Python 运行
  • 我刚试过(安装和导入),确实,正确的包名是speech_recognition。我敢打赌@Daniel 所说的。
  • 琐碎检查和更多信息:python --versionpip --versionpip install SpeechRecognitionpython -m speech_recognition。在同一个控制台中运行所有这些并评论它们的输出。
  • >python --version Python 2.7.10 >pip --version pip 9.0.1 from /usr/local/lib/python2.7/site-packages (python 2.7) >pip install SpeechRecognition 要求已经满意:/usr/local/lib/python2.7/site-packages 中的 SpeechRecognition >python -m speech_recognition /usr/bin/python:没有名为 Speech_recognition 的模块

标签: python pip speech-recognition


【解决方案1】:

我认为问题是

import SpeechRecognition as sr

你应该在哪里使用

import speech_recognition as sr

【讨论】:

    猜你喜欢
    • 2018-02-24
    • 1970-01-01
    • 2013-03-11
    • 2012-12-07
    • 2012-05-23
    • 2019-07-29
    • 2015-07-04
    • 2014-03-15
    • 2017-12-29
    相关资源
    最近更新 更多