Answer the question
In order to leave comments, you need to log in
Unknown crash, mb error in the code?
I don’t know why, but after some time using the assistant, it just crashes.
import speech_recognition
from gtts import gTTS
import random
import time
import playsound
import speech_recognition as sr
import pyttsx3
def listen_command():
#return input("Чего желаете? ")
r = sr.Recognizer()
with sr.Microphone() as source:
print('Говорите : ')
r.pause_threshold = 1
r.adjust_for_ambient_noise(source, duration=1)
audio = r.listen(source)
try:
exersize = r.recognize_google(audio, language="ru-Ru").lower()
print('Вы сказали : ' + exersize)
except sr.UnknownValueError:
talk('Я вас не поняла , повторите пожалуйста ')
exersize = commands()
return exersize
def do_this_command(message):
message = message.lower()
if "привет" in message:
say_message("Здравствуйте, хозяин!")
elif "как дела" in message:
say_message("Всё отлично, у Вас?")
elif "что ты умеешь" in message:
say_message("Я могу ...")
elif "какое сейчас время" in message:
say_message("Сейчас"+str(time.time()))
elif "пока" in message:
say_message("Рад служить Вам")
exit()
else:
say_message("Команда не распознана.")
def say_message(message):
voice = gTTS(message, lang="ru")
filevoicename = "_audio_"+str(time.time())+str(random.randint(0,100000))+".mp3"
voice.save(filevoicename)
playsound.playsound(filevoicename)
print("Jarvis say"+message)
if __name__ == '__main__':
while True:
command = listen_command()
do_this_command(command)
Вы сказали : какое сейчас время
Jarvis sayКоманда не распознана.
Говорите :
Traceback (most recent call last):
File "C:\Users\User\PycharmProjects\Jarvis\main.py", line 20, in listen_command
exersize = r.recognize_google(audio, language="ru-Ru").lower()
File "C:\Users\User\PycharmProjects\Jarvis\venv\lib\site-packages\speech_recognition\__init__.py", line 858, in recognize_google
if not isinstance(actual_result, dict) or len(actual_result.get("alternative", [])) == 0: raise UnknownValueError()
speech_recognition.UnknownValueError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\User\PycharmProjects\Jarvis\main.py", line 55, in <module>
command = listen_command()
File "C:\Users\User\PycharmProjects\Jarvis\main.py", line 23, in listen_command
talk('Я вас не поняла , повторите пожалуйста ')
NameError: name 'talk' is not defined
Process finished with exit code 1
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question