karen_constantine

Untitled

Nov 20th, 2023
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. from pyttsx3 import init
  2. from datetime import datetime
  3.  
  4. engine = init()
  5. engine.setProperty("rate", 120)
  6. engine.setProperty("volume", 0.9)
  7.  
  8. def talk(text):
  9. engine.say(text)
  10. engine.runAndWait()
  11.  
  12. def take_commands():
  13. recognizer = Recognizer()
  14. with Microphone() as source:
  15. print("Я слушаю...")
  16. audio = recognizer.listen(source)
  17.  
  18. try:
  19. print("Распознавание...")
  20. command = recognizer.recognize_google(audio, language="ru-RU")
  21. print(f"Вы сказали: {command}")
  22. return command.lower()
  23. except UnknownValueError:
  24. print("Извините, не могу распознать голос")
  25. return ""
  26.  
  27. while True:
  28. command1 = take_commands()
  29. print(command1)
  30. if "как дела" in command1:
  31. talk("Нормально")
  32. elif "стоп" in command1:
  33. talk("Ну пока")
  34. break
  35. elif "время" in command1:
  36. current_time = datetime.now().strftime("%I:%M %p")
  37. current_date = datetime.today().strftime("%d.%m.%Y")
  38. talk(f"Сейчас {current_time}, сегодня {current_date}")
  39. else:
  40. talk("Ничего не знаю, только учусь")
  41.  
Advertisement
Add Comment
Please, Sign In to add comment