Files
scrapyard-cogworks/wiki/TtsToy-Servers.md
T
kingston 26a0728e14 docs: move cog documentation into the wiki and stub the README
The root README carried the full ten cog manual while the wiki held the
authoritative pages. Point the repository at the wiki, keep only install and
catalog basics in the README, and remove the per cog documents that are now
folded into wiki source under wiki/.
2026-11-03 12:54:42 -06:00

8.5 KiB

TtsToy Servers

TtsToy talks to five optional services over HTTP. Four of them run as independent processes, normally under systemd, and are not started or stopped by the cog. The cog only needs their addresses.

The repository includes server code for DECTalk, Morshu and VOX under ttstoy/dectalk-server, ttstoy/morshu-server and ttstoy/vox-server. Chatterbox and Piper are separate projects.

Port and endpoint summary

Service Default address Endpoints used
DECTalk http://127.0.0.1:33001 GET /health, POST /v1/t2a_v2
Morshu http://127.0.0.1:33002 GET /say?text=...
VOX port 33003 declared, generation is in process none currently
Piper http://127.0.0.1:5006 POST /synthesize, GET /voices, GET /
Chatterbox http://127.0.0.1:8099 See below
TtsToy web UI port 8098, behind a public URL POST /api/register_token
TtsToy health port 8097 GET /health

DECTalk server

The DECTalk service exposes a MiniMax-shaped synthesis API so the cog can use one request builder for both engines.

Request to /v1/t2a_v2:

{
  "model": "<model>",
  "text": "<text with [:xx] voice tags>",
  "stream": false,
  "language_boost": "auto",
  "output_format": "hex",
  "voice_setting": {"voice_id": "paul", "speed": 1, "vol": 1, "pitch": 0},
  "audio_setting": {"sample_rate": 32000, "bitrate": 128000, "format": "mp3", "channel": 1}
}

The response must contain base_resp.status_code equal to 0 and a hex encoded MP3 in data.audio. GET /health must answer 200 for the preflight check in [p]tts.

The bundled server is a Node.js application. It requires Node.js 14 or newer, npm, and ffmpeg. The npm install step pulls express and the dectalk package, which ships the original DECTalk binaries and works on Linux.

The server listens on port 3000 by default; the deployment convention for this cog is PORT=33001. OUTPUT_DIR changes where generated files are kept. Endpoints beyond the two the cog calls are GET /engine, which returns the engine type and version, GET /say?text=..., which returns MP3 bytes for quick tests, and GET /voices, which lists the nine voices.

Generated audio is mono, 32 kHz, 128 kbps MP3, matching what the cog expects. On Debian derivatives the DECTalk binaries may need libasound2. The service is expected to be managed with systemd under the unit name dectalk-tts-server, which is the name the cog prints in its mode confirmation.

DECTalk accepts synthesis commands in the text:

Command Effect
[:phoneme on] Switches to phoneme input
[:rate 200] Sets speech rate, default 180
[:dv ap 100] Sets voice parameters

Example: [p]tts [:rate 200] speaking very fast.

Because the cog no longer manages the process, the commands dectalkinstall, dectalkstart, dectalkstop, dectalkstatus and dectalkautotoggle from older releases are gone. Use systemctl or an equivalent service manager.

Morshu server

GET /say?text=<url encoded text> returns MP3 bytes. The cog requests it with a 60 second timeout. When the request fails for any reason, the cog falls back to the in-process engine from morshutalk_engine.py, which needs g2p_en, numpy and pydub.

There is no health endpoint. The preflight in [p]tts checks only whether the engine imported, not whether the server is up.

The Morshu voice is fixed. Voice selection commands explain this and point at the mode itself.

VOX

The VOX engine is implemented in vox_engine.py and runs inside the bot process. It synthesises speech by concatenating samples for known words, so unknown words are skipped and the output can be unintelligible for unusual text.

[p]ttstoy voxpack switches between the vox and vox2 packs detected on disk. [p]ttstoy voxwords lists the current vocabulary, split across messages to stay under the limit.

The cog declares vox_port = 33003 but does not use it. A vox-server directory exists in the repository for a standalone service, which the current renderer does not call.

