diff --git a/cli.py b/cli.py index 43fae44..f376762 100644 --- a/cli.py +++ b/cli.py @@ -25,6 +25,7 @@ TEMPERATURE = config.FindItem("temperature", 1.3) MAX_CONTENT_LENGTH = config.FindItem("max_content_length", None) SYSTEM_PROMPT_PATH = config.FindItem("system_prompt_path", None) AUTO_SPEAK_WAIT_SECOND = config.FindItem("auto_speak_wait_second", 15.0) +TTS_ENABLE = config.FindItem("tts_enable", False) TTS_SERVER_URL = config.FindItem("tts_server_url", "http://localhost:43400") TTS_PROMPT_TEXT = config.FindItem("tts_prompt_text", None) TTS_PROMPT_WAV_PATH = config.FindItem("tts_prompt_wav_path", None) @@ -40,6 +41,7 @@ if VERBOSE: PrintColorful(ConsoleFrontColor.LIGHTYELLOW_EX,f"MAX_CONTENT_LENGTH: {MAX_CONTENT_LENGTH}") PrintColorful(ConsoleFrontColor.LIGHTYELLOW_EX,f"SYSTEM_PROMPT_PATH: {SYSTEM_PROMPT_PATH}") PrintColorful(ConsoleFrontColor.LIGHTYELLOW_EX,f"AUTO_SPEAK_WAIT_SECOND: {AUTO_SPEAK_WAIT_SECOND}") + PrintColorful(ConsoleFrontColor.LIGHTYELLOW_EX,f"TTS_ENABLE: {TTS_ENABLE}") temp_dir = config.GetFile("temp")|chat_start_id|None ollama_llm_config = { @@ -202,6 +204,8 @@ async def audio_player_worker(): # CHANGE TOCHECK async def play_vocal(text:str) -> None: + if not TTS_ENABLE: + return if len(text) == 0 or not text: return tts_server_url = f"{TTS_SERVER_URL}/api/synthesis/sft" @@ -287,11 +291,13 @@ async def achat(engine:SimpleChatEngine,message:str) -> None: buffer_response += ch if len(buffer_response) > 20: if ch in end_symbol: - await play_vocal(buffer_response.strip()) + if TTS_ENABLE: + await play_vocal(buffer_response.strip()) buffer_response = "" buffer_response = buffer_response.strip() if len(buffer_response) > 0: - await play_vocal(buffer_response) + if TTS_ENABLE: + await play_vocal(buffer_response) def add_speaker() -> None: @@ -317,8 +323,11 @@ def add_speaker() -> None: async def event_loop(engine:SimpleChatEngine) -> None: - add_speaker() - audio_player_task = asyncio.create_task(audio_player_worker()) + if TTS_ENABLE: + add_speaker() + audio_player_task = asyncio.create_task(audio_player_worker()) + else: + audio_player_task = None message = input("请开始对话: ") wait_second = AUTO_SPEAK_WAIT_SECOND try: @@ -332,10 +341,11 @@ async def event_loop(engine:SimpleChatEngine) -> None: else: wait_second = AUTO_SPEAK_WAIT_SECOND finally: - await audio_play_queue.join() - await audio_play_queue.put(None) - await audio_player_task - cleanup_audio() + if TTS_ENABLE and audio_player_task is not None: + await audio_play_queue.join() + await audio_play_queue.put(None) + await audio_player_task + cleanup_audio() async def main(): diff --git a/pip_install.bat b/pip_install.bat new file mode 100644 index 0000000..1d8a2c9 --- /dev/null +++ b/pip_install.bat @@ -0,0 +1 @@ +pip install torch torchvision --index-url https://download.pytorch.org/whl/cu126 diff --git a/requirements.txt b/requirements.txt index 6769be7..046040a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -95,7 +95,6 @@ pydantic==2.7.0 pydantic_core==2.18.1 pydub==0.25.1 Pygments==2.19.2 -pynini @ file:///D:/bld/pynini_1696660974449/work pyparsing==3.2.5 pyreadline3==3.5.4 PySocks==1.7.1