#python #error-handling #youtube #speech-recognition #alexa
Вопрос:
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:Users97150PycharmProjectspythonProject3main.py», строка 69, в файле query = takeCommand().lower () «C:Users97150PycharmProjectspythonProject3main.py», строка 40, в команде r = sr.Распознаватель() Ошибка атрибута: модуль «speech_recognition» не имеет атрибута «Распознаватель»
Process finished with exit code 1