diff --git a/README.md b/README.md index e3fe0c7..87ae374 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ A ComfyUI custom node for text-to-speech integration with a local TTS server. ## Features - Custom ComfyUI node `HttpTTSToAudio` for sending text to a local TTS server. -- Local TTS server using Coqui TTS (XTTS v2 model). +- Local TTS server using pyttsx3 (offline TTS engine). - Easy setup with batch files for Windows. ## Prerequisites diff --git a/install.bat b/install.bat index 3fc9ad2..114ac0b 100644 --- a/install.bat +++ b/install.bat @@ -3,25 +3,25 @@ echo Setting up TTS environment... REM Check for Python in ComfyUI root python_embeded directory if exist "..\..\..\python_embeded\python.exe" ( - set PYTHON_EXE="..\..\..\python_embeded\python.exe" + set PYTHON_EXE=..\..\..\python_embeded\python.exe goto :python_found ) REM Check for Python in ComfyUI python_embeded directory (higher in tree) if exist "..\..\python_embeded\python.exe" ( - set PYTHON_EXE="..\..\python_embeded\python.exe" + set PYTHON_EXE=..\..\python_embeded\python.exe goto :python_found ) REM Check for Python in ComfyUI python_embeded directory if exist "..\python_embeded\python.exe" ( - set PYTHON_EXE="..\python_embeded\python.exe" + set PYTHON_EXE=..\python_embeded\python.exe goto :python_found ) REM Check for Python in ComfyUI directory if exist "..\python.exe" ( - set PYTHON_EXE="..\python.exe" + set PYTHON_EXE=..\python.exe goto :python_found ) @@ -42,13 +42,13 @@ echo Using Python: %PYTHON_EXE% REM Set PIP_EXE based on Python location if "%PYTHON_EXE%" == "..\..\..\python_embeded\python.exe" ( - set PIP_EXE="..\..\..\python_embeded\Scripts\pip.exe" + set PIP_EXE=..\..\..\python_embeded\Scripts\pip.exe set USE_VENV=false ) else if "%PYTHON_EXE%" == "..\..\python_embeded\python.exe" ( - set PIP_EXE="..\..\python_embeded\Scripts\pip.exe" + set PIP_EXE=..\..\python_embeded\Scripts\pip.exe set USE_VENV=false ) else if "%PYTHON_EXE%" == "..\python_embeded\python.exe" ( - set PIP_EXE="..\python_embeded\Scripts\pip.exe" + set PIP_EXE=..\python_embeded\Scripts\pip.exe set USE_VENV=false ) else ( set PIP_EXE=pip diff --git a/requirements.txt b/requirements.txt index aa33a59..afa8b8b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -TTS +pyttsx3 flask \ No newline at end of file diff --git a/run_tts.bat b/run_tts.bat index 6ec4bb0..af614e8 100644 --- a/run_tts.bat +++ b/run_tts.bat @@ -7,13 +7,17 @@ if exist venv ( ) else ( REM Check for embedded Python if exist "..\..\..\python_embeded\python.exe" ( - set PYTHON_CMD="..\..\..\python_embeded\python.exe" - ) else if exist "..\..\python_embeded\python.exe" ( - set PYTHON_CMD="..\..\python_embeded\python.exe" - ) else if exist "..\python_embeded\python.exe" ( - set PYTHON_CMD="..\python_embeded\python.exe" + set PYTHON_CMD=..\..\..\python_embeded\python.exe ) else ( - set PYTHON_CMD=python + if exist "..\..\python_embeded\python.exe" ( + set PYTHON_CMD=..\..\python_embeded\python.exe + ) else ( + if exist "..\python_embeded\python.exe" ( + set PYTHON_CMD=..\python_embeded\python.exe + ) else ( + set PYTHON_CMD=python + ) + ) ) ) diff --git a/tts_server.py b/tts_server.py index 63d139b..e6344f8 100644 --- a/tts_server.py +++ b/tts_server.py @@ -1,13 +1,10 @@ from flask import Flask, request, send_file, jsonify -from TTS.api import TTS +import pyttsx3 import os import uuid -# Choose a model (example: XTTS v2 multilingual; you can pick any supported model) -MODEL_NAME = "tts_models/multilingual/multi-dataset/xtts_v2" - app = Flask(__name__) -tts = TTS(MODEL_NAME) +engine = pyttsx3.init() OUTPUT_DIR = "outputs" os.makedirs(OUTPUT_DIR, exist_ok=True) @@ -16,8 +13,7 @@ os.makedirs(OUTPUT_DIR, exist_ok=True) def tts_route(): data = request.get_json() text = data.get("text", "").strip() - speaker = data.get("speaker") # optional - language = data.get("language", "en") # optional + language = data.get("language", "en") # pyttsx3 doesn't support language directly, but we can set voice if not text: return jsonify({"error": "No text"}), 400 @@ -25,13 +21,12 @@ def tts_route(): out_name = f"{uuid.uuid4().hex}.wav" out_path = os.path.join(OUTPUT_DIR, out_name) + # Set properties if needed + # engine.setProperty('voice', voice_id) # for language, but pyttsx3 has limited support + # Generate audio - # For XTTS you can pass language, speaker_wav, etc.; adjust to your chosen model - tts.tts_to_file( - text=text, - file_path=out_path, - language=language - ) + engine.save_to_file(text, out_path) + engine.runAndWait() return jsonify({ "ok": True,