/** * TTS Stream Bridge — generates TTS audio server-side and pipes PCM data * into FFmpeg's audio track for RTMP streaming. * * Uses pipe:3 (a 4th stdio fd) as the audio input to FFmpeg. Writes PCM * silence when idle and decoded TTS audio when speaking. This avoids FIFO * complexity and works cross-platform. * * @module services/tts-stream-bridge */ import type { Writable } from "node:stream"; import type { TtsConfig, TtsProvider } from "../config/types.messages"; /** Resolved TTS configuration for a speak() call. */ export interface ResolvedTtsConfig { provider: TtsProvider; elevenlabs?: { apiKey: string; voiceId: string; modelId: string; voiceSettings?: Record; }; openai?: { apiKey: string; model: string; voice: string; }; edge?: { voice: string; }; } /** Public interface for the TTS stream bridge. */ export interface ITtsStreamBridge { attach(stream: Writable): void; detach(): void; isAttached(): boolean; isSpeaking(): boolean; speak(text: string, config: ResolvedTtsConfig): Promise; } declare class TtsStreamBridge implements ITtsStreamBridge { private writeStream; private tickTimer; private pcmQueue; private _speaking; private silenceChunk; constructor(); /** Attach the bridge to an FFmpeg stdio pipe (pipe:3). */ attach(stream: Writable): void; /** Detach from FFmpeg — stops tick loop and clears queue. */ detach(): void; /** Whether the bridge is currently attached to an FFmpeg process. */ isAttached(): boolean; /** Whether TTS audio is currently being played. */ isSpeaking(): boolean; /** * Generate TTS for the given text and queue PCM audio for playback. * Non-blocking — queues audio and returns immediately after generation. */ speak(text: string, config: ResolvedTtsConfig): Promise; /** Called every CHUNK_MS — writes next PCM chunk (TTS or silence) to FFmpeg. */ private tick; private generateTts; private generateElevenlabs; private generateOpenai; private generateEdge; /** Decode MP3 audio to raw s16le PCM using an FFmpeg subprocess. */ private decodeMp3ToPcm; } /** * Resolve TTS configuration from milady config, finding the best available * provider with valid API keys. */ export declare function resolveTtsConfig(ttsConfig: TtsConfig | undefined): ResolvedTtsConfig | null; /** * Get a summary of available TTS providers and their status. */ export declare function getTtsProviderStatus(ttsConfig: TtsConfig | undefined): { configuredProvider: string | null; hasApiKey: boolean; resolvedProvider: string | null; }; export declare const ttsStreamBridge: TtsStreamBridge; export {}; //# sourceMappingURL=tts-stream-bridge.d.ts.map