File size: 5,077 Bytes
0d80816
 
 
ea32d9a
0d80816
 
 
 
b07c30e
0d80816
 
 
 
 
 
ea32d9a
 
b37a421
 
 
 
ea32d9a
 
 
b07c30e
0d80816
 
 
 
 
b07c30e
 
0d80816
ea32d9a
 
 
0d80816
8129b0f
b07c30e
 
0d80816
 
90c437b
0d80816
 
 
 
 
 
 
 
ea32d9a
0d80816
 
 
b07c30e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90c437b
b07c30e
 
0d80816
b07c30e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0d80816
b07c30e
0d80816
9da2dd2
0d80816
 
 
 
2afaead
b07c30e
 
90c437b
 
b07c30e
90c437b
b07c30e
90c437b
0d80816
 
 
b07c30e
0d80816
 
b07c30e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1768f9f
b07c30e
 
 
90c437b
 
b07c30e
90c437b
b07c30e
90c437b
b07c30e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a91dcdc
b07c30e
 
 
 
 
 
a91dcdc
825451d
b07c30e
0d80816
b07c30e
 
0d80816
b07c30e
 
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# Copyright (c) 2023 Amphion.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree

import subprocess

command_to_run = "cd ./modules/monotonic_align;mkdir -p monotonic_align;python setup.py build_ext --inplace;cd /home/user/app"
subprocess.check_output(command_to_run, shell=True, text=True)

import gradio as gr
import os
import inference

SUPPORTED_SPEAKERS = {
    "Cori Samuel":"hifitts_92",
    "Phil Benson":"hifitts_6097",
    "Mike Pelton":"hifitts_6670",
    "Tony Oliva":"hifitts_6671",
    "Maria Kasper":"hifitts_8051",
    "John Van Stan":"hifitts_9017",
    "Helen Taylor":"hifitts_9136",
    "Sylviamb":"hifitts_11614", 
    "Celine Major":"hifitts_11697",
    "LikeManyWaters":"hifitts_12787"
}


def tts_inference(
    input_text,
    target_speaker,
    duration
):
    ### Target Speaker ###
    target_speaker = SUPPORTED_SPEAKERS[target_speaker]
    
    args_list = ["--config", "./egs/tts/vits_hifitts/exp_config.json"]
    args_list += ["--checkpoint_path", "./expdir/checkpoint/latest-checkpoint"]
    args_list += ["--speaker_name_1", target_speaker]
    args_list += ["--speaker_name_2", None]
    args_list += ["--text", input_text]
    args_list += ["--mode","single"]
    args_list += ["--duration_control",str(float(2.05-duration))]
    args_list += ["--output_dir", "result"]
    args_list += ["--log_level", "debug"]

    os.environ["WORK_DIR"] = "./"
    inference.main(args_list)

    ### Display ###
    result_file = os.path.join(
        "result/single/test_pred.wav"
    )
    return result_file

def tc_inference(
    input_text,
    target_speaker_1,
    target_speaker_2,
    confusion_degree,
    duration
):
    ### Target Speaker ###
    target_speaker_1 = SUPPORTED_SPEAKERS[target_speaker_1]
    if target_speaker_2 is not None:
        target_speaker_2 = SUPPORTED_SPEAKERS[target_speaker_2]
    
    args_list = ["--config", "./egs/tts/vits_hifitts/exp_config.json"]
    args_list += ["--checkpoint_path", "./expdir/checkpoint/latest-checkpoint"]
    args_list += ["--speaker_name_1", target_speaker_1]
    args_list += ["--speaker_name_2", target_speaker_2]
    args_list += ["--alpha", str(float(confusion_degree))]
    args_list += ["--text", input_text]
    args_list += ["--mode","single"]
    args_list += ["--duration_control",str(float(2.05-duration))]
    args_list += ["--output_dir", "result"]
    args_list += ["--log_level", "debug"]

    os.environ["WORK_DIR"] = "./"
    inference.main(args_list)

    ### Display ###
    source_speaker_1 = os.path.join(
        "result/single/s1.wav"
    )
    source_speaker_2 = os.path.join(
        "result/single/s2.wav"
    )
    result_file = os.path.join(
        "result/single/test_pred.wav"
    )
    
    return source_speaker_1, source_speaker_2, result_file

# Section 1: TTS
tts_demo_inputs = [
    gr.Textbox(
        label="Input Text",
        type="text",
        placeholder="Type something here.."
    ),
    gr.Radio(
        choices=list(SUPPORTED_SPEAKERS.keys()),
        label="Target Speaker",
        value="Cori Samuel"
    ),
    gr.Slider(
        0.1,
        2,
        value=1,
        step=0.05,
        label="Speaking Rate",
        info="As the step number increases, the speaking rate will be faster.",
    )
]

tts_demo_output = gr.Audio(label="Generated Speech")


# Section 2: Timbre confusion
tc_demo_inputs = [
    gr.Textbox(
        label="Input Text",
        type="text",
        placeholder="Type something here.."
    ),
    gr.Radio(
        choices=list(SUPPORTED_SPEAKERS.keys()),
        label="Target Speaker 1",
        value="Cori Samuel"
    ),
    gr.Radio(
        choices=list(SUPPORTED_SPEAKERS.keys()),
        label="Target Speaker 2",
        value="Phil Benson"
    ),
    gr.Slider(
        0,
        1,
        value=0.5,
        step=0.1,
        label="Fusion Degree",
        info="As the step number increases, the generated voice will be more similar to speaker 2.",
    ),
    gr.Slider(
        0.1,
        2,
        value=1,
        step=0.05,
        label="Speaking Rate",
        info="As the step number increases, the speaking rate will be faster.",
    )
]

tc_demo_outputs = [
    gr.Audio(label="Target Speaker 1"),
    gr.Audio(label="Target Speaker 2"),
    gr.Audio(label="Interpolated Speech")
]

    

with gr.Blocks() as demo:
    gr.Interface(
        fn=tts_inference,
        inputs=tts_demo_inputs,
        outputs=tts_demo_output,
        title="Amphion Text-to-Speech",
        description="This demo offers an Amphion TTS pretrained model (VITS) for you to explore."
    )
    
    gr.Interface(
        fn=tc_inference,
        inputs=tc_demo_inputs,
        outputs=tc_demo_outputs,
        title="Voice Fusion",
        description="In this section, you can choose two speakers to create a voice mix. Adjust the ‘Fusion Degree’ slider to customize your desired mix ratio between the two speakers."
    )

    demo.queue()
    demo.launch()

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