Custom Audio Track - Android
We have introduced the ability to pass a custom Audio track for the Audio of the participants. This feature can be used to add custom layers like background noise removal, echo cancellation, etc. on audio and send it to other participants.
Creating a Custom Audio Track
- You can create a Audio Track using
createAudioTrack()method ofVideoSDK. - This method can be used to create audio track using different encoding parameters and noise cancellation configuration.
Parameters
-
encoderConfig:
- type:
String - required:
true - default:
speech_standard - Allowed values :
speech_low_quality|speech_standard|music_standard|standard_stereo|high_quality|high_quality_stereo - It will be the encoder configuration you want to use for Audio Track.
- type:
-
noiseConfig
-
type:
JSONObject -
required:
true -
acousticEchoCancellation
- type:
boolean - required:
true - If
trueecho cancellation will turned on else it would be turned off.
- type:
-
autoGainControl
- type:
boolean - required:
true - If
trueauto gain will turned on else it would be turned off.
- type:
-
noiseSuppression
- type:
boolean - required:
true - If
truenoise suppression will turned on else it would be turned off.
- type:
-
-
context
- type:
Context - required:
true - Pass the Android Context for this parameter.
- type:
Returns
CustomStreamTrack
Example
- Kotlin
- Java
val noiseConfig = JSONObject()
try {
noiseConfig.put("acousticEchoCancellation", true)
noiseConfig.put("autoGainControl", true)
noiseConfig.put("noiseSuppression", true)
val audioCustomTrack: CustomStreamTrack = VideoSDK.createAudioTrack("high_quality", noiseConfig, this)
} catch (e: JSONException) {
e.printStackTrace()
}
JSONObject noiseConfig=new JSONObject();
try {
noiseConfig.put("acousticEchoCancellation",true);
noiseConfig.put("autoGainControl",true);
noiseConfig.put("noiseSuppression",true);
CustomStreamTrack audioCustomTrack=VideoSDK.createAudioTrack("high_quality", noiseConfig, this);
}catch (JSONException e) {
e.printStackTrace();
}
Using Custom Audio Track
Custom Track while initializing the meeting
If you are passing micEnabled: true in the initMeeting of VideoSDK and want to use custom tracks from start of the meeting, you can pass custom track in the initMeeting as shown below.
- Kotlin
- Java
override fun onCreate(savedInstanceState: Bundle?) {
//..
val customTracks: MutableMap<String, CustomStreamTrack> = HashMap()
val noiseConfig = JSONObject()
try {
noiseConfig.put("acousticEchoCancellation", true)
noiseConfig.put("autoGainControl", true)
noiseConfig.put("noiseSuppression", true)
} catch (e: JSONException) {
e.printStackTrace()
}
val audioCustomTrack: CustomStreamTrack = VideoSDK.createAudioTrack("high_quality", noiseConfig, this)
customTracks["mic"] = audioCustomTrack //Key must be "mic"
// create a new meeting instance
val meeting = VideoSDK.initMeeting(
this@MainActivity,meetingId,participantName,
//MicEnabled , If true, it will use the passed custom track to turn mic on
true,
//WebcamEnabled
true,
//multiStream
false,
//ParticipantId
null,
//Pass the custom tracks here
customTracks
)
}
@Override
protected void onCreate(Bundle savedInstanceState) {
//..
Map<String, CustomStreamTrack> customTracks = new HashMap<>();
JSONObject noiseConfig=new JSONObject();
try {
noiseConfig.put("acousticEchoCancellation",true);
noiseConfig.put("autoGainControl",true);
noiseConfig.put("noiseSuppression",true);
}catch (JSONException e) {
e.printStackTrace();
}
CustomStreamTrack audioCustomTrack = VideoSDK.createAudioTrack("high_quality", noiseConfig, this);
customTracks.put("mic", audioCustomTrack); //Key must be "mic"
// create a new meeting instance
Meeting meeting = VideoSDK.initMeeting(
MainActivity.this, meetingId, participantName,
//MicEnabled , If true, it will use the passed custom track to turn mic on
true,
//WebcamEnabled
true,
//multiStream
false,
//ParticipantId
null,
//Pass the custom tracks here
customTracks
);
}
Custom Track with unmuteMic()
In order to switch tracks during the meeting, you have to pass the CustomStreamTrack in the unmuteMic() method of Meeting.
You can also pass custom track in changeMic() method of Meeting.
Make sure to call muteMic() before you create a new track as it may lead to unexpected behavior.
- Kotlin
- Java
val noiseConfig = JSONObject()
try {
noiseConfig.put("acousticEchoCancellation", true)
noiseConfig.put("autoGainControl", true)
noiseConfig.put("noiseSuppression", true)
val audioCustomTrack: CustomStreamTrack = VideoSDK.createAudioTrack("high_quality", noiseConfig, this)
meeting!!.unmuteMic(audioCustomTrack)
//or
meeting!!.changeMic(AppRTCAudioManager.AudioDevice.BLUETOOTH, audioCustomTrack)
} catch (e: JSONException) {
e.printStackTrace()
}
JSONObject noiseConfig=new JSONObject();
try {
noiseConfig.put("acousticEchoCancellation",true);
noiseConfig.put("autoGainControl",true);
noiseConfig.put("noiseSuppression",true);
CustomStreamTrack audioCustomTrack = VideoSDK.createAudioTrack("high_quality", noiseConfig, this);
meeting.unmuteMic(audioCustomTrack);
//or
meeting.changeMic(AppRTCAudioManager.AudioDevice.BLUETOOTH,audioCustomTrack);
}catch (JSONException e) {
e.printStackTrace();
}
Got a Question? Ask us on discord

