| import gradio as gr |
| import requests |
| import os |
| import dwani |
|
|
| |
| LANGUAGES = ["malayalam", "tamil", "telugu", "hindi", "kannada"] |
| dwani.api_key = os.getenv("DWANI_API_KEY") |
|
|
| dwani.api_base = os.getenv("DWANI_API_BASE_URL") |
|
|
| |
| def get_lang_name(lang_string): |
| return lang_string.split("(")[0].strip().lower() |
|
|
| def transcribe_api(audio_file, language): |
| |
| result = dwani.ASR.transcribe(file_path=audio_file, language=language) |
| return result |
|
|
| |
| with gr.Blocks(title="Speech to Text API Interface") as demo: |
| gr.Markdown("# Speech to Text API Interface") |
| |
| with gr.Row(): |
| with gr.Column(): |
| |
| audio_input = gr.Audio( |
| label="Audio File", |
| type="filepath", |
| sources=["upload"] |
| ) |
| language_input = gr.Dropdown( |
| label="Language", |
| choices=LANGUAGES, |
| value="kannada" |
| ) |
| |
| submit_btn = gr.Button("Transcribe") |
| |
| with gr.Column(): |
| |
| output = gr.JSON(label="Transcription Response") |
| |
| |
| submit_btn.click( |
| fn=transcribe_api, |
| inputs=[audio_input, language_input], |
| outputs=output |
| ) |
|
|
| |
| demo.launch() |