-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.py
41 lines (31 loc) · 1.12 KB
/
commands.py
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
39
40
41
import speech_recognition
from colorama import Fore, Style
def takeCommand():
r = speech_recognition.Recognizer()
with speech_recognition.Microphone() as source:
print(Fore.YELLOW + 'Listening....' + Style.RESET_ALL)
r.pause_threshold = 1
audio = r.listen(source)
try:
print(Fore.YELLOW + 'Recognizing....' + Style.RESET_ALL)
query = r.recognize_google(audio, language='en-UK')
print(query)
except Exception as ex:
print(ex)
print(Fore.YELLOW + 'Please tell again' + Style.RESET_ALL)
return 'None'
return query
def takeCommand_without_print():
r = speech_recognition.Recognizer()
with speech_recognition.Microphone() as source:
print(Fore.YELLOW + 'Listening....' + Style.RESET_ALL)
r.pause_threshold = 1
audio = r.listen(source)
try:
print(Fore.YELLOW + 'Recognizing....' + Style.RESET_ALL)
query = r.recognize_google(audio, language='en-UK')
except Exception as ex:
print(ex)
print(Fore.YELLOW + 'Please tell again' + Style.RESET_ALL)
return 'None'
return query