Project_1 / app.py
Futuresony's picture
Create app.py
0f1e860 verified
raw
history blame
1.29 kB
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 automatically
def auto_detect_and_transcribe(audio):
detected_lang = identify(audio) # Identify language from audio
if detected_lang in ["swh", "eng"]: # Ensure it's either Swahili or English
return f"[Detected Language: {detected_lang.upper()}]\n\n" + transcribe(audio)
return "Error: Unsupported language detected."
# Speech-to-Text Interface with Auto Language Detection
mms_transcribe = gr.Interface(
fn=auto_detect_and_transcribe,
inputs=gr.Audio(),
outputs="text",
examples=ASR_EXAMPLES,
title="Speech-to-Text (Automatic Language Detection)",
description="Upload or record audio, and the model will detect if it is Swahili or English before transcribing.",
article=ASR_NOTE,
allow_flagging="never",
)
# Main Gradio App
with gr.Blocks() as demo:
gr.Markdown("<p align='center' style='font-size: 20px;'>MMS Speech-to-Text</p>")
gr.HTML("<center>Convert speech to text while automatically detecting Swahili or English.</center>")
mms_transcribe.render()
if __name__ == "__main__":
demo.queue()
demo.launch()