Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,12 +9,20 @@ def listen(audio):
|
|
| 9 |
# with wave.open(audio, 'rb') as audio_file:
|
| 10 |
# sample_width = audio_file.getsampwidth()
|
| 11 |
audio = sr.AudioData(audio_data, sample_rate=sample_rate,sample_width=sample_width)
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
|
| 20 |
gr.Interface(fn=listen,inputs="audio",outputs="text").launch()
|
|
|
|
| 9 |
# with wave.open(audio, 'rb') as audio_file:
|
| 10 |
# sample_width = audio_file.getsampwidth()
|
| 11 |
audio = sr.AudioData(audio_data, sample_rate=sample_rate,sample_width=sample_width)
|
| 12 |
+
with open("Voice/audio_file.wav", "wb") as f:
|
| 13 |
+
f.write(audio.get_wav_data())
|
| 14 |
+
|
| 15 |
+
audio_file = sr.AudioFile("Voice/audio_file.wav")
|
| 16 |
+
|
| 17 |
+
# use the recognizer with the AudioFile
|
| 18 |
+
r = sr.Recognizer()
|
| 19 |
+
with audio_file as source:
|
| 20 |
+
audio = r.record(source)
|
| 21 |
+
try:
|
| 22 |
+
text = r.recognize_google(audio, language='ur')
|
| 23 |
+
return text
|
| 24 |
+
except:
|
| 25 |
+
return "Sorry could not recognize what you said"
|
| 26 |
|
| 27 |
|
| 28 |
gr.Interface(fn=listen,inputs="audio",outputs="text").launch()
|