UNPKG

ez-web-audio

Version:

Making the Web Audio API super EZ since 2024.

76 lines 2.69 kB
import { TimeObject } from './utils/create-time-object'; import { SoundController } from './controllers/sound-controller'; import { BaseSound } from './base-sound'; /** * One-shot audio playback from an AudioBuffer. * * Sound is the core class for playing audio files. Each `.play()` call creates * a new AudioBufferSourceNode, allowing simultaneous overlapping playback. * Use {@link Track} instead if you need pause/resume/seek functionality. * * Sound extends {@link BaseSound} and inherits all audio parameter controls * (gain, pan) and the fluent API for scheduling parameter changes. * * @example * ```typescript * import { createSound } from 'ez-web-audio' * * const sound = await createSound('click.mp3') * sound.play() * * // Adjust volume before playing * sound.changeGainTo(0.5) * sound.play() * * // Schedule a fade-in * sound.onPlaySet('gain').to(0).endingAt(1, 'exponential') * sound.play() * ``` */ export declare class Sound extends BaseSound { private audioBuffer; /** The underlying AudioBufferSourceNode that plays the audio. */ audioSourceNode: AudioBufferSourceNode; /** Controller for managing gain, pan, and other audio parameters. */ protected controller: SoundController; /** * Create a Sound instance. * * Note: Use {@link createSound} factory function instead of calling this directly. * * @param audioContext - The AudioContext to use for audio operations * @param audioBuffer - The decoded audio data to play * @param opts - Optional configuration (name, setTimeout override) */ constructor(audioContext: AudioContext, audioBuffer: AudioBuffer, opts?: any); /** * Set up a new AudioBufferSourceNode for playback. * Called automatically before each play() - creates fresh source nodes * since AudioBufferSourceNode is single-use. * @protected */ protected setup(): void; /** * Wire audio source through connections to the effect chain. * @protected */ protected wireConnections(): void; /** * Get the duration of the audio buffer. * * Returns a TimeObject with the duration in multiple formats: * - `raw`: Duration in seconds * - `string`: Formatted as 'MM:SS' * - `pojo`: Object with `minutes` and `seconds` properties * * @example * ```typescript * const sound = await createSound('song.mp3') * console.log(sound.duration.raw) // 180.5 * console.log(sound.duration.string) // '3:00' * console.log(sound.duration.pojo) // { minutes: 3, seconds: 0 } * ``` */ get duration(): TimeObject; } //# sourceMappingURL=sound.d.ts.map