Advertisement
Savelyev_Vyacheslav

helper

Apr 15th, 2021
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.93 KB | None | 0 0
  1. import pyaudio
  2. import speech_recognition as sr
  3. import os
  4. import pyttsx3
  5. import random
  6. import webbrowser
  7.  
  8. r = sr.Recognizer()
  9. voice = pyttsx3.init()
  10. voice.say("Здравствуйте, я ваш голосовой помощник")
  11. voice.runAndWait()
  12. greetings = ["Привет", "Здравствуйте", "Доброго времени суток", "Хай", "Ку"]
  13.  
  14. while True:
  15.     with sr.Microphone(device_index=1) as source:
  16.         print("Скажите что-нибудь ...")
  17.         audio = r.listen(source)
  18.  
  19.     try:
  20.         speech = r.recognize_google(audio, language="ru_RU").lower()
  21.         print("Вы сказали: " + speech)
  22.         if speech.find("привет") >= 0 or speech.find("хай") >=0:
  23.             voice.say(random.choice(greetings))
  24.             voice.runAndWait()
  25.         elif speech.find("ты кто") >= 0:
  26.             voice.say("Меня зовут РОБОТ!")
  27.             voice.runAndWait()
  28.         elif speech.find("открой папку") >= 0 or speech.find("папка") >=0:
  29.             os.startfile("D:абочий стол 2021.02.13")
  30.             voice.say("Игра запущена")
  31.             voice.runAndWait()
  32.         elif "вк" in speech:
  33.             webbrowser.open_new("https://vk.com/feed")
  34.             voice.say("ВК запущен")
  35.             voice.runAndWait()
  36.         elif speech.find("пока") >= 0 or speech.find("до свидания") >=0:
  37.             voice.say("До свидания")
  38.             voice.runAndWait()
  39.             break
  40.         else:
  41.             voice.say("Я вас не понимаю, повторите пожалуйста")
  42.             voice.runAndWait()
  43.     except:
  44.         print("Ошибка, я вас не услышала")
  45.  
  46.    
  47.  #  https://docs.google.com/document/d/1cA-KVjD3N5iY30xS_3w8YCnv4L7jyuDv4LB3XtjtmpU/edit
  48.  #  https://docs.google.com/document/d/1ycfepnGu9k9S267EVPDy8ze7zWdN7Nuul57aYLrrVa8/edit
  49.  
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement