Overview
AudioMixer uses the Web Audio API to combine multiple MediaStreams with audio tracks into a single mixed MediaStream. This is useful for scenarios like mixing multiple audio sources for recording or combining audio tracks for processing.Constructor
Create a new AudioMixer instance.start() to begin mixing.
Methods
addMediaStream
Adds an audio MediaStream to be mixed. If the stream doesn’t contain audio tracks, a warning is logged but the stream is still added.MediaStream
required
The MediaStream to be mixed. Should contain at least one audio track.
start
Initializes the Web Audio graph and starts mixing all added MediaStreams. Returns the mixed output stream.MediaStream containing the mixed audio, or null if no MediaStreams were added.
How it works:
- Creates an AudioContext
- Creates a MediaStreamAudioDestinationNode for output
- Creates MediaStreamAudioSourceNode for each input stream
- Connects all source nodes to the destination node
- Returns the mixed MediaStream
If
start() is called multiple times, it returns the existing mixed stream without recreating the audio graph.reset
Disconnects all audio nodes and clears all references. Call this to clean up when done with the mixer.- Disconnects all MediaStreamAudioSourceNode instances
- Clears the list of streams to mix
- Cleans up the AudioContext and destination node
- Resets the started state
Complete Example
Basic Audio Mixing
Mixing Remote Participant Audio
Browser Support
AudioMixer uses the Web Audio API, which is supported in all modern browsers:- Chrome/Edge 14+
- Firefox 25+
- Safari 6+
- Opera 15+
AudioContext is automatically created with default sample rate. The mixer handles all audio graph setup internally.
Common Use Cases
- Recording multiple audio sources - Mix microphone + system audio for screen recordings
- Conference audio mixing - Combine all participant audio for processing
- Audio monitoring - Mix multiple inputs for real-time monitoring
- Custom audio processing - Pre-mix audio before applying effects
Important Notes
The mixer performs a simple mixing operation by connecting all sources to a single destination. Audio levels are not automatically adjusted - you may want to apply gain control for better balance.