Audio element. For advanced use cases, you can opt in to receive the raw MediaStream via the captureAudio event by setting captureAudio: true in the client configuration. The SDK also notifies when playback stops via the audioEnded event.
Default Behavior
By default, the SDK:- Creates an internal
Audioelement withautoplayenabled and volume set to1.0. - When a remote audio stream arrives via the WebRTC peer connection, the SDK attaches it to the
Audioelement and starts playback automatically. - When the call ends, the SDK stops playback, releases the stream, and emits the
audioEndedevent.
Browser autoplay policies may block audio playback if the call is not initiated by a user gesture, for example, a button click. Always start calls in response to user interaction.
Accessing the Raw Audio Stream
To receive the rawMediaStream for advanced audio processing, enable the captureAudio option and subscribe to the event:
The
captureAudio event fires in addition to the SDKโs automatic audio playback. You donโt need to handle playback yourself โ the SDK still plays audio through its internal Audio element.Volume Control
Use the Web Audio API to add programmatic volume control on top of the captured stream:The example above does not connect to
audioContext.destination because the SDK already plays audio through its internal Audio element. If you connect to audioContext.destination, you will hear audio twice. If you want to fully replace the SDKโs audio playback with your own Web Audio pipeline, mute the internal audio element first.Audio Visualization
Create a real-time audio visualizer using theAnalyserNode:
When using the
captureAudio stream for visualization, avoid connecting it to audioContext.destination since the SDK already handles playback. Doing so would cause the audio to play twice.Audio Recording
Record the remote audio stream using theMediaRecorder API:
More Information
- audioEnded โ event reference
- Getting Started โ basic setup
- Troubleshooting โ No Audio โ resolve audio issues