AudioSource class.
AudioBufferSource
ConvertsAudioBuffer instances (from the Web Audio API) to audio samples, encodes them, and adds them to the output track.
Constructor
AudioEncodingConfig
required
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.AudioBuffer
required
The AudioBuffer to convert and encode.
Promise<void>
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
AudioEncodingConfig
required
Configuration object that controls audio encoding. See AudioBufferSource for detailed properties.
Methods
add
Encodes an audio sample and adds it to the output.AudioSample
required
The audio sample to encode and add.
Promise<void>
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
AudioCodec
required
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.EncodedPacket
required
The encoded audio packet to add. Cannot be a metadata-only packet.
EncodedAudioChunkMetadata
Additional encoder metadata. You should pass this for the first call, including a valid decoder config.
Promise<void>
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
MediaStreamAudioTrack
required
The audio MediaStreamTrack to capture audio from.
AudioEncodingConfig
required
Configuration object that controls audio encoding. See AudioBufferSource for detailed properties.
Properties
Promise<never>
A promise that rejects upon any error within this source. This promise never resolves. You should handle this promise to catch internal errors.
boolean
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.