ai virtual assistant

Solutions on MaxInterview for ai virtual assistant by the best coders in the world

showing results for - "ai virtual assistant"
Lily-Rose
05 Nov 2020
1import os
2import time
3import webbrowser
4from datetime import date
5import playsound
6import speech_recognition as sr
7from gtts import gTTS
8import wikipedia
9from datetime import datetime
10
11WAKE = 'Sam'
12
13
14def speak111(text):
15    tts = gTTS(text=text, lang="en")
16    filename = "b.mp3"
17    playsound.playsound(filename)
18
19
20def speak1000(text):
21    tts = gTTS(text=text, lang="en")
22    filename = "bbvhdzdzhuif.mp3"
23    tts.save(filename)
24    playsound.playsound(filename)
25
26
27def speak100(text):
28    tts = gTTS(text=text, lang="en")
29    filename = "bumakdg.mp3"
30    playsound.playsound(filename)
31
32
33def speak12(text):
34    tts = gTTS(text=text, lang="en")
35    filename = "dck.mp3"
36    playsound.playsound(filename)
37
38
39def speak2(text):
40    tts = gTTS(text=text, lang="en")
41    filenam = "vo.mp3"
42    playsound.playsound(filenam)
43
44
45def speak3(text):
46    tts = gTTS(text=text, lang="en")
47    filenam = "voi.mp3"
48    playsound.playsound(filenam)
49
50
51def speak4(text):
52    tts = gTTS(text=text, lang="en")
53    filenam = "voic.mp3"
54    playsound.playsound(filenam)
55
56
57def speak5(text):
58    tts = gTTS(text=text, lang="en")
59    filename = "voic.mp3"
60    playsound.playsound(filename)
61
62
63def speak1(text):
64    tts = gTTS(text=text, lang="en")
65    filename = "voice1.mp3"
66    playsound.playsound(filename)
67
68
69def get_audio():
70    r = sr.Recognizer()
71    with sr.Microphone() as source:
72        audio = r.listen(source)
73        said = ""
74
75        try:
76            said = r.recognize_google(audio)
77            print(said)
78        except Exception as e:
79            said = None
80    return said
81
82
83def speak(text):
84    tts = gTTS(text=text, lang="en")
85    filename = "v.mp3"
86    tts.save(filename)
87    playsound.playsound(filename)
88
89
90while True:
91    text = get_audio()
92    if text is not None:
93        if "hello" == text:
94            speak("hello, how are you?")
95            print("hello, how are you?")
96        elif "what is your name" == text:
97            speak2("My name is Sam")
98            print("My name is Sam")
99        elif 'open YouTube' == text:
100            webbrowser.open_new_tab('https://www.youtube.com/')
101        elif 'tell me the news' == text:
102            webbrowser.open_new_tab('https://www.bbc.co.uk/newsround')
103        elif 'open my maps' == text:
104            webbrowser.open_new_tab('https://www.mymaths.co.uk/')
105        elif 'open HW' == text:
106            webbrowser.open_new_tab('https://www.satchelone.com/todos/issued')
107        elif 'open mail' == text:
108            webbrowser.open_new_tab('https://outlook.office365.com/mail/inbox')
109        elif 'what is the weather' == text or 'tell me the weather' == text or 'tell me the weather in barkingside' == text:
110            webbrowser.open_new_tab(
111                'https://www.google.com/search?q=weather&oq=weather&aqs=chrome..69i57j0j69i59l2j0l4.2886j1j7&sourceid=chrome&ie=UTF-8')
112        elif 'open' == text:
113            webbrowser.open('https://www.google.com/search?q=gmail')
114        elif 'tell me the time' == text:
115            now = datetime.now()
116            current_time = now.strftime("%H:%M")
117            print("Current Time =", current_time)
118            speak('the time is' + current_time)
119        elif 'tell me the date' == text or 'what is the time' == text:
120            today = date.today()
121            print("Today's date:", today)
122        elif 'Google' in text:
123            speak12('searching Google')
124            print('searching Google')
125            text = text.replace(' on Google', '')
126            webbrowser.open_new_tab('https://www.google.com/search?q={}'.format(text))
127        elif 'YouTube' in text:
128            speak111('searching Youtube')
129            print('searching Youtube')
130            text = text.replace('on YouTube', '')
131            webbrowser.open_new_tab('https://www.Youtube.com/search?q={}'.format(text))
132        elif 'play' in text:
133            speak111('searching Youtube')
134            print('searching Youtube')
135            text = text.replace('play', '')
136            webbrowser.open_new_tab('https://www.Youtube.com/search?q={}'.format(text))
137        elif 'Wikipedia' in text:
138            speak3('searching wikipedia')
139            print('searching wikipedia')
140            text = text.replace('wikipedia', '')
141            results = wikipedia.summary(text, sentences=2)
142            speak4(results)
143            print(results)