File size: 1,290 Bytes
0f1e860
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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()