Voice M
Voice M
Sem - IV
by
AIML19_Khatre Aditi Anant
AIML67_Kazi Muskan Taufiq
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def wishme():
hour = int(datetime.datetime.now().hour)
if hour > 0 and hour <=12:
speak("Good Morning!")
elif hour > 12 and hour < 18:
speak("Good Afternoon!")
elif hour > 18 and hour < 21:
speak("Good Evening!")
else:
speak("Good Night!")
speak("I am Assistant. How may I help you ?")
def Command():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 1
audio = r.listen(source)
try:
print("Recognizing...")
query = r.recognize_google(audio, language='en-in')
print("You said: ", query, "\n")
except Exception as e:
print("Say that again...")
speak("Say that again...")
return "none"
return query
except Exception as e:
print(e)
if _name_ == '_main_':
wishme()
while True:
query = Command().lower()
os.startfile("C:\\Users\\MEHZABEEN\\AppData\\Roaming\\Microsoft\\Windows\\Start
Menu\\Programs\\Chrome Apps")
os.startfile("C:\\Users\\MEHZABEEN\\AppData\\Roaming\\Microsoft\\Windows\\Start
Menu\\Programs\\Chrome Apps")
def weather_data(query):
res = requests.get('http://api.openweathermap.org/data/2.5/weather?' +
query + '&APPID=b35975e18dc93725acb092f7272cc6b8&units=metric')
return res.json()
def main():
city = "Mumbai"
print()
try:
query = 'q=' + city;
w_data = weather_data(query)
print_weather(w_data, city)
print()
except:
print('City name not found...')
speak('City name not found...')
if _name_ == 'main':
main()