Piper server

POST /synthesize with:

{"text": "...", "voice": "en_US-ryan-medium"}

voice is omitted when the cog has no model configured, in which case the server's default is used. The response must be audio; the cog treats fewer than 100 bytes as a failure.

GET /voices is used only for the listing in [p]ttstoy pipervoice. It may return a mapping of ids or a list of objects with key or name; the cog handles both.

GET / is the reachability preflight. It must answer 200.

The accessibility voice pool uses five model ids: en_US-kristin-medium, en_US-hfc_female-medium, en_US-hfc_male-medium, en_US-john-medium and en_US-lessac-high. Each must exist in the server's data directory.

Piper models are .onnx files in the server's data directory. The model id is the filename without the extension.

Chatterbox server

Required endpoints:

Method and path Purpose
POST /tts Synthesis, returns WAV bytes
POST /upload_predefined_voice Multipart upload of a reference clip
DELETE /delete_predefined_voice/<filename> Removes a reference clip
GET /api/ui/initial-data Reachability check
GET /openapi.json Confirms a /tts route exists
GET /api/model-info Reports model type, class and loaded state
POST /save_settings Sets model.repo_id
POST /restart_server Hot swaps the model

The last three are used only by [p]chatterbox model and may not exist on every build. The cog reports the failure rather than hiding it.

Synthesis payload:

{
  "text": "...",
  "voice_mode": "predefined",
  "predefined_voice_id": "<user id>_<name>.wav",
  "output_format": "wav",
  "split_text": false,
  "temperature": 0.8,
  "exaggeration": 1.2,
  "speed_factor": 1.1
}

The tuning keys are omitted when unset. A 500 response whose body contains "failed to synthesize" is translated into advice about the reference clip's length and format.

Reference clips live in the server's voice directory. The cog owns their filenames and the per-user lists, but not the bytes.

TtsToy web UI service

The web UI is a separate service, not a bot subprocess. It shares state with the cog through a JSON file.

Paths and environment:

Variable Default Purpose
TTSTOY_SHARED_STATE /tmp/ttstoy_webui_state.json Shared state file
TTSTOY_SHARED_STATE_LOCK /tmp/ttstoy_webui_state.lock Lock file for cross-process updates
WEBUI_PORT 8098 Port the cog calls for internal API requests
WEBUI_URL https://ttstoy.kingstons-scrapyard.net Public URL shown to members
TTSTOY_WEBUI_CHANNEL_ID unset Fallback channel for web UI audio

The state file holds internal_secret, webui_url, users, pending_commands and pending_posts. The cog polls every three seconds, takes the pending arrays under a file lock, refreshes member profile fields from every guild, and writes the file back.

Login flow

  1. [p]ttstoy login reads internal_secret from the state file. If it is missing, the command refuses.
  2. The cog posts to <internal URL>/api/register_token with the header X-Internal-Secret and a body containing the user id, Discord name, avatar URL, owner flag, guild id and guild name.
  3. The service returns a token.
  4. The bot DMs a login URL and the token, valid for five minutes.
  5. The member logs in once on the homepage and the session cookie is shared across the Scrapyard subdomains.

Queued actions

The web UI can queue set_voice, set_mode, set_chatterbox_params, add_voice and remove_voice. The cog validates the user, checks owner status for set_mode, and applies the change to config.

Queued posts carry a generated audio path, text, the user's display name, engine, guild and user ids, and a play_vc flag. If play_vc is set and the member is in a voice channel with a connected node, the file is queued for playback. The transcript and file are then posted to the configured channel.

The shared state file is readable by any local user on a default temporary directory and contains the internal secret. Restrict its permissions or move it with TTSTOY_SHARED_STATE.

Deployment checklist

  1. Start Lavalink and confirm port 2333.
  2. Start the engine services you intend to use and confirm their health endpoints.
  3. Load YTAudio, then TtsToy.
  4. Set the engine with [p]ttstoy mode and verify with [p]tts.
  5. For the web UI, start the service, confirm it writes the shared state file, then run [p]ttstoy login.
  6. Set [p]ttstoy webuichannel per guild where web UI audio should appear.