feat: add VOX TTS server on port 33003 with webui integration

- New vox-server/server.py (HTTP API matching morshu-server pattern)
- Added voxstart/voxstop/voxstatus commands to ttstoy cog
- WebUI /api/tts/generate and /api/mc/tts now support VOX mode
- Cog_unload stops VOX server automatically
This commit is contained in:
2026-06-09 11:07:59 -05:00
parent fa8c904c6f
commit 2f1e66cef4
4 changed files with 233 additions and 0 deletions
+109
View File
@@ -321,6 +321,11 @@ class TtsToy(Cog):
self.morshu_process = None
self.morshu_port = 33002
# VOX server
self.vox_dir = Path(__file__).resolve().parent / "vox-server"
self.vox_process = None
self.vox_port = 33003
# TTS queue system - one queue per guild
self.tts_queues = {} # guild_id -> asyncio.Queue
self.tts_locks = {} # guild_id -> asyncio.Lock
@@ -386,6 +391,8 @@ class TtsToy(Cog):
self._webui_state_processor.stop()
await self._stop_webui()
await self._stop_dectalk_server()
await self._stop_morshu_server()
await self._stop_vox_server()
if self._health_server:
self._health_server.shutdown()
@@ -572,6 +579,56 @@ class TtsToy(Cog):
except Exception as e:
log.exception(f"Error stopping Morshu server: {e}")
async def _start_vox_server(self) -> tuple:
"""Start the built-in VOX TTS server. Returns (success, error_msg)."""
try:
if self.vox_process and self.vox_process.poll() is None:
return True, None
server_py = self.vox_dir / "server.py"
if not server_py.exists():
return False, f"server.py not found: {server_py}"
env = os.environ.copy()
env['PORT'] = str(self.vox_port)
self.vox_process = await asyncio.to_thread(
subprocess.Popen,
[sys.executable, str(server_py)],
cwd=str(self.vox_dir),
env=env,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
await asyncio.sleep(2)
if self.vox_process.poll() is not None:
stderr = self.vox_process.stderr.read()
stdout = self.vox_process.stdout.read()
err = stderr or stdout or "Unknown error"
log.error(f"VOX server failed (exit {self.vox_process.returncode}): {err}")
return False, err
log.info(f"VOX server started on port {self.vox_port}")
return True, None
except Exception as e:
log.exception(f"Failed to start VOX server: {e}")
return False, str(e)
async def _stop_vox_server(self):
"""Stop the built-in VOX server."""
if self.vox_process and self.vox_process.poll() is None:
try:
self.vox_process.terminate()
await asyncio.sleep(1)
if self.vox_process.poll() is None:
self.vox_process.kill()
log.info("VOX server stopped")
except Exception as e:
log.exception(f"Error stopping VOX server: {e}")
async def _get_effective_minimax_voice(self, user: discord.abc.User) -> str:
mode = await self._get_tts_mode()
@@ -2181,6 +2238,58 @@ class TtsToy(Cog):
await ctx.send("\n".join(lines))
@ttstoy_group.command(name="voxstart")
@commands.is_owner()
async def vox_start(self, ctx: commands.Context):
"""Start the built-in VOX TTS server."""
await ctx.send("🚀 Starting VOX server...")
success, error = await self._start_vox_server()
if success:
await ctx.send(
f"✅ VOX server started on port {self.vox_port}!\n"
f"Switch to VOX mode: `{ctx.clean_prefix}ttstoy mode vox`"
)
else:
err_msg = (error or "Unknown error")[:1500]
await ctx.send(f"❌ Failed to start VOX server:\n```\n{err_msg}\n```")
@ttstoy_group.command(name="voxstop")
@commands.is_owner()
async def vox_stop(self, ctx: commands.Context):
"""Stop the built-in VOX server."""
if not self.vox_process or self.vox_process.poll() is not None:
return await ctx.send("❌ VOX server is not running")
await self._stop_vox_server()
await ctx.send("✅ VOX server stopped")
@ttstoy_group.command(name="voxstatus")
@commands.is_owner()
async def vox_status(self, ctx: commands.Context):
"""Check VOX server status."""
process_running = self.vox_process and self.vox_process.poll() is None
api_responding = False
try:
r = requests.get(f"http://127.0.0.1:{self.vox_port}/health", timeout=2)
api_responding = r.status_code == 200
except:
pass
lines = [
"**VOX Server Status**",
f"Process Running: {'✅ Yes' if process_running else '❌ No'}",
f"API Responding: {'✅ Yes' if api_responding else '❌ No'}",
f"URL: `http://127.0.0.1:{self.vox_port}`",
]
if not process_running:
lines.append(f"\nStart with: `{ctx.clean_prefix}ttstoy voxstart`")
await ctx.send("\n".join(lines))
@ttstoy_group.command(name="accessibility")
@commands.is_owner()
async def accessibility_toggle(self, ctx: commands.Context):