-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmalayalam speech recognition.py
42 lines (31 loc) · 1.07 KB
/
malayalam speech recognition.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
import speech_recognition as sr
def MAL():
r = sr.Recognizer()
with sr.Microphone() as source:
print('Listening')
r.pause_threshold = 0.7
#for noise cancellation
r.adjust_for_ambient_noise(source)
#time for recording
audio = r.listen(source,phrase_time_limit=4)
try:
print("Recognizing")
Query = r.recognize_google(audio, language='ml-In')
#Displaying the recognized text in Malayalam
print("The Text is='", Query, "'")
return Query
#To raise exception if no speech was recognized or no audio was played
except Exception as e:
print(e)
print("we didnt get you")
return "None"
return Query
#function for translating malayalam into english
def trans(query):
from googletrans import Translator
translator = Translator()
result = translator.translate(query,dest='en', src='auto')
return result
query=MAL()
text=trans(query)
print(text.text)