-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpeechRecog.py
41 lines (30 loc) · 1.15 KB
/
SpeechRecog.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 as sr
def parseCommand(lang):
listener = sr.Recognizer()
if lang=='en-GB':
print("Listening for a command...")
with sr.Microphone() as source:
listener.pause_threshold=2
input_speech=listener.listen(source)
try:
print("Recognizing speech...")
query=listener.recognize_google(input_speech,language=lang)
print(f"said text is : {query}")
except Exception as exception:
print("I did not quite catch that.")
print(exception)
return 'None'
else:
print("Ascultand o comanda...")
with sr.Microphone() as source:
listener.pause_threshold=2
input_speech=listener.listen(source)
try:
print("Transcriere voce in text ...")
query=listener.recognize_google(input_speech,language=lang)
print(f"Textul spus este : {query}")
except Exception as exception:
print("Nu am inteles ce ai spus.")
print(exception)
return 'None'
return query