python - AttributeError:部分初始化的模块“speech_recognition”没有属性“Recognizer”(很可能是由于循环导入)
问题描述
import speech_recognition as sr
import pyttsx3
import pywhatkit
import datetime
import wikipedia
import pyjokes
listener = sr.Recognizer()
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)
print('Getting ready...')
def talk(text):
engine.say(text)
engine.runAndWait()
def take_command():
try:
with sr.Microphone() as source:
print('listening...')
voice = listener.listen(source)
command = listener.recognize_google(voice)
command = command.lower()
if 'alexa' in command:
command = command.replace('alexa', '')
print(command)
except:
pass
return command
def run_alexa():
command = take_command()
print(command)
if 'play' in command:
song = command.replace('play', '')
talk('playing ' + song)
pywhatkit.playonyt(song)
elif 'time' in command:
time = datetime.datetime.now().strftime('%I:%M %p')
talk('Current time is ' + time)
elif 'who the heck is' in command:
person = command.replace('who the heck is', '')
info = wikipedia.summary(person, 1)
print(info)
talk(info)
elif 'joke' in command:
talk(pyjokes.get_joke())
else:
talk('Please say the command again.')
while True:
run_alexa()
我正在尝试用 python 制作语音助手。每当我尝试运行时,都会出现此错误。我下载了所有文件,一切都很好,请帮助。
回溯(最后一次调用):文件“C:\Users\97150\PycharmProjects\pythonProject3\main.py”,第 69 行,查询 = takeCommand().lower() 文件“C:\Users\97150\PycharmProjects\ pythonProject3\main.py",第 40 行,在 takeCommand r = sr.Recognizer() AttributeError: module 'speech_recognition' has no attribute 'Recognizer'
Process finished with exit code 1
解决方案
推荐阅读
- vue.js - vuex + vuexfire - 添加数据时存储对象不会更新
- r - R CRAN Check - 临时目录中的碎屑
- rest - NetSuite Rest API 获取商品价格
- c - 指向 N 元素数组的指针与指向数组或数组第一个元素的指针
- python - 使用 python opencv 清理 ocr 图像
- opennebula - opennebula 升级无法解析 oned.conf
- opentok - Opentok 连接质量为空
- python - Python 嵌套 elif,for
- python-3.x - 我怎样才能让 flake8 捕捉到这个错误?
- highcharts - highcharts 7 带有负刻度的问题