Skip to content

Commit 579f43e

Browse files
committed
feat(app): vad-stt demo
1 parent 556ebe3 commit 579f43e

File tree

5 files changed

+63
-0
lines changed

5 files changed

+63
-0
lines changed

app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"@ricky0123/vad-react": "^0.0.30",
3333
"@xsai/generate-speech": "catalog:xsai",
3434
"@xsai/generate-text": "catalog:xsai",
35+
"@xsai/generate-transcription": "catalog:xsai",
3536
"@xsai/shared": "catalog:xsai",
3637
"@xsai/shared-chat": "catalog:xsai",
3738
"foxact": "catalog:",

app/src/pages/debug/vad-stt.tsx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Text } from '@react-three/drei'
2+
import { useMicVAD, utils } from '@ricky0123/vad-react'
3+
import { generateTranscription } from '@xsai/generate-transcription'
4+
import { useEffect, useState } from 'react'
5+
6+
import { useSTTProvider } from '~/hooks/use-providers'
7+
8+
const DebugVadStt = () => {
9+
const [sttProvider] = useSTTProvider()
10+
const [file, setFile] = useState<Blob>()
11+
const [text, setText] = useState('')
12+
13+
useMicVAD({
14+
onSpeechEnd: (audio) => {
15+
console.warn('onSpeechEnd')
16+
17+
setFile(new Blob([utils.encodeWAV(audio)], { type: 'audio/wav' }))
18+
},
19+
onSpeechStart: () => console.warn('onSpeechStart'),
20+
startOnLoad: true,
21+
})
22+
23+
useEffect(() => {
24+
if (!file)
25+
return
26+
27+
const getTranscription = async () => {
28+
const { text } = await generateTranscription({ ...sttProvider, file })
29+
30+
console.warn('Transcription:', text)
31+
setText(text)
32+
}
33+
34+
void getTranscription()
35+
}, [file, sttProvider])
36+
37+
return (
38+
<Text>{text}</Text>
39+
)
40+
}
41+
42+
export default DebugVadStt

app/src/router.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export type Path =
1515
| `/debug/speech-recognition`
1616
| `/debug/tablet`
1717
| `/debug/text`
18+
| `/debug/vad-stt`
1819

1920
export type Params = {
2021

pnpm-lock.yaml

Lines changed: 18 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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ catalogs:
3939
xsai:
4040
'@xsai/generate-speech': &xsai ^0.2.2
4141
'@xsai/generate-text': *xsai
42+
'@xsai/generate-transcription': *xsai
4243
'@xsai/shared': *xsai
4344
'@xsai/shared-chat': *xsai
4445

0 commit comments

Comments
 (0)