Skip to content

Commit

Permalink
新增:GPT-SOVITS-V2 0821整合包API对接
Browse files Browse the repository at this point in the history
  • Loading branch information
Ikaros-521 committed Aug 31, 2024
1 parent 80f4385 commit a835060
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 1 deletion.
21 changes: 21 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,27 @@
"prompt_language": "中文",
"cut_punc": ",。"
},
"v2_api_0821": {
"text_lang": "zh",
"ref_audio_path": "F:\\GPT-SoVITS-0304\\output\\slicer_opt\\smoke1.wav",
"aux_ref_audio_paths": [],
"prompt_lang": "zh",
"prompt_text": "整整策划了半年了,终于现在有结果了",
"top_k": 5,
"top_p": 1,
"temperature": 1,
"text_split_method": "cut0",
"batch_size": 1,
"batch_threshold": 0.75,
"split_bucket": true,
"speed_factor": 1.0,
"fragment_interval": 0.3,
"seed": -1,
"media_type": "wav",
"streaming_mode": false,
"parallel_infer": true,
"repetition_penalty": 1.35
},
"webtts": {
"version": "1",
"api_ip_port": "http://127.0.0.1:8080",
Expand Down
21 changes: 21 additions & 0 deletions config.json.bak
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,27 @@
"prompt_language": "中文",
"cut_punc": ",。"
},
"v2_api_0821": {
"text_lang": "zh",
"ref_audio_path": "F:\\GPT-SoVITS-0304\\output\\slicer_opt\\smoke1.wav",
"aux_ref_audio_paths": [],
"prompt_lang": "zh",
"prompt_text": "整整策划了半年了,终于现在有结果了",
"top_k": 5,
"top_p": 1,
"temperature": 1,
"text_split_method": "cut0",
"batch_size": 1,
"batch_threshold": 0.75,
"split_bucket": true,
"speed_factor": 1.0,
"fragment_interval": 0.3,
"seed": -1,
"media_type": "wav",
"streaming_mode": false,
"parallel_infer": true,
"repetition_penalty": 1.35
},
"webtts": {
"version": "1",
"api_ip_port": "http://127.0.0.1:8080",
Expand Down
3 changes: 3 additions & 0 deletions utils/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,7 @@ async def tts_handle(self, message):
"cut": message["data"]["cut"],
"api_0322": message["data"]["api_0322"],
"api_0706": message["data"]["api_0706"],
"v2_api_0821": message["data"]["v2_api_0821"],
"webtts": message["data"]["webtts"],
"content": message["content"]
}
Expand Down Expand Up @@ -2005,6 +2006,7 @@ async def audio_synthesis_use_local_config(self, content, audio_synthesis_type="
else:
language = self.config.get("gpt_sovits", "language")

# 传太多有点冗余了
data = {
"type": self.config.get("gpt_sovits", "type"),
"gradio_ip_port": self.config.get("gpt_sovits", "gradio_ip_port"),
Expand All @@ -2017,6 +2019,7 @@ async def audio_synthesis_use_local_config(self, content, audio_synthesis_type="
"cut": self.config.get("gpt_sovits", "cut"),
"api_0322": self.config.get("gpt_sovits", "api_0322"),
"api_0706": self.config.get("gpt_sovits", "api_0706"),
"v2_api_0821": self.config.get("gpt_sovits", "v2_api_0821"),
"webtts": self.config.get("gpt_sovits", "webtts"),
"content": content
}
Expand Down
33 changes: 33 additions & 0 deletions utils/audio_handle/my_tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,39 @@ async def websocket_client_logic(websocket, data_json):
except Exception as e:
logger.error(traceback.format_exc())
logger.error(f'gpt_sovits未知错误: {e}')
elif data["type"] == "v2_api_0821":
try:
data_json = {
"text": data["content"],
"text_lang": data[data["type"]]["text_lang"],
"ref_audio_path": data[data["type"]]["ref_audio_path"],
"aux_ref_audio_paths": data[data["type"]]["aux_ref_audio_paths"],
"prompt_text": data[data["type"]]["prompt_text"],
"prompt_lang": data[data["type"]]["prompt_lang"],
"top_k": int(data[data["type"]]["top_k"]),
"top_p": float(data[data["type"]]["top_p"]),
"temperature": float(data[data["type"]]["temperature"]),
"text_split_method": data[data["type"]]["text_split_method"],
"batch_size": int(data[data["type"]]["batch_size"]),
"split_bucket": data[data["type"]]["split_bucket"],
"speed_factor": float(data[data["type"]]["speed_factor"]),
"fragment_interval": float(data[data["type"]]["fragment_interval"]),
"seed": int(data[data["type"]]["seed"]),
"media_type": data[data["type"]]["media_type"],
"streaming_mode": data[data["type"]]["streaming_mode"],
"parallel_infer": data[data["type"]]["parallel_infer"],
"repetition_penalty": float(data[data["type"]]["repetition_penalty"]),
}

API_URL = urljoin(data["api_ip_port"], '/tts')

return await self.download_audio("gpt_sovits", API_URL, self.timeout, "post", None, data_json)
except aiohttp.ClientError as e:
logger.error(traceback.format_exc())
logger.error(f'gpt_sovits请求失败: {e}')
except Exception as e:
logger.error(traceback.format_exc())
logger.error(f'gpt_sovits未知错误: {e}')

elif data["type"] == "webtts":
try:
Expand Down
82 changes: 81 additions & 1 deletion webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2344,6 +2344,25 @@ def common_textarea_handle(content):
config_data["gpt_sovits"]["api_0706"]["text_language"] = select_gpt_sovits_api_0706_text_language.value
config_data["gpt_sovits"]["api_0706"]["cut_punc"] = input_gpt_sovits_api_0706_cut_punc.value

config_data["gpt_sovits"]["v2_api_0821"]["ref_audio_path"] = input_gpt_sovits_v2_api_0821_ref_audio_path.value
config_data["gpt_sovits"]["v2_api_0821"]["prompt_text"] = input_gpt_sovits_v2_api_0821_prompt_text.value
config_data["gpt_sovits"]["v2_api_0821"]["prompt_lang"] = select_gpt_sovits_v2_api_0821_prompt_lang.value
config_data["gpt_sovits"]["v2_api_0821"]["text_lang"] = select_gpt_sovits_v2_api_0821_text_lang.value
config_data["gpt_sovits"]["v2_api_0821"]["text_split_method"] = select_gpt_sovits_v2_api_0821_text_split_method.value
config_data["gpt_sovits"]["v2_api_0821"]["top_k"] = int(input_gpt_sovits_v2_api_0821_top_k.value)
config_data["gpt_sovits"]["v2_api_0821"]["top_p"] = round(float(input_gpt_sovits_v2_api_0821_top_p.value), 2)
config_data["gpt_sovits"]["v2_api_0821"]["temperature"] = round(float(input_gpt_sovits_v2_api_0821_temperature.value), 2)
config_data["gpt_sovits"]["v2_api_0821"]["batch_size"] = int(input_gpt_sovits_v2_api_0821_batch_size.value)
config_data["gpt_sovits"]["v2_api_0821"]["batch_threshold"] = round(float(input_gpt_sovits_v2_api_0821_batch_threshold.value), 2)
config_data["gpt_sovits"]["v2_api_0821"]["split_bucket"] = switch_gpt_sovits_v2_api_0821_split_bucket.value
config_data["gpt_sovits"]["v2_api_0821"]["speed_factor"] = round(float(input_gpt_sovits_v2_api_0821_speed_factor.value), 2)
config_data["gpt_sovits"]["v2_api_0821"]["fragment_interval"] = round(float(input_gpt_sovits_v2_api_0821_fragment_interval.value), 2)
config_data["gpt_sovits"]["v2_api_0821"]["seed"] = int(input_gpt_sovits_v2_api_0821_seed.value)
config_data["gpt_sovits"]["v2_api_0821"]["media_type"] = input_gpt_sovits_v2_api_0821_media_type.value
config_data["gpt_sovits"]["v2_api_0821"]["parallel_infer"] = switch_gpt_sovits_v2_api_0821_parallel_infer.value
config_data["gpt_sovits"]["v2_api_0821"]["repetition_penalty"] = round(float(input_gpt_sovits_v2_api_0821_repetition_penalty.value), 2)


config_data["gpt_sovits"]["webtts"]["version"] = select_gpt_sovits_webtts_version.value
config_data["gpt_sovits"]["webtts"]["api_ip_port"] = input_gpt_sovits_webtts_api_ip_port.value
config_data["gpt_sovits"]["webtts"]["spk"] = input_gpt_sovits_webtts_spk.value
Expand Down Expand Up @@ -5073,7 +5092,15 @@ def vits_get_speaker_id():
with ui.row():
select_gpt_sovits_type = ui.select(
label='API类型',
options={'api':'api', 'api_0322':'api_0322', 'api_0706':'api_0706', 'webtts':'WebTTS', 'gradio':'gradio旧版', 'gradio_0322':'gradio_0322'},
options={
'api':'api',
'api_0322':'api_0322',
'api_0706':'api_0706',
'v2_api_0821': 'v2_api_0821',
'webtts':'WebTTS',
'gradio':'gradio旧版',
'gradio_0322':'gradio_0322',
},
value=config.get("gpt_sovits", "type")
).style("width:100px;")
input_gpt_sovits_gradio_ip_port = ui.input(
Expand Down Expand Up @@ -5197,6 +5224,59 @@ def vits_get_speaker_id():
value=config.get("gpt_sovits", "api_0706", "text_language")
).style("width:150px;")
input_gpt_sovits_api_0706_cut_punc = ui.input(label='文本切分', value=config.get("gpt_sovits", "api_0706", "cut_punc"), placeholder='文本切分符号设定, 符号范围,.;?!、,。?!;:…').style("width:200px;")

with ui.card().style(card_css):
ui.label("v2_api_0821")
with ui.row():
input_gpt_sovits_v2_api_0821_ref_audio_path = ui.input(label='参考音频路径', value=config.get("gpt_sovits", "v2_api_0821", "ref_audio_path"), placeholder='参考音频路径,建议填绝对路径').style("width:300px;")
input_gpt_sovits_v2_api_0821_prompt_text = ui.input(label='参考音频的文本', value=config.get("gpt_sovits", "v2_api_0821", "prompt_text"), placeholder='参考音频的文本').style("width:200px;")
select_gpt_sovits_v2_api_0821_prompt_lang = ui.select(
label='参考音频的语种',
options={'zh':'中文', 'ja':'日文', 'en':'英文'},
value=config.get("gpt_sovits", "v2_api_0821", "prompt_lang")
).style("width:150px;")
select_gpt_sovits_v2_api_0821_text_lang = ui.select(
label='需要合成的语种',
options={
"all_zh": "中文",
"all_yue": "粤语",
"en": "英文",
"all_ja": "日文",
"all_ko": "韩文",
"zh": "中英混合",
"yue": "粤英混合",
"ja": "日英混合",
"ko": "韩英混合",
"auto": "多语种混合", #多语种启动切分识别语种
"auto_yue": "多语种混合(粤语)",
},
value=config.get("gpt_sovits", "v2_api_0821", "text_lang")
).style("width:150px;")
select_gpt_sovits_v2_api_0821_text_split_method = ui.select(
label='语句切分',
options={
'cut0':'不切',
'cut1':'凑四句一切',
'cut2':'凑50字一切',
'cut3':'按中文句号。切',
'cut4':'按英文句号.切',
'cut5':'按标点符号切'
},
value=config.get("gpt_sovits", "v2_api_0821", "text_split_method")
).style("width:200px;")
with ui.row():
input_gpt_sovits_v2_api_0821_top_k = ui.input(label='top_k', value=config.get("gpt_sovits", "v2_api_0821", "top_k"), placeholder='top_k').style("width:100px;")
input_gpt_sovits_v2_api_0821_top_p = ui.input(label='top_p', value=config.get("gpt_sovits", "v2_api_0821", "top_p"), placeholder='top_p').style("width:100px;")
input_gpt_sovits_v2_api_0821_temperature = ui.input(label='temperature', value=config.get("gpt_sovits", "v2_api_0821", "temperature"), placeholder='temperature').style("width:100px;")
input_gpt_sovits_v2_api_0821_batch_size = ui.input(label='batch_size', value=config.get("gpt_sovits", "v2_api_0821", "batch_size"), placeholder='batch_size').style("width:100px;")
input_gpt_sovits_v2_api_0821_batch_threshold = ui.input(label='batch_threshold', value=config.get("gpt_sovits", "v2_api_0821", "batch_threshold"), placeholder='batch_threshold').style("width:100px;")
switch_gpt_sovits_v2_api_0821_split_bucket = ui.switch('split_bucket', value=config.get("gpt_sovits", "v2_api_0821", "split_bucket")).style(switch_internal_css)
input_gpt_sovits_v2_api_0821_speed_factor = ui.input(label='speed_factor', value=config.get("gpt_sovits", "v2_api_0821", "speed_factor"), placeholder='speed_factor').style("width:100px;")
input_gpt_sovits_v2_api_0821_fragment_interval = ui.input(label='分段间隔(秒)', value=config.get("gpt_sovits", "v2_api_0821", "fragment_interval"), placeholder='fragment_interval').style("width:100px;")
input_gpt_sovits_v2_api_0821_seed = ui.input(label='seed', value=config.get("gpt_sovits", "v2_api_0821", "seed"), placeholder='seed').style("width:100px;")
input_gpt_sovits_v2_api_0821_media_type = ui.input(label='media_type', value=config.get("gpt_sovits", "v2_api_0821", "media_type"), placeholder='media_type').style("width:100px;")
switch_gpt_sovits_v2_api_0821_parallel_infer = ui.switch('parallel_infer', value=config.get("gpt_sovits", "v2_api_0821", "parallel_infer")).style(switch_internal_css)
input_gpt_sovits_v2_api_0821_repetition_penalty = ui.input(label='repetition_penalty', value=config.get("gpt_sovits", "v2_api_0821", "repetition_penalty"), placeholder='repetition_penalty').style("width:100px;")


with ui.card().style(card_css):
Expand Down

0 comments on commit a835060

Please sign in to comment.