import speech_recognition as sr
import os
import sys
import webbrowser
import pyttsx3
import pyowm
import datetime
import time
owm = pyowm.OWM('f58349d7f89f82766b104bc8b3f318b1',language='ru')
engine = pyttsx3.init()
def talk(words):
print(words)
engine.say(words)
engine.runAndWait()
talk('Здравствуйте, попросите что-нибудь : ')
def commands():
r = sr.Recognizer()
with sr.Microphone() as source:
print('Говорите : ')
r.pause_threshold = 0.5
r.adjust_for_ambient_noise(source, duration=1)
audio = r.listen(source)
try:
exersize = r.recognize_google(audio, language="ru-Ru").lower()
talk('Вы сказали : ' + exersize)
except sr.UnknownValueError:
talk('Я вас не поняла ')
exersize = commands()
return exersize
def makeSomeThing(exersize):
if 'открой гугл' in exersize:
talk('Сию минуту' )
url = '
https://www.google.com/'
webbrowser.open(url)
elif 'имя' in exersize:
talk('Меня зовут Данелия')
elif 'время' in exersize:
now = datetime.datetime.now()
talk("Сейчас " + str(now.hour) + ':' + str(now.minute))
elif 'стоп' in exersize:
talk('Да, конечно')
sys.exit()
elif 'погода' in exersize:
talk('Скажите город в котором хотите узнать погоду: ')
r = sr.Recognizer()
with sr.Microphone() as source1:
audio = r.listen(source1)
nameOFcity = r.recognize_google(audio, language="ru-Ru").lower()
observation = owm.weather_at_place(nameOFcity)
w = observation.get_weather()
temp = w.get_weather('celsius')["temp"]
talk(' В городе ' + str(nameOFcity) + ' сейчас ' + w.get_detailed_status() + '\n')
talk('Температура в районе ' + str(temp) + '\n\n')
while True:
makeSomeThing(commands())