truongghieu's picture
Update app.py
c143727
raw
history blame
616 Bytes
import speech_recognition as sr
import gradio as gr
def recognize_speech(audio_data):
audio_data = sr.AudioData(audio_data, sample_rate=16000,sample_width=2)
recognizer = sr.Recognizer()
try:
text = recognizer.recognize_google(audio_data)
return f"Recognized Speech: {text}"
except sr.UnknownValueError:
return "Speech Recognition could not understand audio."
except sr.RequestError as e:
return f"Could not request results from Google Speech Recognition service; {e}"
iface = gr.Interface(fn=recognize_speech, inputs="microphone", outputs="text")
iface.launch()