-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
244 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 146 additions & 0 deletions
146
docusaurus/docs/Android/03-guides/05-noise-cancellation.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
--- | ||
title: Noise Cancellation | ||
description: How to implement noise cancellation in Stream Video Android SDK | ||
--- | ||
|
||
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 SDK to your project | ||
|
||
To add the Stream Video Noise Cancellation SDK, open your app's `build.gradle.kts` file and add the following dependency: | ||
```kotlin | ||
dependencies { | ||
implementation(libs.stream.video.android.noise.cancellation) | ||
} | ||
``` | ||
|
||
Make sure you have the correct version specified in your `libs.versions.toml` file: | ||
|
||
```toml | ||
[versions] | ||
streamNoiseCancellation = "1.0.1" | ||
|
||
[libraries] | ||
stream-video-android-noise-cancellation = { module = "io.getstream:stream-video-android-noise-cancellation", version.ref = "streamNoiseCancellation" } | ||
``` | ||
|
||
## 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. | ||
```kotlin | ||
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: | ||
|
||
```kotlin | ||
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 | ||
|
||
```kotlin | ||
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. | ||
|
||
:::info | ||
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: | ||
|
||
```kotlin | ||
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 | ||
|
||
````kotlin | ||
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 | ||
|
||
````kotlin | ||
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. | ||
|
||
:::note | ||
The requirements for `AutoOn` to work properly are: | ||
|
||
1. A `NoiseCancellation` instance provided when you initialize StreamVideo: | ||
```kotlin | ||
val noiseCancellation = NoiseCancellation(context) | ||
val streamVideo = StreamVideoBuilder( | ||
// ... other parameters | ||
audioProcessing = noiseCancellation | ||
).build() | ||
``` | ||
2. 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: | ||
|
||
```kotlin | ||
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. | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/Users/kanat/.nvm/versions/node/v20.10.0/bin/../lib/node_modules/stream-chat-docusaurus-cli/shared |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...roid-core/src/main/kotlin/io/getstream/video/android/core/utils/NoiseCancellationUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (c) 2014-2024 Stream.io Inc. All rights reserved. | ||
* | ||
* Licensed under the Stream License; | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://github.com/GetStream/stream-video-android/blob/main/LICENSE | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.getstream.video.android.core.utils | ||
|
||
import org.openapitools.client.models.NoiseCancellationSettings | ||
|
||
/** | ||
* Returns true if the noise cancellation mode is "auto-on". | ||
*/ | ||
val NoiseCancellationSettings.isAutoOn get() = mode == NoiseCancellationSettings.Mode.AutoOn | ||
|
||
/** | ||
* Returns true if the noise cancellation mode is "available". | ||
*/ | ||
val NoiseCancellationSettings.isAvailable get() = mode == NoiseCancellationSettings.Mode.Available | ||
|
||
/** | ||
* Returns true if the noise cancellation mode is "disabled". | ||
*/ | ||
val NoiseCancellationSettings.isDisabled get() = mode == NoiseCancellationSettings.Mode.Disabled | ||
|
||
/** | ||
* Returns true if the noise cancellation mode is "auto-on" or "available". | ||
*/ | ||
val NoiseCancellationSettings.isEnabled get() = when (mode) { | ||
NoiseCancellationSettings.Mode.Available, | ||
NoiseCancellationSettings.Mode.AutoOn, | ||
-> true | ||
else -> false | ||
} |