Skip to main content
Version: Next

Optimize Audio Track - Flutter

While optimizing for the best listening experience, it is necessary to fine-tune the audio track that is being used during the calls.

For the best fine-tuning experience, we have introduced the ability to pass a custom audio track for the participant's media before and during the meeting.

Custom Audio Track

This feature can be used to add custom layers like background noise removal, echo cancellation, etc. on audio and send it to other participants.

How to Create Custom Audio Track ?

  • You can create a Audio Track using createMicrophoneAudioTrack() method of VideoSDK.

  • This method can be used to create audio track using different encoding parameters and noise cancellation configuration.

Example

import 'package:videosdk/videosdk.dart';

CustomTrack customTrack = await VideoSDK.createMicrophoneAudioTrack({
// It will be the id of the mic from which the voice should be captured.
microphoneId : 'mic-id' // OPTIONAL

// This will accept the voice profile you want to capture.
encoderConfig: CustomAudioTrackConfig.speech_standard, // `high_quality` | `music_standard`, Default : `speech_standard`

noiseConfig: {
// It is used to improve the quality of audio by removing background noise
// that can interfere with the clarity of speech.
"noiseSuppression": true,

// It is used to remove unwanted echoes from voice.
"echoCancellation": true,

// It is used to maintain a consistent level of loudness or amplitude in a voice.
"autoGainControl": true,
},
});
  • speech_standard : This config is optimised for normal voice communication.

  • high_quality : This config is used for getting RAW audio, where you can apply your noiseConfig.

  • music_standard : This config is optimised for communication, where sharing of musical notes such as songs or instrumental sounds, is important.

How to Setup Custom Audio Track ?

The custom track can be set up both before and after the initialization of the meeting.

  1. Setting up a Custom Track during the initialization of a meeting
  2. Setting up a Custom Track with methods
1. Setting up a Custom Track during the initialization of a meeting

If you are passing micEnabled: true in the createRoom and want to use custom tracks from start of the meeting, you can pass custom track in the customMicrophoneAudioTrack as shown below.

caution

Custom Track will not apply on micEnabled: false configuration.

Example
import 'package:flutter/material.dart';
import 'package:videosdk/videosdk.dart';

class MeetingScreen extends StatefulWidget {
final String meetingId;
final String token;

const MeetingScreen(
{super.key, required this.meetingId, required this.token});

@override
State<MeetingScreen> createState() => _MeetingScreenState();
}

class _MeetingScreenState extends State<MeetingScreen> {
late Room _room;

@override
void initState() {
initRoom();
super.initState();
}

void initRoom() {
//Creating Custom Audio Track
CustomTrack audioTrack = await VideoSDK.createMicrophoneAudioTrack(
encoderConfig: CustomAudioTrackConfig.speech_standard);

//Creating a new Room with custom audio track
// create room
_room = VideoSDK.createRoom(
roomId: widget.meetingId,
token: widget.token,
displayName: "John Doe",
micEnabled: true,
camEnabled: true,
defaultCameraIndex:
1, // Index of MediaDevices will be used to set default camera
customMicrophoneAudioTrack: audioTrack, // custom audio track :: optional
);
}

@override
Widget build(BuildContext context) {
return YourMeetingWidget();
}
}

2. Setting up a Custom Track with methods

In order to switch tracks during the meeting, you have to pass the CustomTrack in the unmuteMic() method of Room.

tip

Make sure to call muteMic() before you create a new track as it may lead to unexpected behavior.

Example
import 'package:flutter/material.dart';
import 'package:videosdk/videosdk.dart';

class MeetingScreen extends StatefulWidget {
final String meetingId;
final String token;

const MeetingScreen(
{super.key, required this.meetingId, required this.token});

@override
State<MeetingScreen> createState() => _MeetingScreenState();
}

class _MeetingScreenState extends State<MeetingScreen> {
late Room _room;

@override
void initState() {
initRoom();
super.initState();
}

void initRoom() {
...
}

@override
Widget build(BuildContext context) {
return Column(
childern: [
ElevatedButton(
onPressed: ()async{
//Creating Custom Audio Track
CustomTrack audioTrack = await VideoSDK.createMicrophoneAudioTrack(
encoderConfig: CustomAudioTrackConfig.speech_standard);

_room.unmuteMic(audioTrack);
},
child: const Text("Unmute with Custom Track"),
),
]
)
}
}

API Reference

The API references for all the methods and events utilised in this guide are provided below.

Got a Question? Ask us on discord