/** * AudioFileLoader - Load and decode audio files in a Web Worker * * This class provides an easy-to-use API for loading audio files from URLs * or decoding raw audio data (ArrayBuffer) in a Web Worker. This keeps the * main thread responsive during file loading and decoding operations. * * @example * ```typescript * const loader = new AudioFileLoader(); * * const audioBuffer = await loader.load('audio.mp3', { * onProgress: (progress) => console.log(`${progress * 100}%`) * }); * * loader.dispose(); * ``` */ import type { AudioLoadingOptions } from './types'; /** * Configuration options for AudioFileLoader */ export interface AudioFileLoaderConfig { /** * Path or URL to the worker script * @default '/audio-processor.worker.bundle.js' */ workerPath?: string; /** * Maximum time to wait for operations (in milliseconds) * @default 60000 (1 minute) */ timeout?: number; } /** * AudioFileLoader class for loading audio in Web Workers */ export declare class AudioFileLoader { private worker; private pendingRequests; private config; private isReady; private readyPromise; /** * Create a new AudioFileLoader instance * * @param config - Configuration options * * @example * ```typescript * const loader = new AudioFileLoader({ * workerPath: '/workers/audio-processor.worker.bundle.js', * timeout: 120000 // 2 minutes * }); * ``` */ constructor(config?: AudioFileLoaderConfig); /** * Initialize the worker */ private initialize; /** * Handle messages from the worker */ private handleWorkerMessage; /** * Send a request to the worker and wait for response */ private sendRequest; /** * Load and decode an audio file from a URL * * @param url - URL of the audio file to load * @param options - Loading options (progress callback) * @returns Promise that resolves to the decoded AudioBuffer * * @throws {Error} If loading or decoding fails * * @example * ```typescript * const audioBuffer = await loader.load('https://example.com/audio.mp3', { * onProgress: (progress) => { * console.log(`Loading: ${Math.round(progress * 100)}%`); * } * }); * ``` */ load(url: string, options?: AudioLoadingOptions): Promise; /** * Load audio file with a provided AudioContext for deserialization * * This is the preferred method as it uses the user's AudioContext * instead of creating a temporary one. * * @param url - URL of the audio file to load * @param audioContext - AudioContext for creating the result buffer * @param options - Loading options * @returns Promise that resolves to the decoded AudioBuffer * * @example * ```typescript * const audioContext = new AudioContext(); * const audioBuffer = await loader.loadWithContext( * 'audio.mp3', * audioContext, * { onProgress: (p) => console.log(`${p * 100}%`) } * ); * ``` */ loadWithContext(url: string, audioContext: BaseAudioContext, options?: AudioLoadingOptions): Promise; /** * Decode raw audio data (ArrayBuffer) to AudioBuffer * * @param audioData - Raw audio data as ArrayBuffer * @param options - Loading options * @returns Promise that resolves to the decoded AudioBuffer * * @throws {Error} If decoding fails * * @example * ```typescript * const response = await fetch('audio.mp3'); * const arrayBuffer = await response.arrayBuffer(); * * const audioBuffer = await loader.decode(arrayBuffer, { * onProgress: (p) => console.log(`${p * 100}%`) * }); * ``` */ decode(audioData: ArrayBuffer, options?: AudioLoadingOptions): Promise; /** * Decode audio data with a provided AudioContext for deserialization * * @param audioData - Raw audio data as ArrayBuffer * @param audioContext - AudioContext for creating the result buffer * @param options - Loading options * @returns Promise that resolves to the decoded AudioBuffer * * @example * ```typescript * const audioContext = new AudioContext(); * const arrayBuffer = await fetch('audio.mp3').then(r => r.arrayBuffer()); * const audioBuffer = await loader.decodeWithContext( * arrayBuffer, * audioContext * ); * ``` */ decodeWithContext(audioData: ArrayBuffer, audioContext: BaseAudioContext, options?: AudioLoadingOptions): Promise; /** * Check if the loader is ready to accept requests * * @returns True if the worker is initialized and ready */ get ready(): boolean; /** * Wait for the loader to be ready * * @returns Promise that resolves when the loader is ready */ waitForReady(): Promise; /** * Dispose and clean up resources * * Call this when you're done using the loader. * After calling dispose(), this instance should not be used again. * * @example * ```typescript * loader.dispose(); * loader = null; * ``` */ dispose(): void; } //# sourceMappingURL=AudioFileLoader.d.ts.map