Spaces:
Sleeping
Sleeping
import gradio as gr | |
import speech_recognition as sr | |
# Speech-to-text conversion function | |
def transcribe_audio(audio): | |
recognizer = sr.Recognizer() | |
with sr.AudioFile(audio) as source: | |
audio_data = recognizer.record(source) | |
try: | |
text = recognizer.recognize_google(audio_data) | |
return text | |
except sr.UnknownValueError: | |
return "Could not understand the audio." | |
except sr.RequestError as e: | |
return f"Speech recognition error: {e}" | |
# Gradio UI | |
def main(): | |
iface = gr.Interface( | |
fn=transcribe_audio, | |
inputs=gr.Audio(sources=["microphone"], type="filepath", label="Speak something"), | |
outputs=gr.Textbox(label="Transcribed Text"), | |
title="Speech-to-Text Demo", | |
description="Speak into the microphone and see the transcribed text below.", | |
live=False | |
) | |
iface.launch() | |
if __name__ == "__main__": | |
main() | |