dependencies {
implementation("io.getstream:stream-video-android-noise-cancellation:1.0.1")
}
Noise Cancellation
Noise Cancellation capabilities of our Android Video SDK can be enabled by installing our NoiseCancellation package. Under the hood, this package uses the technology developed by krisp.ai.
Installation
Add the library to your project
To add the Stream Video Noise Cancellation library, open your app’s build.gradle.kts
file and add the following dependency:
Make sure to replace 1.0.1
with the latest version of the noise cancellation library.
Integration
Our Android SDK provides a utility component that makes the integration smoother. You’ll need to create a NoiseCancellation
instance and pass it to the StreamVideoBuilder
when initializing the SDK.
import io.getstream.video.android.core.StreamVideoBuilder
import io.getstream.video.android.noise.cancellation.NoiseCancellation
// ...
val noiseCancellation = NoiseCancellation(context)
val streamVideo = StreamVideoBuilder(
context = context,
apiKey = apiKey,
user = user,
token = token,
// ... other configuration options
audioProcessing = noiseCancellation
).build()
// ...
Feature availability
The availability of noise cancellation is controlled by the call settings. You can check the availability and status of noise cancellation through the Call
object:
val call: Call = // ... obtain your call object
val noiseCancellationMode = call.state.settings.value?.audio?.noiseCancellation?.mode
There are three possible modes for noise cancellation:
Available
if (noiseCancellationMode == NoiseCancellationSettings.Mode.Available) {
// The feature is enabled on the dashboard and available for the call
// You can present noise cancellation toggle UI in your application
}
The feature has been enabled on the dashboard and it’s available for the call. In this case, you are free to present any noise cancellation toggle UI in your application.
Even though the feature may be enabled for your call, you should note that NoiseCancellation is a very performance-heavy process. For that reason, it’s recommended to only allow the feature on devices with sufficient processing power.
While there isn’t a definitive way to determine if a device can handle noise cancellation efficiently, you can use the following method to check for advanced audio processing capabilities:
import android.content.pm.PackageManager
val context: Context = // ... obtain your context
val hasAdvancedAudioProcessing = context.packageManager.hasSystemFeature(PackageManager.FEATURE_AUDIO_PRO)
This can serve as an indicator of whether the device might be capable of handling noise cancellation efficiently. Devices with this feature are more likely to have the necessary hardware to support performance-intensive audio processing tasks.
For the most accurate assessment of noise cancellation performance, you may want to consider implementing your own benchmarking or testing mechanism on different device models.
For more info, you can refer to our UI docs about Noise Cancellation.
Disabled
if (noiseCancellationMode == NoiseCancellationSettings.Mode.Disabled) {
// The feature is not enabled on the dashboard or not available for the call
// You should hide any noise cancellation toggle UI in your application
}
The feature hasn’t been enabled on the dashboard or the feature isn’t available for the call. In this case, you should hide any noise cancellation toggle UI in your application.
AutoOn
if (noiseCancellationMode == NoiseCancellationSettings.Mode.AutoOn) {
// Noise cancellation is automatically enabled
}
Similar to Available
with the difference that if possible, the StreamVideo SDK will enable the filter automatically, when the user joins the call.
The requirements for AutoOn
to work properly are:
- A
NoiseCancellation
instance provided when you initialize StreamVideo:val noiseCancellation = NoiseCancellation(context) val streamVideo = StreamVideoBuilder( // ... other parameters audioProcessing = noiseCancellation ).build()
- Device has sufficient processing power (you can use the
FEATURE_AUDIO_PRO
check as an indicator)
Activate/Deactivate the filter
To toggle noise cancellation during a call, you can use the toggleAudioProcessing()
method on the StreamVideo
instance:
val streamVideo: StreamVideo = // ... obtain your StreamVideo instance
// Check if audio processing (noise cancellation) is enabled
val isAudioProcessingEnabled = streamVideo.isAudioProcessingEnabled()
// Toggle noise cancellation
val isEnabled = streamVideo.toggleAudioProcessing()
// Or using the setAudioProcessingEnabled method
streamVideo.setAudioProcessingEnabled(!isAudioProcessingEnabled)
Note that toggling noise cancellation affects all ongoing and future calls for the current StreamVideo
instance.