Mahiruoshi commited on
Commit
352a927
·
1 Parent(s): aad5650

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -7
app.py CHANGED
@@ -19,7 +19,7 @@ import warnings
19
 
20
  warnings.filterwarnings("ignore", category=UserWarning, module="gradio.blocks")
21
 
22
-
23
  import re
24
  import torch
25
  import utils
@@ -29,6 +29,9 @@ import numpy as np
29
  from tools.sentence import extrac, is_japanese, is_chinese
30
  import sys, os
31
  import math
 
 
 
32
  net_g = None
33
 
34
  cara_list = ["ひまり","たえ","彩","日菜","美咲","ましろ","燐子","香子","珠緒","たえ"]
@@ -53,7 +56,6 @@ if sys.platform == "darwin" and torch.backends.mps.is_available():
53
  device = "mps"
54
  os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1"
55
  else:
56
- #device = "cuda"
57
  device = "cpu"
58
 
59
  def generate_audio(
@@ -73,7 +75,8 @@ def generate_audio(
73
  language = "JP"
74
  elif is_chinese(text):
75
  language = "ZH"
76
- print(text+":"+language)
 
77
  audio = infer(
78
  text,
79
  sdp_ratio=sdp_ratio,
@@ -152,9 +155,19 @@ if __name__ == "__main__":
152
  for filename in filenames:
153
  modelPaths.append(os.path.join(dirpath, filename))
154
  with gr.Blocks() as app:
155
- gr.Markdown(
156
- f"少歌邦邦全员TTS,使用本模型请严格遵守法律法规!\现已支持日语bert推理<a href='https://huggingface.co/spaces/Mahiruoshi/MyGO_VIts-bert/'>上一版本模型</a>及V1.0版本模型\n 发布二创作品请注明项目和本模型作者<a href='https://space.bilibili.com/19874615/'>B站@Mahiroshi</a>及项目链接\n从 <a href='https://nijigaku.top/2023/10/03/BangDreamTTS/'>我的博客站点</a> 查看使用说明</a>"
157
- )
 
 
 
 
 
 
 
 
 
 
158
  for band in BandList:
159
  with gr.TabItem(band):
160
  for name in BandList[band]:
@@ -170,6 +183,7 @@ if __name__ == "__main__":
170
  length_scale = gr.Slider(
171
  minimum=0.1, maximum=2, value=1, step=0.01, label="语速调节"
172
  )
 
173
  with gr.Accordion(label="切换模型", open=False):
174
  modelstrs = gr.Dropdown(label = "模型", choices = modelPaths, value = modelPaths[0], type = "value")
175
  btnMod = gr.Button("载入模型")
@@ -183,6 +197,9 @@ if __name__ == "__main__":
183
  )
184
  btn = gr.Button("点击生成", variant="primary")
185
  audio_output = gr.Audio(label="Output Audio")
 
 
 
186
  with gr.Accordion(label="其它参数设定", open=False):
187
  sdp_ratio = gr.Slider(
188
  minimum=0, maximum=1, value=0.2, step=0.01, label="SDP/DP混合比"
@@ -193,7 +210,6 @@ if __name__ == "__main__":
193
  noise_scale_w = gr.Slider(
194
  minimum=0.1, maximum=2, value=0.8, step=0.01, label="音素长度"
195
  )
196
- LongSentence = gr.Checkbox(value=True, label="Generate LongSentence")
197
  language = gr.Dropdown(
198
  choices=languages, value=languages[0], label="选择语言(默认自动)"
199
  )
 
19
 
20
  warnings.filterwarnings("ignore", category=UserWarning, module="gradio.blocks")
21
 
22
+ from datetime import datetime
23
  import re
24
  import torch
25
  import utils
 
29
  from tools.sentence import extrac, is_japanese, is_chinese
30
  import sys, os
31
  import math
32
+
33
+ from tools.translate import translate
34
+
35
  net_g = None
36
 
37
  cara_list = ["ひまり","たえ","彩","日菜","美咲","ましろ","燐子","香子","珠緒","たえ"]
 
56
  device = "mps"
57
  os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1"
58
  else:
 
59
  device = "cpu"
60
 
61
  def generate_audio(
 
75
  language = "JP"
76
  elif is_chinese(text):
77
  language = "ZH"
78
+ current_time = datetime.now()
79
+ print(str(current_time)+':'+str(speaker)+ text+":"+language)
80
  audio = infer(
81
  text,
82
  sdp_ratio=sdp_ratio,
 
155
  for filename in filenames:
156
  modelPaths.append(os.path.join(dirpath, filename))
157
  with gr.Blocks() as app:
158
+ gr.Markdown(value="""
159
+ 少歌邦邦全员在线语音合成(Bert-Vits2)\n
160
+ 作者:B站@Mahiroshi https://space.bilibili.com/19874615\n
161
+ 声音归属:BangDream及少歌手游\n
162
+ Bert-VITS2项目:https://github.com/Stardust-minus/Bert-VITS2\n
163
+ 使用参考: https://nijigaku.top/2023/10/03/BangDreamTTS\n
164
+ 数据集制作: https://huggingface.co/spaces/Mahiruoshi/BangDream-Bert-VITS2/tree/main/%E7%88%AC%E8%99%AB
165
+ 服务器启动示例: https://huggingface.co/spaces/Mahiruoshi/BangDream-Bert-VITS2/blob/main/server.py\n
166
+ 使用本模型请严格遵守法律法规!禁止生成任何有损声优或者企划的内容!!!!!\n
167
+ このモデルを使用する際は法律法規を厳守してください!声優や企画に損害を与える内容の生成は禁止です!!!!!\n
168
+ Please strictly follow the laws in your country and regulations when using this model! It is prohibited to generate any content that is harmful to others!!!!!\n
169
+ 发布二创作品请标注本项目作者及链接、作品使用Bert-VITS2 AI生成!\n
170
+ """)
171
  for band in BandList:
172
  with gr.TabItem(band):
173
  for name in BandList[band]:
 
183
  length_scale = gr.Slider(
184
  minimum=0.1, maximum=2, value=1, step=0.01, label="语速调节"
185
  )
186
+ LongSentence = gr.Checkbox(value=True, label="自动拆分句子")
187
  with gr.Accordion(label="切换模型", open=False):
188
  modelstrs = gr.Dropdown(label = "模型", choices = modelPaths, value = modelPaths[0], type = "value")
189
  btnMod = gr.Button("载入模型")
 
197
  )
198
  btn = gr.Button("点击生成", variant="primary")
199
  audio_output = gr.Audio(label="Output Audio")
200
+ btntran = gr.Button("快速中翻日")
201
+ translateResult = gr.TextArea("从这复制翻译后的文本")
202
+ btntran.click(translate, inputs=[text], outputs = [translateResult])
203
  with gr.Accordion(label="其它参数设定", open=False):
204
  sdp_ratio = gr.Slider(
205
  minimum=0, maximum=1, value=0.2, step=0.01, label="SDP/DP混合比"
 
210
  noise_scale_w = gr.Slider(
211
  minimum=0.1, maximum=2, value=0.8, step=0.01, label="音素长度"
212
  )
 
213
  language = gr.Dropdown(
214
  choices=languages, value=languages[0], label="选择语言(默认自动)"
215
  )