Skip to content

Commit

Permalink
Merge pull request #873 from Ikaros-521/owner
Browse files Browse the repository at this point in the history
更新ChatTTS的API对接(刘悦佬整合包)
  • Loading branch information
Ikaros-521 authored Jun 8, 2024
2 parents 94e6732 + ea93637 commit 148db31
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 19 deletions.
11 changes: 9 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -802,9 +802,16 @@
}
},
"chattts": {
"gradio_ip_port": "http://127.0.0.1:8080",
"type": "gradio",
"api_ip_port": "http://127.0.0.1:58081",
"gradio_ip_port": "http://127.0.0.1:58081",
"temperature": 0.3,
"audio_seed_input": -1
"audio_seed_input": 1,
"api": {
"media_type": "wav",
"seed": 2581,
"streaming": 0
}
},
"choose_song": {
"enable": false,
Expand Down
11 changes: 9 additions & 2 deletions config.json.bak
Original file line number Diff line number Diff line change
Expand Up @@ -802,9 +802,16 @@
}
},
"chattts": {
"gradio_ip_port": "http://127.0.0.1:8080",
"type": "gradio",
"api_ip_port": "http://127.0.0.1:58081",
"gradio_ip_port": "http://127.0.0.1:58081",
"temperature": 0.3,
"audio_seed_input": -1
"audio_seed_input": 1,
"api": {
"media_type": "wav",
"seed": 2581,
"streaming": 0
}
},
"choose_song": {
"enable": false,
Expand Down
8 changes: 7 additions & 1 deletion utils/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -1018,10 +1018,13 @@ async def tts_handle(self, message):
elif message["tts_type"] == "chattts":
logging.info(message)
data = {
"type": message["data"]["type"],
"api_ip_port": message["data"]["api_ip_port"],
"gradio_ip_port": message["data"]["gradio_ip_port"],
"temperature": message["data"]["temperature"],
"audio_seed_input": message["data"]["audio_seed_input"],
"content": message["content"]
"content": message["content"],
"api": message["data"]["api"],
}

voice_tmp_path = await self.my_tts.chattts_api(data)
Expand Down Expand Up @@ -1932,9 +1935,12 @@ async def audio_synthesis_use_local_config(self, content, audio_synthesis_type="
voice_tmp_path = await self.my_tts.fish_speech_api(data)
elif audio_synthesis_type == "chattts":
data = {
"type": self.config.get("chattts", "type"),
"api_ip_port": self.config.get("chattts", "api_ip_port"),
"gradio_ip_port": self.config.get("chattts", "gradio_ip_port"),
"temperature": self.config.get("chattts", "temperature"),
"audio_seed_input": self.config.get("chattts", "audio_seed_input"),
"api": self.config.get("chattts", "api"),
"content": content
}
# 调用接口合成语音
Expand Down
43 changes: 31 additions & 12 deletions utils/audio_handle/my_tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -1113,21 +1113,40 @@ async def chattts_api(self, data):
str: 音频路径
"""
try:
client = Client(data["gradio_ip_port"])
result = client.predict(
data["content"], # str in '需要合成的文本' Textbox component
data["temperature"], # 越大越发散,越小越保守
data["audio_seed_input"], # 声音种子,-1随机,1女生,4女生,8男生
api_name="/generate_audio"
)
if data["type"] == "gradio":
client = Client(data["gradio_ip_port"])
result = client.predict(
data["content"], # str in '需要合成的文本' Textbox component
data["temperature"], # 越大越发散,越小越保守
data["audio_seed_input"], # 声音种子,-1随机,1女生,4女生,8男生
api_name="/generate_audio"
)

new_file_path = None
new_file_path = None

if result:
voice_tmp_path = result[0]
new_file_path = self.common.move_file(voice_tmp_path, os.path.join(self.audio_out_path, 'chattts_' + self.common.get_bj_time(4)), 'chattts_' + self.common.get_bj_time(4))
if result:
voice_tmp_path = result[0]
new_file_path = self.common.move_file(voice_tmp_path, os.path.join(self.audio_out_path, 'chattts_' + self.common.get_bj_time(4)), 'chattts_' + self.common.get_bj_time(4))

return new_file_path
return new_file_path
elif data["type"] == "api":
params = {
"text": data["content"],
"media_type": data["api"]["media_type"],
"seed": data["api"]["seed"],
"streaming": data["api"]["streaming"],
}

try:
return await self.download_audio("ChatTTS", data["api_ip_port"], self.timeout, "get", params)
except aiohttp.ClientError as e:
logging.error(traceback.format_exc())
logging.error(f'ChatTTS请求失败: {e}')
except Exception as e:
logging.error(traceback.format_exc())
logging.error(f'ChatTTS未知错误: {e}')

return None
except Exception as e:
logging.error(traceback.format_exc())
logging.error(f'ChatTTS未知错误,请检查您的ChatTTS WebUI是否启动/配置是否正确,报错内容: {e}')
Expand Down
26 changes: 24 additions & 2 deletions webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2276,9 +2276,13 @@ def common_textarea_handle(content):
config_data["fish_speech"]["web"]["repetition_penalty"] = round(float(input_fish_speech_web_repetition_penalty.value), 2)

if config.get("webui", "show_card", "tts", "chattts"):
config_data["chattts"]["type"] = select_chattts_type.value
config_data["chattts"]["api_ip_port"] = input_chattts_api_ip_port.value
config_data["chattts"]["gradio_ip_port"] = input_chattts_gradio_ip_port.value
config_data["chattts"]["temperature"] = round(float(input_chattts_temperature.value), 2)
config_data["chattts"]["audio_seed_input"] = int(input_chattts_audio_seed_input.value)
config_data["chattts"]["api"]["seed"] = int(input_chattts_api_seed.value)
config_data["chattts"]["api"]["media_type"] = input_chattts_api_media_type.value

"""
SVC
Expand Down Expand Up @@ -4981,17 +4985,35 @@ async def fish_speech_load_model(data):
with ui.card().style(card_css):
ui.label("ChatTTS")
with ui.row():
select_chattts_type = ui.select(
label='类型',
options={"api": "api", "gradio": "gradio"},
value=config.get("chattts", "type")
).style("width:150px").tooltip("对接的API类型")
input_chattts_api_ip_port = ui.input(
label='API地址',
value=config.get("chattts", "api_ip_port"),
placeholder='刘悦佬接口程序启动后api监听的地址',
validation={
'请输入正确格式的URL': lambda value: common.is_url_check(value),
}
).style("width:200px;").tooltip("对接新版刘悦佬整合包的api接口,填api的地址")
input_chattts_gradio_ip_port = ui.input(
label='Gradio API地址',
value=config.get("chattts", "gradio_ip_port"),
placeholder='官方webui程序启动后gradio监听的地址',
validation={
'请输入正确格式的URL': lambda value: common.is_url_check(value),
}
).style("width:200px;")
).style("width:200px;").tooltip("对接旧版webui的gradio接口,填webui的地址")
input_chattts_temperature = ui.input(label='温度', value=config.get("chattts", "temperature"), placeholder='默认:0.3').style("width:200px;").tooltip("Audio temperature,越大越发散,越小越保守")
input_chattts_audio_seed_input = ui.input(label='声音种子', value=config.get("chattts", "audio_seed_input"), placeholder='默认:-1').style("width:200px;").tooltip("声音种子,-1随机,1女生,4女生,8男生")

with ui.card().style(card_css):
ui.label("API相关配置")
with ui.row():
input_chattts_api_seed = ui.input(label='声音种子', value=config.get("chattts", "api", "seed"), placeholder='默认:2581').style("width:200px;").tooltip("声音种子")
input_chattts_api_media_type = ui.input(label='音频格式', value=config.get("chattts", "api", "media_type"), placeholder='默认:wav').style("width:200px;").tooltip("音频格式,没事不建议改")

with ui.tab_panel(svc_page).style(tab_panel_css):
if config.get("webui", "show_card", "svc", "ddsp_svc"):
with ui.card().style(card_css):
Expand Down

0 comments on commit 148db31

Please sign in to comment.