ricky0123 / vad

Voice activity detector (VAD) for the browser with a simple API
https://www.vad.ricky0123.com
Other
818 stars 130 forks source link

If you use Vite, refer to my configuration. #128

Open Jakevin opened 3 months ago

Jakevin commented 3 months ago

vite.config.js

export default defineConfig({
  plugins: [
    vue(),
    viteStaticCopy({
      targets: [
        {
          src: 'node_modules/@ricky0123/vad-web/dist/vad.worklet.bundle.min.js',
          dest: './'
        },
        {
          src: 'node_modules/@ricky0123/vad-web/dist/silero_vad.onnx',
          dest: './'
        },
        {
          src: 'node_modules/onnxruntime-web/dist/*.wasm',
          dest: './'
        }
      ]
    })
  ],

})

in your code

import { MicVAD } from "@ricky0123/vad-web"

onMounted(async () => {
   const myvad = await MicVAD.new({
    workletURL: './vad.worklet.bundle.min.js', // setting workletURL
    modelURL: './silero_vad.onnx', // setting modelURL
    onSpeechEnd: (audio) => {
      console.log('Speech end detected');
      // do something with `audio` (Float32Array of audio samples at sample rate 16000)...
      const audioArray = new Float32Array(audio); // Example audio data
      return audioArray;
    },
  })
  myvad.start()
})
soylomass commented 2 months ago

Thanks. I have another problem though, the library seems to be trying to load some files (ort-wasm-simd.wasm) from the current path instead of from root, therefore it's failing.

ie. Should load from http://localhost:3000/ort-wasm-simd.wasm Loads from http://localhost:3000/path/ort-wasm-simd.wasm

Do you have this problem?


Solved, had to add:

      ortConfig: (ort) => {
        ort.env.wasm.wasmPaths = "/";
      },