UNPKG

expo-edge-speech

Version:

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

190 lines 5.36 kB
/** * Provides audio playback service using expo-av with integration for Network Service, * Storage Service, and Audio Utilities. Handles platform-specific configuration, * audio session management, and provides expo-speech compatible callbacks. */ import type { SpeechOptions, SpeechAudioConfig } from "../types"; import { StorageService } from "./storageService"; /** * Audio playback state enumeration */ export declare enum AudioPlaybackState { Idle = "idle", Loading = "loading", Playing = "playing", Paused = "paused", Stopped = "stopped", Error = "error", Completed = "completed" } /** * User action state enumeration for deterministic action tracking */ export declare enum UserActionState { Idle = "idle", PauseRequested = "pause-requested", ResumeRequested = "resume-requested", StopRequested = "stop-requested" } /** * Audio Service class providing audio playback functionality * integration for Edge TTS audio streaming, platform-specific configuration, * session management, and expo-speech compatible callbacks. */ export declare class AudioService { /** Current audio playback state */ private state; /** Current audio object from expo-av */ private sound; /** Current connection ID for storage coordination */ private connectionId; /** Audio service configuration */ private config; /** Storage service instance */ private storageService; /** Whether audio session has been initialized */ private audioSessionInitialized; /** Current audio URI for expo-av */ private audioURI; /** Current temporary audio file path */ private tempAudioFilePath; private onStartCallback; private onDoneCallback; private onStoppedCallback; private onPauseCallback; private onResumeCallback; private onErrorCallback; private onPlaybackStateChangeCallback; private userActionState; private lastValidPosition; constructor(storageService: StorageService, config?: Partial<SpeechAudioConfig>); /** * Initialize audio service (required by StateManager) */ initialize(): Promise<void>; /** * Cleanup audio service and release resources (required by StateManager) */ cleanup(): Promise<void>; /** * Register callback for playback state changes (required by StateManager) */ onPlaybackStateChange(callback: (state: AudioPlaybackState, context?: any) => void): void; /** * Play audio from Storage Service buffer using connection ID */ speak(options: SpeechOptions, connectionId: string): Promise<void>; /** * Play audio from streamed data stored in Storage Service */ playStreamedAudio(connectionId: string): Promise<void>; /** * Pause audio playback */ pause(): Promise<void>; /** * Resume audio playback */ resume(): Promise<void>; /** * Stop audio playback and cleanup */ stop(): Promise<void>; /** * Start progressive audio playback as chunks arrive (for streaming) */ startProgressivePlayback(connectionId: string): Promise<void>; /** * Finalize progressive playback after all chunks have been received */ finalizeProgressivePlayback(connectionId: string): Promise<void>; /** * Process audio buffer and validate format */ private processAudioBuffer; /** * Load audio using expo-av Sound API */ private loadAudio; /** * Start audio playback */ private playAudio; /** * Play audio from buffer data */ private playAudioFromBuffer; /** * Create temporary audio file from buffer */ private createTempAudioFile; /** * Unload current audio and free resources */ private unloadAudio; /** * Clean up temporary audio file immediately after audio resource release */ private cleanupTempAudioFile; /** * Initialize audio session for platform-specific configuration */ private initializeAudioSession; /** * Create loading options for expo-av */ private createLoadingOptions; /** * Handle playback status updates from expo-av */ private handlePlaybackStatusUpdate; /** * Set audio playback state */ private setState; /** * Enhanced interruption detection using audio status validation */ private isGenuineInterruption; /** * Schedule debounced interruption detection */ /** * Set callback handlers from speech options */ private setCallbacks; /** * Clear all callback handlers */ private clearCallbacks; /** * Create default configuration */ private createDefaultConfig; /** * Handle audio errors */ private handleError; /** * Get current playback state */ get currentState(): AudioPlaybackState; /** * Get current connection ID */ get currentConnectionId(): string | null; /** * Check if audio is currently playing */ get isPlaying(): boolean; /** * Check if audio is paused */ get isPaused(): boolean; /** * Check if audio is stopped */ get isStopped(): boolean; } export { AudioService as default }; //# sourceMappingURL=audioService.d.ts.map