UNPKG

expo-edge-speech

Version:

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

183 lines 5.71 kB
/** * Coordinates WebSocket connections via Network Service with audio playback via Audio Service. * Handles connection pooling using Storage Service, processes audio data streams, * manages concurrent connections using State Management, and implements circuit breaker pattern. */ import type { SpeechOptions, SpeechConnectionConfig } from "../types"; import { StateManager } from "./state"; import { NetworkService } from "../services/networkService"; import { AudioService } from "../services/audioService"; import { StorageService } from "../services/storageService"; /** * Circuit breaker state */ declare enum CircuitBreakerState { Closed = "closed",// Normal operation Open = "open",// Blocking requests due to failures HalfOpen = "halfopen" } /** * Connection Manager - coordinates all services for speech synthesis * * Responsibilities: * - Coordinate WebSocket connections via Network Service with audio playback via Audio Service * - Handle connection pooling using Storage Service connection management * - Implement connection lifecycle management using all service capabilities * - Process audio data streams coordinating Network Service, Storage Service, and Audio Utilities * - Handle connection errors and recovery using Network Service error handling * - Manage concurrent connections using State Management * - Coordinate real-time streaming between all services * - Implement circuit breaker pattern using complete error types and constants */ export declare class ConnectionManager { private stateManager; private networkService; private audioService; private storageService; private config; private circuitBreakerState; private activeConnections; private activeSessions; private connectionQueue; private globalConnectionState; private isShuttingDown; private failureCount; private lastFailureTime; private successCount; private appStateSubscription?; private appStateHandlerAdded; constructor(stateManager: StateManager, networkService: NetworkService, audioService: AudioService, storageService: StorageService, config?: Partial<SpeechConnectionConfig>); /** * Start speech synthesis and return session ID */ startSynthesis(ssml: string, // Changed from text to ssml options: SpeechOptions & { clientSessionId: string; connectionId: string; }): Promise<string>; /** * Stop speech synthesis for a specific session */ stopSynthesis(sessionId: string): Promise<void>; /** * Pause speech synthesis for a specific session */ pauseSynthesis(sessionId: string): Promise<void>; /** * Resume speech synthesis for a specific session */ resumeSynthesis(sessionId: string): Promise<void>; /** * Get connection pool status */ getConnectionPoolStatus(): { activeConnections: number; maxConnections: number; availableConnections: number; circuitBreakerState: string; }; /** * Shutdown connection manager and clean up all resources */ shutdown(): Promise<void>; /** * Stop all active connections and clear queue */ stopAllConnections(): Promise<void>; /** * Get connection manager status */ getStatus(): { activeConnections: number; queuedConnections: number; circuitBreakerState: CircuitBreakerState; failureCount: number; }; /** * Create and manage a complete connection lifecycle */ private createAndManageConnection; /** * Setup audio streaming coordination between services */ private setupAudioStreamingCoordination; /** * Setup audio data processing pipeline */ private setupAudioDataPipeline; /** * Establish WebSocket connection via Network Service */ private establishNetworkConnection; /** * Terminate connection and cleanup */ private terminateConnection; /** * Cleanup connection resources */ private cleanupConnection; /** * Handle incoming audio data from Network Service * Coordinates data flow between Network Service, Storage Service, and Audio Service */ private handleAudioData; /** * Store audio data (new helper method) */ private storeAudioData; /** * Stream audio data to Audio Service */ private streamAudioToService; /** * Handle boundary events from Network Service */ private handleBoundaryEvent; /** * Handle connection errors with recovery logic */ private handleConnectionError; /** * Determine if connection should be retried based on error type */ private shouldRetryConnection; /** * Retry connection with exponential backoff */ private retryConnection; /** * Check if circuit breaker allows new connections */ private isCircuitClosed; /** * Record successful connection */ private recordSuccess; /** * Record connection failure */ private recordFailure; /** * Process queued connections when space becomes available */ private processConnectionQueue; /** * Update global connection state based on individual connection states */ private updateGlobalConnectionState; /** * Setup event handlers for service coordination */ private setupEventHandlers; /** * Create SpeechError object */ private createSpeechError; /** * Convert Uint8Array to base64 string */ private uint8ArrayToBase64; } export {}; //# sourceMappingURL=connectionManager.d.ts.map