import gradio as gr import speech_recognition as sr def speech_to_text_from_file(audio_file): recognizer = sr.Recognizer() try: with sr.AudioFile(audio_file) as source: audio = recognizer.record(source) text = recognizer.recognize_google(audio) return text except sr.UnknownValueError: return "❌ Could not understand the audio." except sr.RequestError: return "❌ API unavailable or internet issue." except Exception as e: return f"❌ Error: {str(e)}" iface = gr.Interface( fn=speech_to_text_from_file, inputs=gr.Audio(type="filepath", label="Upload Audio File (WAV/FLAC/AIFF)"), outputs=gr.Textbox(label="Transcribed Text"), title="🗣️ Speech-to-Text Converter", description="Upload an audio file (WAV, FLAC, AIFF) to get a text transcription using Google Speech Recognition.", allow_flagging="never" ) if __name__ == "__main__": iface.launch()