User guide for use in React projects
-
Install
@ricky0123/vad-react
:npm i @ricky0123/vad-react
-
Follow the bundling instructions for
@ricky0123/vad-web
. To recap, you need to serve the worklet and onnx files that come distributed with@ricky0123/vad-web
and the wasm files fromonnxruntime-web
, which will both be pulled in as dependencies. -
Use the
useMicVAD
hook to start the voice activity detector:import { useMicVAD } from "@ricky0123/vad-react"
const MyComponent = () => {
const vad = useMicVAD({
startOnLoad: true,
onSpeechEnd: (audio) => {
console.log("User stopped talking")
},
})
return <div>{vad.userSpeaking && "User is speaking"}</div>
}See the docs for useMicVAD for details.