import { Channel } from "./channel"; import { SoundToken } from "./soundToken"; import { SoundOptions, ChannelOptions, PlayOptions, CachedAudio, IAudioProvider } from "./types"; /** * Sound is the main class that manages the audio context, channels, and audio playback. * It uses a master channel internally to manage volume and sub-channels. */ export declare class Sound implements IAudioProvider { private readonly audioContext; private readonly options; private readonly masterChannel; private readonly registeredChannels; private readonly audioCache; private isReady; private readyPromise; private destroyed; private unlockHandler; constructor(options?: Partial); /** * Wait for the audio context to be ready. */ onceReady(): Promise; /** * Initialize the audio context and wait for user interaction if needed. */ private initialize; /** * Wait for user interaction to unlock the audio context. */ private waitForUnlock; /** * Clear unlock event listeners if they have been registered. */ private clearUnlockHandler; /** * Ensure the sound instance is not destroyed. */ private ensureNotDestroyed; /** * Ensure the audio context is ready (unlocked). * Throws if not yet ready. */ private ensureReady; /** * Get the audio context. */ getAudioContext(): AudioContext; /** * Create a new sound token for playback. */ createToken(source: string | CachedAudio, options: PlayOptions | undefined, outputNode: GainNode): Promise; /** * Resolve the load mode based on the specified mode and file size. * For "auto" mode, sends a HEAD request to determine file size. * Files < 10MB use "full" mode, otherwise "stream" mode. */ private resolveLoadMode; /** * Create a streaming audio source using HTMLAudioElement. */ private createStreamSource; /** * Check if we can create more channels. * Note: maxChannels includes the master channel, so we add 1 to the registered count. */ checkChannelLimit(): void; /** * Register a channel with the sound instance. */ registerChannel(channel: Channel): void; /** * Unregister a channel from the sound instance. */ unregisterChannel(channel: Channel): void; /** * Set the master volume of all audio. * @param volume - The volume value between 0 and 1. */ setVolume(volume: number): this; /** * Get the master volume. */ getVolume(): number; /** * Mute all audio. */ mute(): this; mute(muted: boolean): this; /** * Unmute all audio. */ unmute(): this; /** * Check if audio is muted. */ isMuted(): boolean; /** * Create a new channel. * @param name - The name of the channel. * @param options - Optional channel options. */ createChannel(name: string, options?: ChannelOptions): Channel; /** * Get a channel by name. * @param name - The name of the channel. */ getChannel(name: string): Channel | null; /** * Get all direct child channels of the master channel. */ getChannels(): Channel[]; /** * Load an audio file and cache it. * @param path - The path to the audio file. */ load(path: string): Promise; /** * Play audio directly without using a channel. * The volume will only be affected by the master volume. * @param source - The path to the audio file or a CachedAudio instance. * @param options - Optional play options. */ play(source: string | CachedAudio, options?: PlayOptions): Promise; /** * Get all currently playing tokens. */ getTokens(): SoundToken[]; /** * Destroy the sound instance and release all resources. */ destroy(): void; /** * Check if the sound instance has been destroyed. */ isDestroyed(): boolean; }