-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvoice.py
More file actions
38 lines (26 loc) · 659 Bytes
/
Copy pathvoice.py
File metadata and controls
38 lines (26 loc) · 659 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
37
38
import speech_recognition as sr
import pyttsx3
def take_cmd():
r = sr.Recognizer()
with sr.Microphone() as source:
print('Listening...')
r.pause_threshold = 1
audio = r.listen(source)
print(audio)
try:
print('Recognizing...')
query = r.recognize_google(audio,language='en-in')
print(f'user said : {query}')
except:
print('please say that Again ')
return 'None'
return query
def speak(cmd):
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice',voices[0].id)
engine.say(cmd)
engine.runAndWait()
if __name__ == '__main__':
query = take_cmd().lower()
print(query)