truongghieu commited on
Commit
9035dc4
1 Parent(s): b576a68

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -4,10 +4,10 @@ import numpy as np
4
 
5
 
6
  def recognize_speech(audio_data):
 
 
7
  audio_data = sr.AudioData(audio_data, sample_rate=16000,sample_width=2).get_wav_data(convert_rate=16000, convert_width=2)
8
-
9
  recognizer = sr.Recognizer()
10
-
11
  try:
12
  text = recognizer.recognize_google(audio_data)
13
  return f"Recognized Speech: {text}"
@@ -16,5 +16,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
- iface = gr.Interface(fn=recognize_speech, inputs="microphone", outputs="text")
 
 
20
  iface.launch()
 
4
 
5
 
6
  def recognize_speech(audio_data):
7
+ # nontype to numpy array
8
+ audio_data = np.frombuffer(audio_data, dtype=np.int16)
9
  audio_data = sr.AudioData(audio_data, sample_rate=16000,sample_width=2).get_wav_data(convert_rate=16000, convert_width=2)
 
10
  recognizer = sr.Recognizer()
 
11
  try:
12
  text = recognizer.recognize_google(audio_data)
13
  return f"Recognized Speech: {text}"
 
16
  except sr.RequestError as e:
17
  return f"Could not request results from Google Speech Recognition service; {e}"
18
 
19
+ input_audio = gr.Audio(source="microphone", type="numpy", label="Recording", optional=False)
20
+
21
+ iface = gr.Interface(fn=recognize_speech, inputs=input_audio, outputs="text")
22
  iface.launch()