Spaces:
Running
Running
kevinwang676
commited on
Commit
·
6d066e2
1
Parent(s):
271e316
Update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,8 @@ from modelscope.models.audio.tts import SambertHifigan
|
|
9 |
from modelscope.pipelines import pipeline
|
10 |
from modelscope.utils.constant import Tasks
|
11 |
|
|
|
|
|
12 |
model_dir = os.path.abspath("./pretrain_work_dir")
|
13 |
|
14 |
custom_infer_abs = {
|
@@ -34,6 +36,36 @@ model_id = SambertHifigan(os.path.join(model_dir, "orig_model"), **kwargs)
|
|
34 |
|
35 |
inference = pipeline(task=Tasks.text_to_speech, model=model_id)
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
def infer(text):
|
38 |
output = inference(input=text)
|
39 |
filename = str(random.randint(1, 1000000000000))
|
@@ -42,6 +74,14 @@ def infer(text):
|
|
42 |
f.write(output["output_wav"])
|
43 |
return filename + "myfile.wav"
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
app = gr.Blocks()
|
46 |
|
47 |
with app:
|
@@ -54,9 +94,12 @@ with app:
|
|
54 |
with gr.Row():
|
55 |
with gr.Column():
|
56 |
inp = gr.Textbox(lines=5, label="请填写您想要转换的中文文本")
|
57 |
-
|
|
|
|
|
58 |
out = gr.Audio(label="为您生成的专属音频", type="filepath")
|
59 |
|
60 |
btn.click(fn=infer, inputs=[inp], outputs=[out])
|
61 |
-
|
|
|
62 |
app.launch(show_error=True)
|
|
|
9 |
from modelscope.pipelines import pipeline
|
10 |
from modelscope.utils.constant import Tasks
|
11 |
|
12 |
+
# model_0
|
13 |
+
|
14 |
model_dir = os.path.abspath("./pretrain_work_dir")
|
15 |
|
16 |
custom_infer_abs = {
|
|
|
36 |
|
37 |
inference = pipeline(task=Tasks.text_to_speech, model=model_id)
|
38 |
|
39 |
+
# model_1
|
40 |
+
|
41 |
+
model_dir1 = os.path.abspath("./jay/pretrain_work_dir")
|
42 |
+
|
43 |
+
custom_infer_abs1 = {
|
44 |
+
'voice_name':
|
45 |
+
'F7',
|
46 |
+
'am_ckpt':
|
47 |
+
os.path.join(model_dir1, 'tmp_am', 'ckpt'),
|
48 |
+
'am_config':
|
49 |
+
os.path.join(model_dir1, 'tmp_am', 'config.yaml'),
|
50 |
+
'voc_ckpt':
|
51 |
+
os.path.join(model_dir1, 'orig_model', 'basemodel_16k', 'hifigan', 'ckpt'),
|
52 |
+
'voc_config':
|
53 |
+
os.path.join(model_dir1, 'orig_model', 'basemodel_16k', 'hifigan',
|
54 |
+
'config.yaml'),
|
55 |
+
'audio_config':
|
56 |
+
os.path.join(model_dir1, 'data', 'audio_config.yaml'),
|
57 |
+
'se_file':
|
58 |
+
os.path.join(model_dir1, 'data', 'se', 'se.npy')
|
59 |
+
}
|
60 |
+
kwargs1 = {'custom_ckpt': custom_infer_abs1}
|
61 |
+
|
62 |
+
model_id1 = SambertHifigan(os.path.join(model_dir1, "orig_model"), **kwargs1)
|
63 |
+
|
64 |
+
inference1 = pipeline(task=Tasks.text_to_speech, model=model_id1)
|
65 |
+
|
66 |
+
|
67 |
+
# functions
|
68 |
+
|
69 |
def infer(text):
|
70 |
output = inference(input=text)
|
71 |
filename = str(random.randint(1, 1000000000000))
|
|
|
74 |
f.write(output["output_wav"])
|
75 |
return filename + "myfile.wav"
|
76 |
|
77 |
+
def infer1(text):
|
78 |
+
output = inference1(input=text)
|
79 |
+
filename = str(random.randint(1, 1000000000000))
|
80 |
+
|
81 |
+
with open(filename + "file.wav", mode='bx') as f:
|
82 |
+
f.write(output["output_wav"])
|
83 |
+
return filename + "file.wav"
|
84 |
+
|
85 |
app = gr.Blocks()
|
86 |
|
87 |
with app:
|
|
|
94 |
with gr.Row():
|
95 |
with gr.Column():
|
96 |
inp = gr.Textbox(lines=5, label="请填写您想要转换的中文文本")
|
97 |
+
with gr.Row():
|
98 |
+
btn = gr.Button("使用AI杰伦的声音")
|
99 |
+
btn1 = gr.Button("使用AI娜娜的声音")
|
100 |
out = gr.Audio(label="为您生成的专属音频", type="filepath")
|
101 |
|
102 |
btn.click(fn=infer, inputs=[inp], outputs=[out])
|
103 |
+
btn.click(fn=infer1, inputs=[inp], outputs=[out])
|
104 |
+
|
105 |
app.launch(show_error=True)
|