Custom Audio Sources - Flutter
For a high-quality streaming experience, fine-tuning audio tracks becomes essential—especially when delivering content to a broader live audience.
To enhance your live audio pipeline, we've introduced the capability to provide a custom audio track for a host's stream both before and during a live session.
Custom Audio Track
This feature allows you to integrate advanced audio layers like background noise suppression, echo cancellation, and more—so your stream sounds polished and professional to every viewer.
How to Create a Custom Audio Track ?
- You can create a Audio Track using
createMicrophoneAudioTrack()method ofVideoSDKclass. - This method can be used to create audio track using different encoding parameters and noise cancellation configuration.
- This method does not ask for microphone permission, so call
VideoSDK.requestPermissions()before you create the track. - If the track cannot be created, the method throws a
VideoSDKError, for example3018without microphone permission,3022when there is no microphone, or3024when the microphone is in use. - The microphone opens when the track is created. If you do not use the track, call
stop()on it to close the microphone.
Example
// The SDK does not ask for microphone permission.
final permissions = await VideoSDK.requestPermissions(Permissions.AUDIO);
if (permissions['audio'] != true) return;
try {
CustomStreamTrack audioTrack = await VideoSDK.createMicrophoneAudioTrack(
encoderConfig: CustomMicrophoneTrackConfig.HIGH_QUALITY);
} on VideoSDKError catch (error) {
log("Could not create the track: ${error.code} ${error.name}");
}
Here are different configurations for customizing audio tracks based on specific use cases:
SPEECH_STANDARD: This config is optimised for normal voice communication.HIGH_QUALITY: This config is used for obtaining RAW audio, allowing you to apply yournoiseConfig.MUSIC_STANDARD: This config is optimised for communication scenarios, where the sharing of musical elements, such as songs or instrumental sounds, is crucial.
noiseConfig takes a NoiseConfig with the fields noiseSuppression, echoCancellation, autoGainControl and highPassFilter. If you pass noiseConfig, every field you leave out is turned on, except highPassFilter, which stays off. Pass no noiseConfig to use the values of the encoderConfig profile.
CustomStreamTrack audioTrack = await VideoSDK.createMicrophoneAudioTrack(
encoderConfig: CustomMicrophoneTrackConfig.HIGH_QUALITY,
noiseConfig: const NoiseConfig(noiseSuppression: true, echoCancellation: true),
);
How to Setup Custom Audio Track ?
You can plug in your custom audio track either before going live or dynamically while the session is ongoing.
1. Setup during live stream initialization
If you are passing micEnabled: true in the createRoom and want to use custom tracks from start of the livestream, you can pass custom track in the createRoom as shown below.
CustomStreamTrack? audioTrack;
try {
audioTrack = await VideoSDK.createMicrophoneAudioTrack(
encoderConfig: CustomMicrophoneTrackConfig.HIGH_QUALITY);
} on VideoSDKError catch (error) {
log("Could not create the track: ${error.code} ${error.name}");
}
Room room = VideoSDK.createRoom(
roomId: widget.livestreamId,
token: widget.token,
participantName: widget.participantName,
micEnabled: widget.micEnabled,
camEnabled: widget.camEnabled,
maxResolution: MaxResolution.HD,
defaultCamera: FacingMode.FRONT,
multiStream: false,
// Pass the custom track here
customMicrophoneTrack: audioTrack, // custom audio track :: optional
);
2. Setup dynamically using methods
In order to switch tracks during the livestream, you have to pass the CustomStreamTrack in the room.unmuteMic() method.
Call muteMic() before you create a new track. While the mic is on, unmuteMic() with a track throws 3054 and releases the track.
try {
// The mic must be off before you pass a new track
if (room.isMicEnabled) await room.muteMic();
CustomStreamTrack audioTrack = await VideoSDK.createMicrophoneAudioTrack(
encoderConfig: CustomMicrophoneTrackConfig.HIGH_QUALITY);
await room.unmuteMic(audioTrack);
} on VideoSDKError catch (error) {
log("Could not unmute with the custom track: ${error.code} ${error.name}");
}
API Reference
The API references for all the methods and events utilized in this guide are provided below.
Got a Question? Ask us on discord

