-
Notifications
You must be signed in to change notification settings - Fork 0
/
listen.py
46 lines (34 loc) · 1.02 KB
/
listen.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
42
43
44
45
46
import translate as ts
import speech_recognition as sr
def listenHindi():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening")
r.pause_threshold = 1
audio = r.listen(source)
try:
print("Recognizing")
Query = r.recognize_google(audio, language="hi-In")
print("the query is printed='", Query, "'")
except Exception as e:
print(e)
print("Say that again sir")
return "None"
print(Query)
Query = ts.translate_hi_en(Query)
return Query
def listenEnglish():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening")
r.pause_threshold = 1
audio = r.listen(source)
try:
print("Recognizing")
Query = r.recognize_google(audio, language="en")
print(Query)
return Query
except Exception as e:
print(e)
print("Say that again sir")
return None