Audio sources are used to add audio samples to output audio tracks. All audio sources extend the baseDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Vanilagy/mediabunny/llms.txt
Use this file to discover all available pages before exploring further.
AudioSource class.
AudioBufferSource
ConvertsAudioBuffer instances (from the Web Audio API) to audio samples, encodes them, and adds them to the output track.
Constructor
Configuration object that controls audio encoding.
Methods
add
Converts an AudioBuffer to audio samples, encodes them, and adds them to the output. The first AudioBuffer starts at timestamp 0, with subsequent buffers following the cumulative duration.The AudioBuffer to convert and encode.
Resolves when the output is ready to receive more samples. Await this to respect backpressure.
close
Closes the source, preventing future samples and signaling no more data will be added to this track.Calling
close() is optional but recommended after adding the last sample for improved performance and reduced memory usage.AudioSampleSource
Adds raw, unencoded audio samples to an output audio track with automatic encoding.Constructor
Configuration object that controls audio encoding. See AudioBufferSource for detailed properties.
Methods
add
Encodes an audio sample and adds it to the output.The audio sample to encode and add.
Resolves when the output is ready to receive more samples. Await this to respect backpressure.
close
Closes the source. See AudioBufferSource.close() for details.EncodedAudioPacketSource
Directly pipes pre-encoded audio packets into the output file without additional encoding.Constructor
The codec used to encode the packets. Examples:
'aac', 'opus', 'mp3', 'vorbis', 'flac'.Methods
add
Adds an encoded packet to the output audio track. Packets must be added in decode order.The encoded audio packet to add. Cannot be a metadata-only packet.
Additional encoder metadata. You should pass this for the first call, including a valid decoder config.
Resolves when the output is ready to receive more samples. Await this to respect backpressure.
close
Closes the source. See AudioBufferSource.close() for details.MediaStreamAudioTrackSource
Encodes data from a liveMediaStreamAudioTrack (e.g., microphone or media element) and pipes it to the output. Audio is automatically captured once the connected Output is started.
Constructor
The audio MediaStreamTrack to capture audio from.
Configuration object that controls audio encoding. See AudioBufferSource for detailed properties.
Properties
A promise that rejects upon any error within this source. This promise never resolves. You should handle this promise to catch internal errors.
Whether this source is currently paused as a result of calling
pause().Methods
pause
Pauses the capture of audio data. Audio data emitted by the media stream is ignored while paused. This does not close the underlying track.resume
Resumes the capture of audio data after being paused.close
Stops capturing and closes the source. See AudioBufferSource.close() for details.Make sure to handle the
errorPromise field so that internal errors are properly surfaced.If
MediaStreamTrackProcessor is not supported in the main thread, Mediabunny will attempt to use it in a Web Worker. If neither is available, an AudioContext fallback is used with the deprecated (but still functional) ScriptProcessorNode.