Skip to content

Commit

Permalink
VITS下,兼容bert-vits2
Browse files Browse the repository at this point in the history
  • Loading branch information
Ikaros-521 committed Sep 7, 2023
1 parent d02bf5e commit 00be6f6
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 38 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1272,13 +1272,16 @@ cmd运行`npm i docsify-cli -g`
- [ ] Edge-TTS在合成音频时会出现合成成功但是系统找不到文件的bug
- [x] 抖音关注事件可以触发关注感谢话术
- [x] 本地问答文本库支持动态变量功能
- [ ] 兼容bert vits2
- [x] 兼容bert vits2

## 📝更新日志

<details>
<summary>展开/收起</summary>

- 2023-09-08
- VITS下,兼容bert-vits2

- 2023-09-05
- 修复后置回复没法关闭 念用户名 的bug
- 删除部分无关紧要的违禁词
Expand Down
4 changes: 3 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
}
},
"vits": {
"type": "vits",
"config_path": "E:\\vits-simple-api\\Model\\ikaros\\config.json",
"api_ip_port": "http://127.0.0.1:23456",
"id": "0",
Expand All @@ -165,7 +166,8 @@
"length": "1",
"noise": "0.33",
"noisew": "0.4",
"max": "50"
"max": "50",
"sdp_radio": "0.2"
},
"vits_fast": {
"config_path": "D:\\GitHub_pro\\VITS-fast-fine-tuning\\inference\\finetune_speaker.json",
Expand Down
4 changes: 3 additions & 1 deletion config.json.bak
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
}
},
"vits": {
"type": "vits",
"config_path": "E:\\vits-simple-api\\Model\\ikaros\\config.json",
"api_ip_port": "http://127.0.0.1:23456",
"id": "0",
Expand All @@ -165,7 +166,8 @@
"length": "1",
"noise": "0.33",
"noisew": "0.4",
"max": "50"
"max": "50",
"sdp_radio": "0.2"
},
"vits_fast": {
"config_path": "D:\\GitHub_pro\\VITS-fast-fine-tuning\\inference\\finetune_speaker.json",
Expand Down
42 changes: 32 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1420,6 +1420,17 @@ def vits_gui_create():
data_json = []

vits_config = config.get("vits")
tmp_json = {
"label_text": "类型",
"label_tip": "选用的TTS模型",
"widget_type": "combo_box",
"combo_data_list": ["vits", "bert_vits2"],
"data": vits_config["type"],
"main_obj_name": "vits",
"index": 0
}
data_json.append(tmp_json)

tmp_json = {
"label_text": "配置文件路径",
"label_tip": "模型配置文件存储路径",
Expand Down Expand Up @@ -1499,7 +1510,16 @@ def vits_gui_create():
"label_tip": "支持wav,ogg,silk,mp3,flac",
"data": vits_config["format"],
"main_obj_name": "vits",
"index": 3
"index": 9
}
data_json.append(tmp_json)

tmp_json = {
"label_text": "SDP/DP混合比",
"label_tip": "SDP/DP混合比:SDP在合成时的占比,理论上此比率越高,合成的语音语调方差越大。",
"data": vits_config["sdp_radio"],
"main_obj_name": "vits",
"index": 10
}
data_json.append(tmp_json)

Expand Down Expand Up @@ -2476,15 +2496,17 @@ def reorganize_vits_data(vits_data):
keys = list(vits_data.keys())

tmp_json = {
"config_path": vits_data[keys[0]],
"api_ip_port": vits_data[keys[1]],
"id": vits_data[keys[2]],
"format": vits_data[keys[8]],
"lang": vits_data[keys[3]],
"length": vits_data[keys[4]],
"noise": vits_data[keys[5]],
"noisew": vits_data[keys[6]],
"max": vits_data[keys[7]]
"type": vits_data[keys[0]],
"config_path": vits_data[keys[1]],
"api_ip_port": vits_data[keys[2]],
"id": vits_data[keys[3]],
"format": vits_data[keys[9]],
"lang": vits_data[keys[4]],
"length": vits_data[keys[5]],
"noise": vits_data[keys[6]],
"noisew": vits_data[keys[7]],
"max": vits_data[keys[8]],
"sdp_radio": vits_data[keys[10]],
}

logging.debug(f"tmp_json={tmp_json}")
Expand Down
2 changes: 2 additions & 0 deletions utils/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ async def voice_change_and_put_to_queue(message, voice_tmp_path):
# logging.info("language=" + language)

data = {
"type": message["data"]["type"],
"api_ip_port": message["data"]["api_ip_port"],
"id": message["data"]["id"],
"format": message["data"]["format"],
Expand All @@ -381,6 +382,7 @@ async def voice_change_and_put_to_queue(message, voice_tmp_path):
"noise": message["data"]["noise"],
"noisew": message["data"]["noisew"],
"max": message["data"]["max"],
"sdp_radio": message["data"]["sdp_radio"],
"content": message["content"]
}

Expand Down
78 changes: 53 additions & 25 deletions utils/audio_handle/my_tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,59 @@ def __init__(self, config_path):
# 请求vits的api
async def vits_api(self, data):
try:
# API地址 "http://127.0.0.1:23456/voice/vits"
API_URL = data["api_ip_port"] + '/voice/vits'
data_json = {
"text": data["content"],
"id": data["id"],
"format": data["format"],
"lang": "ja",
"length": data["length"],
"noise": data["noise"],
"noisew": data["noisew"],
"max": data["max"]
}

if data["lang"] == "中文" or data["lang"] == "汉语":
data_json["lang"] = "zh"
elif data["lang"] == "英文" or data["lang"] == "英语":
data_json["lang"] = "en"
elif data["lang"] == "韩文" or data["lang"] == "韩语":
data_json["lang"] = "ko"
elif data["lang"] == "日文" or data["lang"] == "日语":
data_json["lang"] = "ja"
elif data["lang"] == "自动":
data_json["lang"] = "auto"
else:
data_json["lang"] = "auto"
if data["type"] == "vits":
# API地址 "http://127.0.0.1:23456/voice/vits"
API_URL = data["api_ip_port"] + '/voice/vits'
data_json = {
"text": data["content"],
"id": data["id"],
"format": data["format"],
"lang": "ja",
"length": data["length"],
"noise": data["noise"],
"noisew": data["noisew"],
"max": data["max"]
}

if data["lang"] == "中文" or data["lang"] == "汉语":
data_json["lang"] = "zh"
elif data["lang"] == "英文" or data["lang"] == "英语":
data_json["lang"] = "en"
elif data["lang"] == "韩文" or data["lang"] == "韩语":
data_json["lang"] = "ko"
elif data["lang"] == "日文" or data["lang"] == "日语":
data_json["lang"] = "ja"
elif data["lang"] == "自动":
data_json["lang"] = "auto"
else:
data_json["lang"] = "auto"
elif data["type"] == "bert_vits2":
# API地址 "http://127.0.0.1:23456/voice/bert-vits2"
API_URL = data["api_ip_port"] + '/voice/bert-vits2'
data_json = {
"text": data["content"],
"id": data["id"],
"format": data["format"],
"lang": "ja",
"length": data["length"],
"noise": data["noise"],
"noisew": data["noisew"],
"max": data["max"],
"sdp_radio": data["sdp_radio"]
}

if data["lang"] == "中文" or data["lang"] == "汉语":
data_json["lang"] = "zh"
elif data["lang"] == "英文" or data["lang"] == "英语":
data_json["lang"] = "en"
elif data["lang"] == "韩文" or data["lang"] == "韩语":
data_json["lang"] = "ko"
elif data["lang"] == "日文" or data["lang"] == "日语":
data_json["lang"] = "ja"
elif data["lang"] == "自动":
data_json["lang"] = "auto"
else:
data_json["lang"] = "auto"

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

0 comments on commit 00be6f6

Please sign in to comment.