Skip to content

Commit 5a8be70

Browse files
committed
use worklet with fade
1 parent 4ef2ca4 commit 5a8be70

File tree

3 files changed

+42
-19
lines changed

3 files changed

+42
-19
lines changed

.prettierrc.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* eslint-env commonjs */
2+
module.exports = {
3+
arrowParens: "always",
4+
bracketSameLine: false,
5+
bracketSpacing: true,
6+
embeddedLanguageFormatting: "auto",
7+
endOfLine: "lf",
8+
htmlWhitespaceSensitivity: "css",
9+
jsxSingleQuote: false,
10+
printWidth: 80,
11+
proseWrap: "preserve",
12+
quoteProps: "as-needed",
13+
rangeEnd: Infinity,
14+
rangeStart: 0,
15+
semi: true,
16+
singleAttributePerLine: false,
17+
singleQuote: true,
18+
tabWidth: 2,
19+
trailingComma: "all",
20+
useTabs: false,
21+
};

examples/next-app/components/Voice.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@ import { ExampleComponent } from '@/components/ExampleComponent';
99
export const Voice = ({ accessToken }: { accessToken: string }) => {
1010
return (
1111
<VoiceProvider
12-
auth={{ type: 'accessToken', value: accessToken }}
13-
hostname={process.env.NEXT_PUBLIC_HUME_VOICE_HOSTNAME || 'api.hume.ai'}
12+
auth={{
13+
type: 'apiKey',
14+
value: 'JesgJYUNkFnqnEDzPSeGXjWMt3Zae2q7o7H1GBqn7A1AOJ2k',
15+
}}
16+
hostname={'test-api.hume.ai'}
17+
queryParams={{
18+
hume_uuid: 'a46eac19-af97-4658-b845-57120c695bef',
19+
}}
20+
configId={'889cff21-cfaf-4269-8e90-b5b9a5f7f92e'}
1421
messageHistoryLimit={10}
1522
onMessage={(message) => {
1623
// eslint-disable-next-line no-console
@@ -118,7 +125,6 @@ export const Voice = ({ accessToken }: { accessToken: string }) => {
118125
});
119126
}
120127
}, [])}
121-
configId={process.env.NEXT_PUBLIC_HUME_VOICE_WEATHER_CONFIG_ID}
122128
onClose={(event) => {
123129
const niceClosure = 1000;
124130
const code = event.code;

packages/react/src/lib/useSoundPlayer.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ export const useSoundPlayer = (props: {
5555

5656
await initAudioContext.audioWorklet
5757
.addModule(
58-
'https://storage.googleapis.com/evi-react-sdk-assets/audio-worklet.js',
58+
//'https://storage.googleapis.com/evi-react-sdk-assets/audio-worklet.js',
59+
'https://storage.googleapis.com/franc-worklet-test/worklet.js',
5960
)
6061
.catch((e) => {
6162
console.log(e);
@@ -104,16 +105,17 @@ export const useSoundPlayer = (props: {
104105
await audioContext.current.decodeAudioData(arrayBuffer);
105106

106107
const pcmData = audioBuffer.getChannelData(0);
108+
workletNode.current?.port.postMessage({ type: 'audio', data: pcmData });
107109

108110
if (gainNode.current) {
109111
const now = audioContext.current.currentTime;
110112
gainNode.current.gain.cancelScheduledValues(now);
111-
const targetGain = isAudioMuted ? 0 : volume;
112-
gainNode.current.gain.setValueAtTime(targetGain, now);
113+
gainNode.current.gain.setValueAtTime(
114+
volume,
115+
audioContext.current.currentTime,
116+
);
113117
}
114118

115-
workletNode.current?.port.postMessage({ type: 'audio', data: pcmData });
116-
117119
setIsPlaying(true);
118120
onPlayAudio.current(message.id);
119121
} catch (e) {
@@ -131,24 +133,18 @@ export const useSoundPlayer = (props: {
131133
}
132134

133135
const now = audioContext.current.currentTime;
134-
135136
gainNode.current.gain.cancelScheduledValues(now);
136137
gainNode.current.gain.setValueAtTime(gainNode.current.gain.value, now);
137138
gainNode.current.gain.exponentialRampToValueAtTime(
138139
FADE_TARGET,
139140
now + FADE_DURATION,
140141
);
141-
142-
await new Promise((resolve) => {
143-
setTimeout(resolve, FADE_DURATION * 1000);
144-
});
145-
146142
workletNode.current?.port.postMessage({ type });
147-
148-
gainNode.current?.gain.setValueAtTime(
149-
1.0,
150-
audioContext.current?.currentTime || 0,
151-
);
143+
/*await new Promise((resolve) => {
144+
setTimeout(() => {
145+
resolve(null);
146+
}, FADE_DURATION * 1000);
147+
});*/
152148
}, []);
153149

154150
const stopAll = useCallback(async () => {

0 commit comments

Comments
 (0)