Skip to content

Commit 1024409

Browse files
Add emoji and Unicode symbol stripping to TTS sanitizer
Adds safety net sanitization to strip emojis, Unicode arrows, math operators, and other unpronouneable symbols before TTS playback. This ensures clean voice output even when agent responses contain special characters. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent dd1987e commit 1024409

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

extensions/voice-assistant/src/tts-sanitize.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,29 @@ export function sanitizeForTTS(text: string): string {
8282
// Curly braces, pipes, backslashes
8383
result = result.replace(/[{}|\\]/g, "");
8484

85+
// --- Remove emojis and Unicode symbols (TTS safety net) ---
86+
87+
// Emojis - remove all Unicode emoji characters
88+
result = result.replace(/[\u{1F300}-\u{1F9FF}]/gu, ""); // Misc symbols, emoticons
89+
result = result.replace(/[\u{2600}-\u{26FF}]/gu, ""); // Misc symbols
90+
result = result.replace(/[\u{2700}-\u{27BF}]/gu, ""); // Dingbats
91+
result = result.replace(/[\u{FE00}-\u{FE0F}]/gu, ""); // Variation selectors
92+
result = result.replace(/[\u{1F000}-\u{1F02F}]/gu, ""); // Mahjong, dominos
93+
result = result.replace(/[\u{1F0A0}-\u{1F0FF}]/gu, ""); // Playing cards
94+
95+
// Unicode arrows and symbols that TTS can't pronounce
96+
result = result.replace(/[\u{2190}-\u{21FF}]/gu, ""); // Arrows
97+
result = result.replace(/[\u{2200}-\u{22FF}]/gu, ""); // Math operators
98+
result = result.replace(/[\u{2300}-\u{23FF}]/gu, ""); // Misc technical
99+
result = result.replace(/[\u{25A0}-\u{25FF}]/gu, ""); // Geometric shapes
100+
result = result.replace(/[\u{2500}-\u{257F}]/gu, ""); // Box drawing
101+
102+
// Common special characters that slip through
103+
result = result.replace(/[©®±×÷]/g, "");
104+
105+
// Degree symbol - keep the number, remove the symbol
106+
result = result.replace(/°/g, " degrees ");
107+
85108
// --- Normalize whitespace ---
86109

87110
// Collapse 3+ newlines into double newline (natural pause)

0 commit comments

Comments
 (0)