Spaces:
Running
Running
Mahiruoshi
commited on
Commit
•
c864f13
1
Parent(s):
0376c2e
Update app.py
Browse files
app.py
CHANGED
@@ -32,6 +32,7 @@ import gradio as gr
|
|
32 |
import webbrowser
|
33 |
import re
|
34 |
from scipy.io.wavfile import write
|
|
|
35 |
net_g = None
|
36 |
BandList = {
|
37 |
|
@@ -150,6 +151,8 @@ def infer(text, sdp_ratio, noise_scale, noise_scale_w, length_scale, sid, langua
|
|
150 |
.float()
|
151 |
.numpy()
|
152 |
)
|
|
|
|
|
153 |
del x_tst, tones, lang_ids, bert, x_tst_lengths, speakers
|
154 |
return audio
|
155 |
|
@@ -314,7 +317,7 @@ def extract_text_from_file(inputFile):
|
|
314 |
elif file_extension == ".asset":
|
315 |
with open(inputFile, 'r', encoding='utf-8') as f:
|
316 |
content = json.load(f)
|
317 |
-
return extract_text_from_game2(content) if
|
318 |
else:
|
319 |
raise ValueError(f"Unsupported file format: {file_extension}")
|
320 |
|
@@ -338,15 +341,21 @@ def audiobook(inputFile, groupsize, speaker, sdp_ratio, noise_scale, noise_scale
|
|
338 |
return result
|
339 |
return result
|
340 |
|
|
|
|
|
|
|
|
|
|
|
|
|
341 |
if __name__ == "__main__":
|
342 |
parser = argparse.ArgumentParser()
|
343 |
parser.add_argument(
|
344 |
-
"-m", "--model", default="./logs/Bangdream/
|
345 |
)
|
346 |
parser.add_argument(
|
347 |
"-c",
|
348 |
"--config",
|
349 |
-
default="
|
350 |
help="path of your config file",
|
351 |
)
|
352 |
parser.add_argument(
|
@@ -360,8 +369,6 @@ if __name__ == "__main__":
|
|
360 |
if args.debug:
|
361 |
logger.info("Enable DEBUG-LEVEL log")
|
362 |
logging.basicConfig(level=logging.DEBUG)
|
363 |
-
hps = utils.get_hparams_from_file(args.config)
|
364 |
-
|
365 |
device = (
|
366 |
"cuda:0"
|
367 |
if torch.cuda.is_available()
|
@@ -371,6 +378,7 @@ if __name__ == "__main__":
|
|
371 |
else "cpu"
|
372 |
)
|
373 |
)
|
|
|
374 |
net_g = SynthesizerTrn(
|
375 |
len(symbols),
|
376 |
hps.data.filter_length // 2 + 1,
|
@@ -378,16 +386,17 @@ if __name__ == "__main__":
|
|
378 |
n_speakers=hps.data.n_speakers,
|
379 |
**hps.model,
|
380 |
).to(device)
|
381 |
-
|
382 |
-
|
383 |
-
_ = utils.load_checkpoint(args.model, net_g, None, skip_optimizer=True)
|
384 |
-
|
385 |
speaker_ids = hps.data.spk2id
|
386 |
speakers = list(speaker_ids.keys())
|
387 |
languages = ["ZH", "JP"]
|
388 |
examples = [
|
389 |
["filelist/Scenarioband6-018.asset", 500, "つくし", "ましろ|真白\n七深|七深\n透子|透子\nつくし|筑紫\n瑠唯|瑠唯\nそよ|素世\n祥子|祥子", "扩展功能"],
|
390 |
]
|
|
|
|
|
|
|
|
|
391 |
with gr.Blocks() as app:
|
392 |
gr.Markdown(
|
393 |
f"少歌邦邦全员TTS,使用本模型请严格遵守法律法规!\n 发布二创作品请注明项目和本模型作者<a href='https://space.bilibili.com/19874615/'>B站@Mahiroshi</a>及项目链接\n从 <a href='https://nijigaku.top/2023/10/03/BangDreamTTS/'>我的博客站点</a> 查看使用说明</a>"
|
@@ -407,6 +416,11 @@ if __name__ == "__main__":
|
|
407 |
length_scale = gr.Slider(
|
408 |
minimum=0.1, maximum=2, value=1, step=0.01, label="语速调节"
|
409 |
)
|
|
|
|
|
|
|
|
|
|
|
410 |
with gr.Column():
|
411 |
text = gr.TextArea(
|
412 |
label="输入纯日语或者中文",
|
|
|
32 |
import webbrowser
|
33 |
import re
|
34 |
from scipy.io.wavfile import write
|
35 |
+
from datetime import datetime
|
36 |
net_g = None
|
37 |
BandList = {
|
38 |
|
|
|
151 |
.float()
|
152 |
.numpy()
|
153 |
)
|
154 |
+
current_time = datetime.now()
|
155 |
+
print(str(current_time)+':'+str(sid))
|
156 |
del x_tst, tones, lang_ids, bert, x_tst_lengths, speakers
|
157 |
return audio
|
158 |
|
|
|
317 |
elif file_extension == ".asset":
|
318 |
with open(inputFile, 'r', encoding='utf-8') as f:
|
319 |
content = json.load(f)
|
320 |
+
return extract_text_from_game2(content) if extract_text_from_game2(content) != '' else extract_text_from_game2(content)
|
321 |
else:
|
322 |
raise ValueError(f"Unsupported file format: {file_extension}")
|
323 |
|
|
|
341 |
return result
|
342 |
return result
|
343 |
|
344 |
+
def loadmodel(model):
|
345 |
+
_ = net_g.eval()
|
346 |
+
_ = utils.load_checkpoint(model, net_g, None, skip_optimizer=True)
|
347 |
+
return "success"
|
348 |
+
|
349 |
+
|
350 |
if __name__ == "__main__":
|
351 |
parser = argparse.ArgumentParser()
|
352 |
parser.add_argument(
|
353 |
+
"-m", "--model", default="./logs/Bangdream/G_10000.pth", help="path of your model"
|
354 |
)
|
355 |
parser.add_argument(
|
356 |
"-c",
|
357 |
"--config",
|
358 |
+
default="configs/config.json",
|
359 |
help="path of your config file",
|
360 |
)
|
361 |
parser.add_argument(
|
|
|
369 |
if args.debug:
|
370 |
logger.info("Enable DEBUG-LEVEL log")
|
371 |
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
|
372 |
device = (
|
373 |
"cuda:0"
|
374 |
if torch.cuda.is_available()
|
|
|
378 |
else "cpu"
|
379 |
)
|
380 |
)
|
381 |
+
hps = utils.get_hparams_from_file(args.config)
|
382 |
net_g = SynthesizerTrn(
|
383 |
len(symbols),
|
384 |
hps.data.filter_length // 2 + 1,
|
|
|
386 |
n_speakers=hps.data.n_speakers,
|
387 |
**hps.model,
|
388 |
).to(device)
|
389 |
+
loadmodel(args.model)
|
|
|
|
|
|
|
390 |
speaker_ids = hps.data.spk2id
|
391 |
speakers = list(speaker_ids.keys())
|
392 |
languages = ["ZH", "JP"]
|
393 |
examples = [
|
394 |
["filelist/Scenarioband6-018.asset", 500, "つくし", "ましろ|真白\n七深|七深\n透子|透子\nつくし|筑紫\n瑠唯|瑠唯\nそよ|素世\n祥子|祥子", "扩展功能"],
|
395 |
]
|
396 |
+
modelPaths = []
|
397 |
+
for dirpath, dirnames, filenames in os.walk("./logs/Bangdream/"):
|
398 |
+
for filename in filenames:
|
399 |
+
modelPaths.append(os.path.join(dirpath, filename))
|
400 |
with gr.Blocks() as app:
|
401 |
gr.Markdown(
|
402 |
f"少歌邦邦全员TTS,使用本模型请严格遵守法律法规!\n 发布二创作品请注明项目和本模型作者<a href='https://space.bilibili.com/19874615/'>B站@Mahiroshi</a>及项目链接\n从 <a href='https://nijigaku.top/2023/10/03/BangDreamTTS/'>我的博客站点</a> 查看使用说明</a>"
|
|
|
416 |
length_scale = gr.Slider(
|
417 |
minimum=0.1, maximum=2, value=1, step=0.01, label="语速调节"
|
418 |
)
|
419 |
+
with gr.Accordion(label="切换模型(合成中文建议切换为早期模型)", open=False):
|
420 |
+
modelstrs = gr.Dropdown(label = "模型", choices = modelPaths, value = modelPaths[0], type = "value")
|
421 |
+
btnMod = gr.Button("载入模型")
|
422 |
+
statusa = gr.TextArea()
|
423 |
+
btnMod.click(loadmodel, inputs=[modelstrs], outputs = [statusa])
|
424 |
with gr.Column():
|
425 |
text = gr.TextArea(
|
426 |
label="输入纯日语或者中文",
|