Skip to content

Commit a35df7d

Browse files
committed
feat(app): positional-audio demo
1 parent bb88ce9 commit a35df7d

File tree

5 files changed

+80
-1
lines changed

5 files changed

+80
-1
lines changed

app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"@react-three/xr": "catalog:three",
3030
"@recast-navigation/core": "catalog:yuka",
3131
"@recast-navigation/three": "catalog:yuka",
32+
"@xsai/generate-speech": "catalog:xsai",
3233
"@xsai/generate-text": "catalog:xsai",
3334
"@xsai/shared": "catalog:xsai",
3435
"@xsai/shared-chat": "catalog:xsai",
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { Container, Root, Text } from '@react-three/uikit'
2+
import { Button, Input } from '@react-three/uikit-default'
3+
import { generateSpeech } from '@xsai/generate-speech'
4+
import { useMemo, useState } from 'react'
5+
6+
import { Galatea } from '~/components/vrm/galatea'
7+
import { useSetAudioBuffer } from '~/context/audio-buffer'
8+
import { useTTSProvider } from '~/hooks/use-providers'
9+
10+
const DebugPositionalAudio = () => {
11+
const [disabled, setDisabled] = useState(false)
12+
const [value, setValue] = useState<string>('')
13+
const [ttsProvider] = useTTSProvider()
14+
const setAudioBuffer = useSetAudioBuffer()
15+
16+
const audioContext = useMemo(() => new AudioContext({ latencyHint: 'interactive' }), [])
17+
18+
const handleSubmit = async () => {
19+
setDisabled(true)
20+
21+
const arrayBuffer = await generateSpeech({
22+
...ttsProvider,
23+
input: value,
24+
})
25+
26+
const audioBuffer = await audioContext.decodeAudioData(arrayBuffer)
27+
28+
setAudioBuffer(audioBuffer)
29+
setValue('')
30+
setDisabled(false)
31+
}
32+
33+
return (
34+
<>
35+
<Galatea />
36+
<group position={[0, 1, 0]}>
37+
<Root>
38+
<Container flexDirection="column" gap={4}>
39+
<Input
40+
data-test-id="debug-input"
41+
disabled={disabled}
42+
onValueChange={value => setValue(value)}
43+
placeholder="Write a message..."
44+
value={value}
45+
width={200}
46+
/>
47+
<Button
48+
data-test-id="debug-button"
49+
disabled={disabled}
50+
// eslint-disable-next-line ts/no-misused-promises
51+
onClick={handleSubmit}
52+
variant="secondary"
53+
>
54+
<Text>Submit</Text>
55+
</Button>
56+
</Container>
57+
</Root>
58+
</group>
59+
</>
60+
)
61+
}
62+
63+
export default DebugPositionalAudio

app/src/router.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export type Path =
1010
| `/debug/input`
1111
| `/debug/menu`
1212
| `/debug/planes`
13+
| `/debug/positional-audio`
1314
| `/debug/settings`
1415
| `/debug/speech-recognition`
1516
| `/debug/tablet`

pnpm-lock.yaml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ catalogs:
3434
three-stdlib: ^2.36.0
3535

3636
xsai:
37-
'@xsai/generate-text': &xsai ^0.2.2
37+
'@xsai/generate-speech': &xsai ^0.2.2
38+
'@xsai/generate-text': *xsai
3839
'@xsai/shared': *xsai
3940
'@xsai/shared-chat': *xsai
4041

0 commit comments

Comments
 (0)