File size: 2,471 Bytes
14e7fb7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
"""
doc string
"""
import logging
import os
import time
import uuid
import gradio as gr
import soundfile as sf
from model import get_pretrained_model

title = "# Danish Text To Speech"
css = """
.result {display:flex;flex-direction:column}
.result_item {padding:15px;margin-bottom:8px;border-radius:15px;width:100%}
.result_item_success {background-color:mediumaquamarine;color:white;align-self:start}
.result_item_error {background-color:#ff7070;color:white;align-self:start}
"""

def process(text: str, sid: str):
    """
    doc string
    """
    repo_id = "csukuangfj/vits-piper-da_DK-talesyntese-medium"
    speed = 1
    sid = int(sid)
    tts = get_pretrained_model(repo_id, speed)
    start = time.time()
    audio = tts.generate(text, sid = sid)
    if len(audio.samples) == 0:
        raise ValueError(
            "Error in generating audios. Please read previous error messages."
        )
    filename = str(uuid.uuid4())
    filename = f"{filename}.wav"
    sf.write(
        filename,
        audio.samples,
        samplerate = audio.sample_rate,
        subtype = "PCM_16",
    )
    return filename

demo = gr.Blocks(css=css)
with demo:
    gr.Markdown(title)
    with gr.Tabs():
        with gr.TabItem("Please input your text"):
            input_text = gr.Textbox(
                label="Input text",
                info="Your text",
                lines=3,
                placeholder="Please input your text here",
            )
            input_sid = gr.Textbox(
                label="Speaker ID",
                info="Speaker ID",
                lines=1,
                max_lines=1,
                value="0",
                placeholder="Speaker ID. Valid only for mult-speaker model",
                visible = False
            )
            input_button = gr.Button("Submit")

            output_audio = gr.Audio(label="Output")

            output_info = gr.HTML(label="Info")
        input_button.click(
            process,
            inputs=[
                input_text,
                input_sid
            ],
            outputs=[
                output_audio
            ],
        )

def download_espeak_ng_data():
    """
    doc string
    """
    os.system(
    """
    cd /tmp
    wget -qq https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/espeak-ng-data.tar.bz2
    tar xf espeak-ng-data.tar.bz2
    """
    )

if __name__ == "__main__":
    download_espeak_ng_data()
    demo.launch(share = True)