Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Сначала установите библиотеки:
- pip install SpeechRecognition
- pip install datetime
- pip install pyttsx3
- #Далее сам код:
- from pyttsx3 import init
- from datetime import datetime
- engine = init()
- engine.setProperty("rate", 120)
- engine.setProperty("volume", 0.9)
- def talk(text):
- engine.say(text)
- engine.runAndWait()
- def take_commands():
- recognizer = Recognizer()
- with Microphone() as source:
- print("Я слушаю...")
- audio = recognizer.listen(source)
- try:
- print("Распознавание...")
- command = recognizer.recognize_google(audio, language="ru-RU")
- print(f"Вы сказали: {command}")
- return command.lower()
- except UnknownValueError:
- print("Извините, не могу распознать голос")
- return ""
- while True:
- command1 = take_commands()
- print(command1)
- if "как дела" in command1:
- talk("Нормально")
- elif "стоп" in command1:
- talk("Ну пока")
- break
- elif "время" in command1:
- current_time = datetime.now().strftime("%I:%M %p")
- current_date = datetime.today().strftime("%d.%m.%Y")
- talk(f"Сейчас {current_time}, сегодня {current_date}")
- else:
- talk("")
Advertisement
Add Comment
Please, Sign In to add comment