diff --git a/config.json b/config.json index b1444b3e..9076f017 100644 --- a/config.json +++ b/config.json @@ -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, diff --git a/config.json.bak b/config.json.bak index b1444b3e..9076f017 100644 --- a/config.json.bak +++ b/config.json.bak @@ -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, diff --git a/utils/audio.py b/utils/audio.py index 55ef32ae..fb6fbec7 100644 --- a/utils/audio.py +++ b/utils/audio.py @@ -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) @@ -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 } # 调用接口合成语音 diff --git a/utils/audio_handle/my_tts.py b/utils/audio_handle/my_tts.py index e06a554c..db4c55a3 100644 --- a/utils/audio_handle/my_tts.py +++ b/utils/audio_handle/my_tts.py @@ -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}') diff --git a/webui.py b/webui.py index af4b5e98..521f108e 100644 --- a/webui.py +++ b/webui.py @@ -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 @@ -4981,6 +4985,19 @@ 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"), @@ -4988,10 +5005,15 @@ async def fish_speech_load_model(data): 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):