UNPKG

expo-edge-speech

Version:

Text-to-speech library for Expo using Microsoft Edge TTS service

178 lines 4.66 kB
/** * Complete EdgeSpeech WebSocket communication service using protocol knowledge * from previous tasks. Handles Edge TTS WebSocket protocol, binary audio processing, * boundary event parsing, timeout/retry logic, and storage service coordination. */ import { type SpeechOptions, type WordBoundary, ConnectionState, type TimingConverter, type SpeechNetworkConfig } from "../types"; import { StorageService } from "./storageService"; /** * Synthesis response data */ interface SynthesisResponse { /** Audio data chunks */ audioChunks: Uint8Array[]; /** Word boundary events */ boundaries: WordBoundary[]; /** Total audio duration in milliseconds */ duration: number; /** Synthesis completion status */ completed: boolean; } /** * Timing conversion implementation */ export declare const timingConverter: TimingConverter; /** * Network service for Edge TTS WebSocket communication */ export declare class NetworkService { private config; private storageService; private activeSessions; private connections; private debugLog; constructor(storageService: StorageService, config?: Partial<SpeechNetworkConfig>); /** * Synthesize SSML to speech using Edge TTS */ synthesizeText(ssml: string, options: SpeechOptions, clientSessionId: string, connectionId: string): Promise<SynthesisResponse>; /** * Close all connections and cleanup */ close(): Promise<void>; /** * Create and establish WebSocket connection */ private createConnection; /** * Setup WebSocket event handlers with state-aware logic */ private setupWebSocketHandlers; /** * Close a WebSocket connection */ private closeConnection; /** * Force close a WebSocket connection without waiting for graceful shutdown */ private forceCloseConnection; /** * Send speech configuration message */ private sendSpeechConfig; /** * Send SSML synthesis request */ private sendSSMLRequest; /** * Format text message with headers */ private formatTextMessage; /** * Send WebSocket message */ private sendWebSocketMessage; /** * Handle incoming WebSocket message */ private handleWebSocketMessage; /** * Handle text (JSON) message */ private handleTextMessage; /** * Handle binary (audio) message */ private handleBinaryMessage; /** * Handle turn start message */ private handleTurnStart; /** * Handle audio metadata (boundary events) */ private handleAudioMetadata; /** * Handle response message */ private handleResponse; /** * Handle turn end message */ private handleTurnEnd; /** * Process boundary event data */ private processBoundaryEvent; /** * Find the next occurrence of a word in text starting from a given position */ private findWordInText; /** * Calculate total audio duration */ private calculateAudioDuration; /** * Perform synthesis with retry logic */ private performSynthesisWithRetry; /** * Perform single synthesis attempt */ private performSynthesis; /** * Complete synthesis and resolve promise */ private completeSynthesis; /** * Handle synthesis timeout */ private handleSynthesisTimeout; /** * Handle connection error */ private handleConnectionError; /** * Cleanup synthesis session */ private cleanupSession; /** * Debug logging helper */ private log; /** * Get service statistics */ getStats(): { activeSessions: number; activeConnections: number; connections: { id: string; state: ConnectionState; createdAt: Date; lastActivity: Date; }[]; }; /** * Initialize the service (for StateManager integration) */ initialize(): Promise<void>; /** * Cleanup the service (for StateManager integration) */ cleanup(): Promise<void>; /** * Register callback for connection state changes (for StateManager integration) */ onConnectionStateChange(callback: (connectionId: string, state: ConnectionState) => void): void; private onConnectionStateChangeCallback; /** * Set connection state and trigger StateManager callback */ private setConnectionState; } /** * Default network service instance */ export default NetworkService; //# sourceMappingURL=networkService.d.ts.map