import gradio as gr import librosa from asr import transcribe, ASR_EXAMPLES, ASR_NOTE from lid import identify # Import Language Identification model # Function to detect language and transcribe speech def auto_transcribe(audio): # Detect language (returns language code like "eng" or "swh") detected_lang = identify(audio) # Ensure the detected language is Swahili or English if detected_lang not in ["eng", "swh"]: return "Error: Only English and Swahili are supported." # Transcribe using detected language return transcribe(audio, lang=detected_lang) # Speech-to-Text Interface with Auto Language Detection mms_transcribe = gr.Interface( fn=auto_transcribe, inputs=gr.Audio(), outputs="text", examples=ASR_EXAMPLES, title="Speech-to-Text (Auto Language Detection)", description="Automatically detects whether speech is in Swahili or English and transcribes it.", article=ASR_NOTE, allow_flagging="never", ) # Main Gradio App with gr.Blocks() as demo: gr.Markdown("

MMS Speech-to-Text

") gr.HTML("
Automatically detects and transcribes Swahili or English speech.
") mms_transcribe.render() if __name__ == "__main__": demo.queue() demo.launch()