Skip to content

Commit 0ffe0d9

Browse files
authored
Add documentation for Voice Focus and Web Audio best practice (#1004)
1 parent fbde57c commit 0ffe0d9

File tree

4 files changed

+92
-11
lines changed

4 files changed

+92
-11
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### Added
1313

14+
- Added documentation for VoiceFocus and WebAudio best practice.
15+
1416
### Removed
1517

1618
### Changed

src/components/sdk/MeetingControls/docs/AudioInputVFControl.mdx

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,55 @@ If you want to apply Amazon Voice Focus feature, try this `AudioInputVFControl`.
1616

1717
You can use it in the [ControlBar component](/docs/ui-components-controlbar--page) to build the meeting controls bar.
1818

19+
## Prerequisites
20+
21+
Amazon Voice Focus and Echo Reduction features require Web Audio to be enabled in your meeting session. Configure this when joining a meeting:
22+
23+
```javascript
24+
await meetingManager.join(meetingSessionConfiguration, {
25+
enableWebAudio: true,
26+
});
27+
```
28+
29+
### Voice Focus and WebAudio Best Practice
30+
31+
When joining a meeting, only enable WebAudio when Voice Focus is both supported and desired by the user. Enabling WebAudio may cause browsers to disable their built-in noise cancellation features. If Voice Focus is not supported in this scenario, users will experience degraded audio quality due to the loss of both browser-level and SDK-level noise suppression. To prevent this, implement a conditional check: `enableWebAudio: userWantsVoiceFocus && (isVoiceFocusSupported === true)`
32+
33+
- userWantsVoiceFocus: Your application's user preference (e.g., checkbox state)
34+
- isVoiceFocusSupported: SDK-provided capability check from useVoiceFocus hook
35+
36+
This ensures WebAudio is only activated when Voice Focus can provide effective noise cancellation, maintaining optimal audio quality across all browser environments and device capabilities.
37+
1938
## Importing
2039

2140
```javascript
2241
import { AudioInputVFControl } from 'amazon-chime-sdk-component-library-react';
2342
```
2443

2544
## Usage
26-
`joinInfo` here is the response of [CreateMeeting](https://docs.aws.amazon.com/chime-sdk/latest/APIReference/API_CreateMeeting.html)
27-
from [Amazon Chime SDK Meetings endpoint](https://docs.aws.amazon.com/chime-sdk/latest/dg/meeting-namespace-migration.html).
45+
46+
`joinInfo` here is the response of [CreateMeeting](https://docs.aws.amazon.com/chime-sdk/latest/APIReference/API_CreateMeeting.html)
47+
from [Amazon Chime SDK Meetings endpoint](https://docs.aws.amazon.com/chime-sdk/latest/dg/meeting-namespace-migration.html).
2848
`joinInfo` is needed here so as to decide whether download Voice Focus or Echo Reduction model according to `CreatingMeetingResponse`.
2949

3050
```jsx
31-
import React from 'react';
51+
import React, { useEffect, useState } from 'react';
3252
import {
3353
MeetingProvider,
3454
VoiceFocusProvider,
3555
AudioInputVFControl,
56+
useMeetingManager,
57+
useVoiceFocus,
3658
} from 'amazon-chime-sdk-component-library-react';
59+
import { VoiceFocusModelName } from 'amazon-chime-sdk-js';
3760

38-
const enableWebAudio = true;
39-
const meetingConfig = { enableWebAudio };
40-
const joinInfo = { Meeting: {} }
61+
const joinInfo = {
62+
Meeting: {
63+
MeetingFeatures: {
64+
Audio: { EchoReduction: 'AVAILABLE' }
65+
}
66+
}
67+
};
4168

4269
function voiceFocusName(name: string): VoiceFocusModelName {
4370
if (name && ['default', 'ns_es'].includes(name)) {
@@ -48,7 +75,7 @@ function voiceFocusName(name: string): VoiceFocusModelName {
4875

4976
function getVoiceFocusSpecName(): VoiceFocusModelName {
5077
if (
51-
joinInfo &&
78+
joinInfo &&
5279
joinInfo.Meeting?.MeetingFeatures?.Audio?.EchoReduction === 'AVAILABLE'
5380
) {
5481
return voiceFocusName('ns_es');
@@ -57,19 +84,37 @@ function getVoiceFocusSpecName(): VoiceFocusModelName {
5784
}
5885

5986
const vfConfigValue = {
60-
spec: {name: getVoiceFocusSpecName()},
87+
spec: { name: getVoiceFocusSpecName() },
6188
createMeetingResponse: joinInfo,
6289
};
6390

91+
const MeetingComponent = () => {
92+
const meetingManager = useMeetingManager();
93+
const { isVoiceFocusSupported } = useVoiceFocus();
94+
const [userWantsVoiceFocus, setUserWantsVoiceFocus] = useState(true); // Set via UI such as a checkbox
95+
96+
const joinMeeting = async () => {
97+
// Only enable WebAudio when Voice Focus is supported and desired
98+
const enableWebAudio = userWantsVoiceFocus && (isVoiceFocusSupported === true);
99+
100+
await meetingManager.join(meetingSessionConfiguration, {
101+
enableWebAudio
102+
});
103+
};
104+
105+
return <AudioInputVFControl />;
106+
};
107+
64108
const App = () => {
65109
return (
66110
<VoiceFocusProvider {...vfConfigValue}>
67-
<MeetingProvider {...meetingConfig}>
68-
<AudioInputVFControl />
111+
<MeetingProvider>
112+
<MeetingComponent />
69113
</MeetingProvider>
70114
</VoiceFocusProvider>
71115
);
72116
};
117+
73118
```
74119
75120
## Props

src/providers/MeetingProvider/docs/MeetingManager.mdx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,24 @@ options?: {
5555
eventController?: EventController;
5656

5757
// If you want to enable Amazon Voice Focus feature, you should enable Web Audio for the meeting and pass the `enableWebAudio` prop with value set to `true`.
58-
// By default, `enableWebAudio` is `false`.
58+
// Recommended: Only enable WebAudio when Voice Focus is both supported and desired by the user.
59+
//
60+
// Why this matters:
61+
// - Enabling WebAudio may cause browsers to disable built-in noise cancellation
62+
// - If Voice Focus is unsupported, users lose both browser-level AND SDK-level noise suppression
63+
// - This results in significantly degraded audio quality
64+
//
65+
// Best Practice:
66+
// enableWebAudio: userWantsVoiceFocus && (isVoiceFocusSupported === true)
67+
//
68+
// Where:
69+
// - userWantsVoiceFocus: Your application's user preference (e.g., checkbox state)
70+
// - isVoiceFocusSupported: SDK-provided support check from `useVoiceFocus` hook
71+
//
72+
// This ensures WebAudio is only activated when Voice Focus can provide effective
73+
// noise cancellation, maintaining optimal audio quality across all environments.
74+
//
75+
// Default: false
5976
enableWebAudio?: boolean;
6077

6178
// The `ActiveSpeakerPolicy` object that you want to be used in the meeting session.

src/providers/VoiceFocusProvider/docs/VoiceFocusProvider.mdx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,23 @@ the provider is unmounted.
1515
This provider is independent from `MeetingProvider`. You can put `VoiceFocusProvider` wherever you want in the component tree to control the workflow of Voice Focus, so long
1616
as any component which relies on `VoiceFocusProvider` is nested within `VoiceFocusProvider`.
1717

18+
## Prerequisites
19+
20+
Amazon Voice Focus and Echo Reduction features require Web Audio to be enabled in your meeting session. Configure this when joining a meeting:
21+
22+
```javascript
23+
await meetingManager.join(meetingSessionConfiguration, { enableWebAudio: true });
24+
```
25+
26+
### Voice Focus and WebAudio Best Practice
27+
28+
When joining a meeting, only enable WebAudio when Voice Focus is both supported and desired by the user. Enabling WebAudio may cause browsers to disable their built-in noise cancellation features. If Voice Focus is not supported in this scenario, users will experience degraded audio quality due to the loss of both browser-level and SDK-level noise suppression. To prevent this, implement a conditional check: `enableWebAudio: userWantsVoiceFocus && (isVoiceFocusSupported === true)`
29+
30+
- userWantsVoiceFocus: Your application's user preference (e.g., checkbox state)
31+
- isVoiceFocusSupported: SDK-provided capability check from useVoiceFocus hook
32+
33+
This ensures WebAudio is only activated when Voice Focus can provide effective noise cancellation, maintaining optimal audio quality across all browser environments and device capabilities.
34+
1835
## State
1936

2037
```typescript

0 commit comments

Comments
 (0)