Spaces:
Sleeping
Sleeping
truongghieu
commited on
Commit
•
3f8ba92
1
Parent(s):
ea316fd
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,13 @@ import numpy as np
|
|
5 |
|
6 |
def recognize_speech(audio_data):
|
7 |
# nontype to wav
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
recognizer = sr.Recognizer()
|
11 |
try:
|
@@ -16,6 +22,7 @@ def recognize_speech(audio_data):
|
|
16 |
except sr.RequestError as e:
|
17 |
return f"Could not request results from Google Speech Recognition service; {e}"
|
18 |
|
|
|
19 |
|
20 |
-
iface = gr.Interface(fn=recognize_speech, inputs=
|
21 |
iface.launch()
|
|
|
5 |
|
6 |
def recognize_speech(audio_data):
|
7 |
# nontype to wav
|
8 |
+
# tuple(sample_rate, numpy array)
|
9 |
+
# get numpy array
|
10 |
+
# get sample rate
|
11 |
+
# convert to AudioData
|
12 |
+
# recognize speech
|
13 |
+
# return text
|
14 |
+
audio_data = sr.AudioData(np.array(audio_data[1]), sample_rate=audio_data[0] , sample_width=2)
|
15 |
|
16 |
recognizer = sr.Recognizer()
|
17 |
try:
|
|
|
22 |
except sr.RequestError as e:
|
23 |
return f"Could not request results from Google Speech Recognition service; {e}"
|
24 |
|
25 |
+
audio_input = gr.Audio(source="microphone", type="numpy", sample_rate=16000)
|
26 |
|
27 |
+
iface = gr.Interface(fn=recognize_speech, inputs=audio_input , outputs="text")
|
28 |
iface.launch()
|