-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.py
More file actions
36 lines (27 loc) · 902 Bytes
/
Main.py
File metadata and controls
36 lines (27 loc) · 902 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
import speech_recognition as sr
import pyttsx3
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice',voices[0].id)
def takeCommand ():
r = sr.Recognizer()
with sr.Microphone(0) as source :
audio = r.listen(source,None,5) # taking and listening audio
try : # recognizing the command
query = r.recognize_google(audio, language = 'en-in')
return query
except Exception as e : # error handling
print('Please say it again')
return ' '
# speak the text
def speak(text):
engine.say(text)
engine.runAndWait()
query = takeCommand()
while 'activate' not in query.lower():
query = takeCommand()
if ('activate') in query.lower() :
folder_dir = 'Assistant.py'
os.startfile(os.path.join(folder_dir))
speak('activating AI.....')