Audio gain processor using the Web Audio API. Provides volume control for audio streams before they are sent to WebRTC.
Methods
# inner GainProcessor(options) → {GainProcessorResult}
Creates an audio gain processor for volume control.
This function creates a Web Audio processing chain that allows real-time volume adjustment of an audio stream. The processed stream can be used with WebRTC while maintaining volume control.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
options |
Object
|
Configuration options |
||
audioContext |
AudioContext
|
The Web Audio AudioContext |
||
stream |
MediaStream
|
The input audio stream to process |
||
gainValue |
number
|
<optional> |
1 | Initial gain value (0 = muted, 1 = normal, >1 = amplified) |
Object containing gainNode, inputNode, and producerTrack
GainProcessorResult
Example
// Create audio context and get microphone stream
const audioContext = new AudioContext();
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
// Create gain processor
const { gainNode, producerTrack } = GainProcessor({
audioContext,
stream,
gainValue: 0.8 // Start at 80% volume
});
// Use producerTrack for WebRTC
const producer = await sendTransport.produce({ track: producerTrack });
// Adjust volume dynamically
gainNode.gain.value = 0.5; // Set to 50% volume
gainNode.gain.value = 0; // Mute
gainNode.gain.value = 1.5; // Amplify to 150%
Type Definitions
Object
# GainProcessorResult
Result object returned by GainProcessor
Properties:
| Name | Type | Description |
|---|---|---|
gainNode |
GainNode
|
The Web Audio GainNode for adjusting volume (use gainNode.gain.value) |
inputNode |
MediaStreamAudioSourceNode
|
The source node connected to the gain |
producerTrack |
MediaStreamTrack
|
The processed audio track to use for WebRTC production |