Implementation:23blocks OS Ai maestro TTS
| Knowledge Sources | |
|---|---|
| Domains | UI, Text_To_Speech |
| Last Updated | 2026-10-26 18:00 GMT |
Overview
Concrete tool for stripping terminal noise and speaking text via Web Speech API or other TTS providers, with long-text chunking and ANSI cleanup, provided by AI Maestro's `lib/tts.ts`.
Description
The tts module provides terminal-output cleanup and text-to-speech helpers. `stripAnsi` removes all ANSI escape sequences (CSI, OSC, DCS). `summarizeTerminalOutput` further removes box-drawing characters, block/shape elements, Braille spinners, progress bars, and percentage lines, then collapses whitespace and trims to the last N characters (most recent output). For speech, the Web Speech API provider chunks text at ≤180 chars (Chrome's ~15s utterance limit), preferring sentence boundaries, then commas, then spaces. The module exposes provider-agnostic TTS types and voice selection helpers.
Usage
Call `stripAnsi` on raw terminal output before display or speech. Call `summarizeTerminalOutput` to get a clean, length-bounded summary for the TTS engine. Use the chunking helpers to split long text for the Web Speech API.
Code Reference
Source Location
- Repository: ai-maestro
- File: lib/tts.ts
- Lines: L1-L409
Signature
export function stripAnsi(text: string): string
export function summarizeTerminalOutput(raw: string, maxLength?: number): string
// Web Speech API provider
export function createWebSpeechProvider(): TTSProvider
// Chunking for long text (Chrome ~15s utterance limit)
export function chunkText(text: string, maxChars?: number): string[]
Import
import { stripAnsi, summarizeTerminalOutput, createWebSpeechProvider } from '@/lib/tts'
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| text | string | Yes (stripAnsi) | Raw text with ANSI escape sequences |
| raw | string | Yes (summarize) | Raw terminal output |
| maxLength | number | No (summarize) | Max output length (default 300) |
Outputs
| Name | Type | Description |
|---|---|---|
| stripAnsi() returns | string | Text with ANSI sequences removed |
| summarizeTerminalOutput() returns | string | Clean, whitespace-collapsed summary |
| chunkText() returns | string[] | Text split into speakable chunks |
Usage Examples
Speak terminal output
import { summarizeTerminalOutput, createWebSpeechProvider } from '@/lib/tts'
const provider = createWebSpeechProvider()
const summary = summarizeTerminalOutput(rawTerminalOutput, 200)
await provider.speak(summary, { rate: 1.0 })
Clean text before display
import { stripAnsi } from '@/lib/tts'
const clean = stripAnsi(rawOutput) // ANSI sequences removed