Skip to content

Commit

Permalink
bert_vits2 新增 刘悦-中文特化API 的对接
Browse files Browse the repository at this point in the history
  • Loading branch information
Ikaros-521 committed Jun 14, 2024
1 parent 46b7e8e commit 71e7bfc
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 107 deletions.
22 changes: 19 additions & 3 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,23 @@
"auto_split": false,
"emotion": "",
"style_text": "",
"style_weight": 0.7
"style_weight": 0.7,
"刘悦-中文特化API": {
"api_ip_port": "http://127.0.0.1:9885",
"speaker": "Yennefer",
"language": "ZH",
"length_scale": "0.9-1.1",
"noise_scale": "0.2-0.3",
"noise_scale_w": "0.85-0.95",
"sdp_radio": "0.2-0.3",
"cut_by_sent": true,
"interval_between_para": "1",
"interval_between_sent": "0.2",
"emotion": "Happy",
"style_text": "",
"style_weight": "0.7-0.8",
"stream": false
}
},
"vits_fast": {
"config_path": "D:\\GitHub_pro\\VITS-fast-fine-tuning\\inference\\finetune_speaker.json",
Expand Down Expand Up @@ -1782,10 +1798,10 @@
"visual_body": {
"live2d": true,
"xuniren": true,
"metahuman": true,
"musetalk": true,
"unity": true,
"EasyAIVtuber": true,
"metahuman": true,
"musetalk": true,
"digital_human_video_player": true
}
}
Expand Down
18 changes: 17 additions & 1 deletion config.json.bak
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,23 @@
"auto_split": false,
"emotion": "",
"style_text": "",
"style_weight": 0.7
"style_weight": 0.7,
"刘悦-中文特化API": {
"api_ip_port": "http://127.0.0.1:9885",
"speaker": "Yennefer",
"language": "ZH",
"length_scale": "0.9-1.1",
"noise_scale": "0.2-0.3",
"noise_scale_w": "0.85-0.95",
"sdp_radio": "0.2-0.3",
"cut_by_sent": true,
"interval_between_para": "1",
"interval_between_sent": "0.2",
"emotion": "Happy",
"style_text": "",
"style_weight": "0.7-0.8",
"stream": false
}
},
"vits_fast": {
"config_path": "D:\\GitHub_pro\\VITS-fast-fine-tuning\\inference\\finetune_speaker.json",
Expand Down
131 changes: 66 additions & 65 deletions utils/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,46 +844,46 @@ async def tts_handle(self, message):
voice_tmp_path = await self.my_tts.vits_api(data)

elif message["tts_type"] == "bert_vits2":
if message["data"]["type"] == "hiyori":
if message["data"]["language"] == "auto":
# 自动检测语言
language = self.common.lang_check(message["content"])
if message["data"]["language"] == "auto":
# 自动检测语言
language = self.common.lang_check(message["content"])

logging.debug(f'language={language}')
logging.debug(f'language={language}')

# 自定义语言名称(需要匹配请求解析)
language_name_dict = {"en": "EN", "zh": "ZH", "ja": "JP"}
# 自定义语言名称(需要匹配请求解析)
language_name_dict = {"en": "EN", "zh": "ZH", "ja": "JP"}

if language in language_name_dict:
language = language_name_dict[language]
else:
language = "ZH" # 无法识别出语言代码时的默认值
if language in language_name_dict:
language = language_name_dict[language]
else:
language = message["data"]["language"]
language = "ZH" # 无法识别出语言代码时的默认值
else:
language = message["data"]["language"]

data = {
"api_ip_port": message["data"]["api_ip_port"],
"type": message["data"]["type"],
"model_id": message["data"]["model_id"],
"speaker_name": message["data"]["speaker_name"],
"speaker_id": message["data"]["speaker_id"],
"language": language,
"length": message["data"]["length"],
"noise": message["data"]["noise"],
"noisew": message["data"]["noisew"],
"sdp_radio": message["data"]["sdp_radio"],
"auto_translate": message["data"]["auto_translate"],
"auto_split": message["data"]["auto_split"],
"emotion": message["data"]["emotion"],
"style_text": message["data"]["style_text"],
"style_weight": message["data"]["style_weight"],
"content": message["content"]
}
data = {
"api_ip_port": message["data"]["api_ip_port"],
"type": message["data"]["type"],
"model_id": message["data"]["model_id"],
"speaker_name": message["data"]["speaker_name"],
"speaker_id": message["data"]["speaker_id"],
"language": language,
"length": message["data"]["length"],
"noise": message["data"]["noise"],
"noisew": message["data"]["noisew"],
"sdp_radio": message["data"]["sdp_radio"],
"auto_translate": message["data"]["auto_translate"],
"auto_split": message["data"]["auto_split"],
"emotion": message["data"]["emotion"],
"style_text": message["data"]["style_text"],
"style_weight": message["data"]["style_weight"],
"刘悦-中文特化API": message["data"]["刘悦-中文特化API"],
"content": message["content"]
}



# 调用接口合成语音
voice_tmp_path = await self.my_tts.bert_vits2_api(data)

elif message["tts_type"] == "vits_fast":
if message["data"]["language"] == "自动识别":
# 自动检测语言
Expand Down Expand Up @@ -1768,46 +1768,47 @@ async def audio_synthesis_use_local_config(self, content, audio_synthesis_type="


elif audio_synthesis_type == "bert_vits2":
if self.config.get("bert_vits2", "type") == "hiyori":
if self.config.get("bert_vits2", "language") == "auto":
# 自动检测语言
language = self.common.lang_check(content)

if self.config.get("bert_vits2", "language") == "auto":
# 自动检测语言
language = self.common.lang_check(content)

logging.debug(f'language={language}')
logging.debug(f'language={language}')

# 自定义语言名称(需要匹配请求解析)
language_name_dict = {"en": "EN", "zh": "ZH", "ja": "JP"}
# 自定义语言名称(需要匹配请求解析)
language_name_dict = {"en": "EN", "zh": "ZH", "ja": "JP"}

if language in language_name_dict:
language = language_name_dict[language]
else:
language = "ZH" # 无法识别出语言代码时的默认值
if language in language_name_dict:
language = language_name_dict[language]
else:
language = self.config.get("bert_vits2", "language")

data = {
"api_ip_port": self.config.get("bert_vits2", "api_ip_port"),
"type": self.config.get("bert_vits2", "type"),
"model_id": self.config.get("bert_vits2", "model_id"),
"speaker_name": self.config.get("bert_vits2", "speaker_name"),
"speaker_id": self.config.get("bert_vits2", "speaker_id"),
"language": language,
"length": self.config.get("bert_vits2", "length"),
"noise": self.config.get("bert_vits2", "noise"),
"noisew": self.config.get("bert_vits2", "noisew"),
"sdp_radio": self.config.get("bert_vits2", "sdp_radio"),
"auto_translate": self.config.get("bert_vits2", "auto_translate"),
"auto_split": self.config.get("bert_vits2", "auto_split"),
"emotion": self.config.get("bert_vits2", "emotion"),
"style_text": self.config.get("bert_vits2", "style_text"),
"style_weight": self.config.get("bert_vits2", "style_weight"),
"content": content
}
language = "ZH" # 无法识别出语言代码时的默认值
else:
language = self.config.get("bert_vits2", "language")

data = {
"api_ip_port": self.config.get("bert_vits2", "api_ip_port"),
"type": self.config.get("bert_vits2", "type"),
"model_id": self.config.get("bert_vits2", "model_id"),
"speaker_name": self.config.get("bert_vits2", "speaker_name"),
"speaker_id": self.config.get("bert_vits2", "speaker_id"),
"language": language,
"length": self.config.get("bert_vits2", "length"),
"noise": self.config.get("bert_vits2", "noise"),
"noisew": self.config.get("bert_vits2", "noisew"),
"sdp_radio": self.config.get("bert_vits2", "sdp_radio"),
"auto_translate": self.config.get("bert_vits2", "auto_translate"),
"auto_split": self.config.get("bert_vits2", "auto_split"),
"emotion": self.config.get("bert_vits2", "emotion"),
"style_text": self.config.get("bert_vits2", "style_text"),
"style_weight": self.config.get("bert_vits2", "style_weight"),
"刘悦-中文特化API": self.config.get("bert_vits2", "刘悦-中文特化API"),
"content": content
}

logging.info(f"data={data}")
logging.info(f"data={data}")

# 调用接口合成语音
voice_tmp_path = await self.my_tts.bert_vits2_api(data)
# 调用接口合成语音
voice_tmp_path = await self.my_tts.bert_vits2_api(data)
elif audio_synthesis_type == "vits_fast":
if vits_fast["language"] == "自动识别":
# 自动检测语言
Expand Down
38 changes: 33 additions & 5 deletions utils/audio_handle/my_tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,42 @@ async def bert_vits2_api(self, data):
"style_weight": self.get_random_float(data["style_weight"])
}

logging.debug(f"data_json={data_json}")
# logging.info(f"data={data}")
logging.debug(f"data_json={data_json}")
# logging.info(f"data={data}")

logging.debug(f"API_URL={API_URL}")
logging.debug(f"API_URL={API_URL}")

url = f"{API_URL}?{urlencode(data_json)}"
url = f"{API_URL}?{urlencode(data_json)}"

return await self.download_audio("bert_vits2", url, self.timeout)
elif data["type"] == "刘悦-中文特化API":
type = data["type"]
# API地址 "http://127.0.0.1:5000/run/predict/"
API_URL = urljoin(data[type]["api_ip_port"], '/tts_to_audio/')

data_json = {
"text": data["content"],
"speaker": data[type]["speaker"],
"language": data["language"],
"length_scale": self.get_random_float(data[type]["length_scale"]),
"noise_scale": self.get_random_float(data[type]["noise_scale"]),
"noise_scale_w": self.get_random_float(data[type]["noise_scale_w"]),
"sdp_radio": self.get_random_float(data[type]["sdp_radio"]),
"cut_by_sent": data[type]["cut_by_sent"],
"interval_between_para": self.get_random_float(data[type]["interval_between_para"]),
"interval_between_sent": self.get_random_float(data[type]["interval_between_sent"]),
"emotion": data[type]["emotion"],
"style_text": data[type]["style_text"],
"style_weight": self.get_random_float(data[type]["style_weight"]),
"stream": data[type]["stream"]
}

logging.debug(f"data_json={data_json}")
# logging.info(f"data={data}")

logging.debug(f"API_URL={API_URL}")

return await self.download_audio("bert_vits2", url, self.timeout)
return await self.download_audio("bert_vits2", API_URL, self.timeout, "post", json_data=data_json)
except aiohttp.ClientError as e:
logging.error(traceback.format_exc())
logging.error(f'bert_vits2请求失败,请检查您的bert_vits2 api是否启动/配置是否正确,报错内容: {e}')
Expand Down
Loading

0 comments on commit 71e7bfc

Please sign in to comment.