File size: 1,674 Bytes
cc62aa8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from voice_processing import tts, get_model_names, voice_mapping


model_names = get_model_names()

def on_convert_click(model_name, tts_text, selected_voice, slang_rate, use_uploaded_voice, voice_upload):
    # Use the imported 'tts' function from voice_processing
    info, edge_tts_output_path, tts_output_data = tts(
        model_name, tts_text, selected_voice, slang_rate, use_uploaded_voice, voice_upload
    )
    return info, edge_tts_output_path, tts_output_data

# Define Gradio interface
app = gr.Blocks()

with app:
    # Define your Gradio components here
    with gr.Row():
        model_name = gr.Dropdown(label="Model", choices=model_names, value=model_names[0] if model_names else None)
        tts_voice = gr.Dropdown(label="Speaker", choices=list(voice_mapping.keys()), value="Mongolian Male")
        slang_rate = gr.Slider(minimum=0, maximum=1, label="Slang rate", value=0.75, interactive=True)
    
    with gr.Row():
        use_uploaded_voice = gr.Checkbox(label="Use uploaded voice file", value=False)
        voice_upload = gr.File(label="Upload voice file")
        tts_text = gr.Textbox(label="Input Text", value="Текстыг оруулна уу.")
        but0 = gr.Button("Convert", variant="primary")

    with gr.Row():
        info_text = gr.Textbox(label="Output info")
        edge_tts_output = gr.Audio(label="Voice", type="filepath")
        tts_output = gr.Audio(label="Result")

    but0.click(
        on_convert_click,
        inputs=[model_name, tts_text, tts_voice, slang_rate, use_uploaded_voice, voice_upload],
        outputs=[info_text, edge_tts_output, tts_output]
    )

# Launch the app
app.launch()