Speech Text Sanitizer (src/spoken-text.ts)

eliza · packages/core/src/spoken-text.ts · typescript · MIT
voice, security, tag:text

Reduces model output to speakable prose for text-to-speech by stripping markup, code, URLs, and nested stage directions, then normalizing punctuation. Reuse before any TTS playback of agent replies.

// Source: https://github.com/elizaOS/eliza | License: MIT | Copyright 2026 Shaw Walters and elizaOS Contributors
// Provided via justclaw.it.com; keep this notice with the code.
/**
 * Reduces a model's written-form output to speakable prose for TTS.
 * `sanitizeSpeechText` NFKC-normalizes the input, then strips thinking /
 * analysis / tool tags, code fences and inline code, markdown links, raw HTML,
 * and URLs, removes parenthetical and bracketed stage directions, normalizes
 * punctuation and unusual glyphs, and collapses whitespace.
 *
 * Stage-direction stripping peels one innermost `()` / `[]` / `{}` / `**`
 * layer per pass. Honest asides nest a handful of delimiters; each miss
 * rescan is O(remaining), so an uncapped `((((…hello…))))` bomb hangs TTS.
 * {@link MAX_NON_SPEECH_STR

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key