Spaces:
Build error
Build error
Create new file
Browse files
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import speech_recognition as sr
|
2 |
+
from googletrans import Translator
|
3 |
+
|
4 |
+
def transcribeHindi():
|
5 |
+
|
6 |
+
r = sr.Recognizer()
|
7 |
+
with sr.Microphone() as source:
|
8 |
+
|
9 |
+
# seconds of non-speaking audio before
|
10 |
+
# a phrase is considered complete
|
11 |
+
print('Listening')
|
12 |
+
r.pause_threshold = 0.7
|
13 |
+
audio = r.listen(source)
|
14 |
+
try:
|
15 |
+
print("Recognizing")
|
16 |
+
Query = r.recognize_google(audio, language='hi-In')
|
17 |
+
|
18 |
+
# for listening the command in indian english
|
19 |
+
print("the query is printed='", Query, "'")
|
20 |
+
|
21 |
+
# handling the exception, so that assistant can
|
22 |
+
# ask for telling again the command
|
23 |
+
except Exception as e:
|
24 |
+
print(e)
|
25 |
+
print("Say that again sir")
|
26 |
+
return "None"
|
27 |
+
return Query
|
28 |
+
|
29 |
+
def translate():
|
30 |
+
translator = Translator()
|
31 |
+
translation = translator.translate(query, dest='en')
|
32 |
+
return translation.text
|
33 |
+
|
34 |
+
gr.Interface(
|
35 |
+
fn=transcribeHindi,
|
36 |
+
inputs=gr.Audio(source="microphone", type="filepath"),
|
37 |
+
outputs="text").launch()
|