Switch to pyttsx3 for TTS due to Python 3.13 compatibility issues with Coqui TTS

This commit is contained in:
GeekatplayStudio
2025-11-16 08:44:51 -07:00
parent 41f884bb90
commit c98fa9cb5e
5 changed files with 27 additions and 28 deletions
+1 -1
View File
@@ -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
+7 -7
View File
@@ -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
+1 -1
View File
@@ -1,2 +1,2 @@
TTS
pyttsx3
flask
+10 -6
View File
@@ -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
)
)
)
)
+8 -13
View File
@@ -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,