File size: 1,492 Bytes
6bd1511
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import gradio as gr
import requests
import os
import dwani

# List of supported languages
LANGUAGES = ["malayalam", "tamil", "telugu", "hindi", "kannada"]
dwani.api_key = os.getenv("DWANI_API_KEY")

dwani.api_base = os.getenv("DWANI_API_BASE_URL")

# Function to extract language name
def get_lang_name(lang_string):
    return lang_string.split("(")[0].strip().lower()

def transcribe_api(audio_file, language):
    # Get the base URL from environment variable
    result = dwani.ASR.transcribe(file_path=audio_file, language=language)
    return result

# Create Gradio interface
with gr.Blocks(title="Speech to Text API Interface") as demo:
    gr.Markdown("# Speech to Text API Interface")
    
    with gr.Row():
        with gr.Column():
            # Input components
            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 component
            output = gr.JSON(label="Transcription Response")
    
    # Connect the button click to the API function
    submit_btn.click(
        fn=transcribe_api,
        inputs=[audio_input, language_input],
        outputs=output
    )

# Launch the interface
demo.launch()