CrawfordZhou commited on
Commit
2b7b812
1 Parent(s): c23d5e4

Update app.py

Browse files

添加情景语言模式+一些样式调整

Files changed (1) hide show
  1. app.py +17 -15
app.py CHANGED
@@ -63,10 +63,9 @@ def get_text(text, language_str, hps):
63
 
64
  return bert, phone, tone, language
65
 
66
- def infer(text, key, sdp_ratio, noise_scale, noise_scale_w, length_scale, sid):
67
  global net_g
68
- message = gpt_35_api(key, text)
69
- print(message)
70
  bert, phones, tones, lang_ids = get_text(message, "ZH", hps)
71
  with torch.no_grad():
72
  x_tst=phones.to(device).unsqueeze(0)
@@ -81,10 +80,11 @@ def infer(text, key, sdp_ratio, noise_scale, noise_scale_w, length_scale, sid):
81
  del x_tst, tones, lang_ids, bert, x_tst_lengths, speakers
82
  return audio
83
 
84
- def tts_fn(text, key, speaker, sdp_ratio, noise_scale, noise_scale_w, length_scale):
 
85
  with torch.no_grad():
86
- audio = infer(text, key, sdp_ratio=sdp_ratio, noise_scale=noise_scale, noise_scale_w=noise_scale_w, length_scale=length_scale, sid=speaker)
87
- return "Success", (hps.data.sampling_rate, audio)
88
 
89
 
90
  if __name__ == "__main__":
@@ -127,11 +127,10 @@ if __name__ == "__main__":
127
  with gr.Row():
128
  with gr.Column():
129
  gr.Markdown(value="""
130
- AI嘉然】在线语音对话版(Bert-Vits2 + gpt)\n
131
- (注:转发生成可能较慢,请等待大约2分钟哦!)\n
132
- 音声作者:Xz乔希 https://space.bilibili.com/5859321\n
133
- 集成gpt作者:碎语碎念 https://space.bilibili.com/4269384\n
134
- 声音归属:嘉然今天吃什么 https://space.bilibili.com/672328094\n
135
  Bert-VITS2项目:https://github.com/Stardust-minus/Bert-VITS2\n
136
  GPT_API_free项目:https://github.com/chatanywhere/GPT_API_free\n
137
  本项目中的apiKey可以从https://github.com/chatanywhere/GPT_API_free\n
@@ -141,7 +140,9 @@ if __name__ == "__main__":
141
  """)
142
  text = gr.TextArea(label="Text", placeholder="Input Text Here",
143
  value="虚拟主播是什么?")
144
- key = gr.TextArea(label="GPT Key", placeholder="请输入上面提示中获取的gpt key",
 
 
145
  value="izlrijShDu7tp2rIgvYfibcC2J0Eh3uWfdm9ndrxN5nWrL96")
146
  speaker = gr.Dropdown(choices=speakers, value=speakers[0], label='Speaker')
147
  sdp_ratio = gr.Slider(minimum=0.1, maximum=1, value=0.2, step=0.01, label='SDP/DP混合比')
@@ -151,10 +152,11 @@ if __name__ == "__main__":
151
  btn = gr.Button("点击生成", variant="primary")
152
  with gr.Column():
153
  text_output = gr.Textbox(label="Message")
154
- audio_output = gr.Audio(label="Output Audio")
 
155
  btn.click(tts_fn,
156
- inputs=[text, key, speaker, sdp_ratio, noise_scale, noise_scale_w, length_scale],
157
- outputs=[text_output, audio_output])
158
 
159
  # webbrowser.open("http://127.0.0.1:6006")
160
  # app.launch(server_port=6006, show_error=True)
 
63
 
64
  return bert, phone, tone, language
65
 
66
+ def infer(text, sdp_ratio, noise_scale, noise_scale_w, length_scale, sid):
67
  global net_g
68
+ print(text)
 
69
  bert, phones, tones, lang_ids = get_text(message, "ZH", hps)
70
  with torch.no_grad():
71
  x_tst=phones.to(device).unsqueeze(0)
 
80
  del x_tst, tones, lang_ids, bert, x_tst_lengths, speakers
81
  return audio
82
 
83
+ def tts_fn(text, font, key, speaker, sdp_ratio, noise_scale, noise_scale_w, length_scale):
84
+ message = gpt_35_api(key, font + text)
85
  with torch.no_grad():
86
+ audio = infer(message, sdp_ratio=sdp_ratio, noise_scale=noise_scale, noise_scale_w=noise_scale_w, length_scale=length_scale, sid=speaker)
87
+ return "Success", (hps.data.sampling_rate, message, audio)
88
 
89
 
90
  if __name__ == "__main__":
 
127
  with gr.Row():
128
  with gr.Column():
129
  gr.Markdown(value="""
130
+ #【AI嘉然】在线语音对话版(Bert-Vits2 + gpt)\n
131
+ ![avatar](https://img2.baidu.com/it/u=624370534,740039074&fm=253&fmt=auto&app=138&f=JPEG?w=200&h=300) \n
132
+ (注:转发生成可能较慢,请等待大约2分钟哦,目前只支持中文语言的答案,其他语言的支持在开发中捏!)\n
133
+ 作者:[Xz乔希](https://space.bilibili.com/5859321) & [碎语碎念](https://space.bilibili.com/4269384) 声音归属:[嘉然今天吃什么](https://space.bilibili.com/672328094) \n
 
134
  Bert-VITS2项目:https://github.com/Stardust-minus/Bert-VITS2\n
135
  GPT_API_free项目:https://github.com/chatanywhere/GPT_API_free\n
136
  本项目中的apiKey可以从https://github.com/chatanywhere/GPT_API_free\n
 
140
  """)
141
  text = gr.TextArea(label="Text", placeholder="Input Text Here",
142
  value="虚拟主播是什么?")
143
+ front_text = gr.TextArea(label="请输入情景语言", placeholder="请输入情景语言",
144
+ value="你是一个叫嘉然的虚拟主播,")
145
+ key = gr.Text(label="GPT Key(过期请更换)", placeholder="请输入上面提示中获取的gpt key",
146
  value="izlrijShDu7tp2rIgvYfibcC2J0Eh3uWfdm9ndrxN5nWrL96")
147
  speaker = gr.Dropdown(choices=speakers, value=speakers[0], label='Speaker')
148
  sdp_ratio = gr.Slider(minimum=0.1, maximum=1, value=0.2, step=0.01, label='SDP/DP混合比')
 
152
  btn = gr.Button("点击生成", variant="primary")
153
  with gr.Column():
154
  text_output = gr.Textbox(label="Message")
155
+ gpt_output = gr.TextArea(label="嘉然老师的文字回答")
156
+ audio_output = gr.Audio(label="嘉然老师的语音回答")
157
  btn.click(tts_fn,
158
+ inputs=[text, front_text, key, speaker, sdp_ratio, noise_scale, noise_scale_w, length_scale],
159
+ outputs=[text_output, gpt_output, audio_output])
160
 
161
  # webbrowser.open("http://127.0.0.1:6006")
162
  # app.launch(server_port=6006, show_error=True)