Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to get this bundled into a vite/SvelteKit app #34

Open
symbolicsorcerer opened this issue Jul 20, 2023 · 3 comments
Open

Trying to get this bundled into a vite/SvelteKit app #34

symbolicsorcerer opened this issue Jul 20, 2023 · 3 comments
Labels

Comments

@symbolicsorcerer
Copy link

I think I'm probably doing something wrong, but I can't seem to get things loading in bundled form. I'm using the following in my onMount (fairly equivalent to useEffect in React):

    const { MicVAD, utils } = await import("@ricky0123/vad-web")

And I'm seeing a 404 in the vite process:

Error: Not found: /node_modules/@ricky0123/vad-web/src/real-time-vad.ts

Reading the vite docs, it sounds like it should be hitting /.vite/node_modules, and that vite will automatically rewrite the URL.

Not sure if this is an issue with the way vad-web is currently packaged, or if I need to be configuring vite better.

Additionally - I've thrown the onnx-runtime and such static files into static/, but looking at some of the code in this repo, I wonder if I need to configure something in vite to do some rewrites there.

(Also posted this in svelte's repo 🙏 sveltejs/kit#779 (comment))

@symbolicsorcerer
Copy link
Author

symbolicsorcerer commented Jul 20, 2023

As a small update, I added this to the vite config as a stab in the dark:

  optimizeDeps: {
    exclude: ['@ricky0123/vad-web']
  }

And I'm seeing Uncaught (in promise) ReferenceError: exports is not defined

@devidw
Copy link

devidw commented Oct 7, 2023

  • the web lib depends on browser apis
  • sveltekit will ssr by default, onMount will also be invoked on the server
  • to work around this you want to import {browser} from "$app/environment" and only invoke your dynamic loading when you are actually in the browser

@lc-spxl
Copy link

lc-spxl commented Oct 10, 2023

UPDATE I had the same issue, but was my fault

      const vad = await import("@ricky0123/vad-web/dist/index");
      try {
        await vad.MicVAD.new({
          stream: mediaStream,
          workletURL: '/node_modules/@ricky0123/vad-web/dist/vad.worklet.bundle.min.js',
          onSpeechEnd: console.log,
          onSpeechStart: console.log,
          onFrameProcessed: console.log,
        })
      } catch(e: any) {
        console.log(e)
      }

Additionally (sveltekit specific)

# in sveltekit project root

mkdir -p ./static
cp node_modules/@ricky0123/vad-web/dist/silero_vad.onnx static/
cp node_modules/onnxruntime-web/dist/*.wasm static/

It starts however I see some errors, will explore if everything works as expected

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants