DeepLearning101 commited on
Commit
89c506f
1 Parent(s): 430d145

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -0
app.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ @author:XuMing(xuming624@qq.com)
4
+ @description: Re-train by TWMAN
5
+ """
6
+ import hashlib
7
+ import os
8
+ import ssl
9
+
10
+ import gradio as gr
11
+ import torch
12
+ from loguru import logger
13
+
14
+ ssl._create_default_https_context = ssl._create_unverified_context
15
+ import nltk
16
+
17
+ nltk.download('cmudict')
18
+ from parrots import TextToSpeech
19
+
20
+ device = "cuda" if torch.cuda.is_available() else "cpu"
21
+ logger.info(f"device: {device}")
22
+ half = True if device == "cuda" else False
23
+
24
+ m = TextToSpeech(speaker_model_path="DeepLearning101/GPT-SoVITS_TWMAN", speaker_name="TWMAN", device=device, half=half)
25
+ m.predict(text="台灣南波萬。Taiwan Number One.", text_language="auto", output_path="output_audio.wav")
26
+ assert os.path.exists("output_audio.wav"), "output_audio.wav not found"
27
+
28
+
29
+ def get_text_hash(text: str):
30
+ return hashlib.md5(text.encode('utf-8')).hexdigest()
31
+
32
+
33
+ def do_tts_wav_predict(text: str, output_path: str = None):
34
+ if output_path is None:
35
+ output_path = f"output_audio_{get_text_hash(text)}.wav"
36
+ if not os.path.exists(output_path):
37
+ m.predict(text, text_language="auto", output_path=output_path)
38
+ return output_path
39
+
40
+
41
+ with gr.Blocks(title="TTS WebUI") as app:
42
+ gr.Markdown(value="""
43
+ # <center>線上語音合成;speaker:TWMAN\n
44
+
45
+ ### <center>語音處理:https://www.twman.org/AI/ASR\n
46
+ ### <center>那些語音處理 (Speech Processing) 踩的坑 https://blog.twman.org/2021/04/ASR.html\n
47
+ ### <center>parrots專案:https://github.com/shibing624/parrots\n
48
+ ### <center>使用模型:https://github.com/RVC-Boss/GPT-SoVITS\n
49
+ ### <center>使用本模型請嚴格遵守法規! 發布二創作品請標註本專案作者及連結、作品使用GPT-SoVITS AI生成! \n
50
+ ### <center>⚠️在線端不穩定且生成速度較慢,建議使用parrots本地推理! \n
51
+ """)
52
+
53
+ with gr.Group():
54
+ gr.Markdown(value="*請在這裡輸入要進行語音合成的文字")
55
+ with gr.Row():
56
+ text = gr.Textbox(label="想語音合成的文字(100字以内)或使用預設", value="床前明月光,疑是地上霜。舉頭望明月,低頭思故鄉。", placeholder="請輸入您想要的文字", lines=3)
57
+ inference_button = gr.Button("語音合成", variant="primary")
58
+ output = gr.Audio(label="合成的語音")
59
+ inference_button.click(
60
+ do_tts_wav_predict,
61
+ [text],
62
+ [output],
63
+ )
64
+
65
+ app.queue(max_size=10)
66
+ app.launch(inbrowser=True)