-
-
Notifications
You must be signed in to change notification settings - Fork 139
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
Implementing vad-react with create-react-app #24
Comments
Hi @Instage, a long time ago I briefly looked into how you might configure an app created by create-react-app to work with the vad, but I concluded early on that it was more trouble than it was worth for me at the time. I can eventually try to provide an example but I won't have time to look into it in the near future. However, one thing that I expect would work is to create a build script that looks something like #!/usr/bin/env bash
npm run build
cp \
node_modules/@ricky0123/vad-web/dist/silero_vad.onnx \
node_modules/@ricky0123/vad-web/dist/vad.worklet.bundle.min.js \
node_modules/onnxruntime-web/dist/*.wasm \
build True, you can't use the dev server, but at least you should have a working build system. You might need to copy the files into some subdirectory of the build directory. If the script I gave doesn't work, open dev tools and try to see what paths your site is requesting the onnx/wasm/worklet files from. |
Hello @ricky0123, Thanks for the quick response. I've been continuing to work on integrating into a Create React App based project, and I'm still facing issues. Following your suggestion, I tried to use a custom build script to copy the necessary files, but it didn't resolve the problem. Here's a summary of the steps I've taken so far:
I have double-checked the paths to the required files, and they seem to be correct. I also confirmed that the paths are being requested successfully through the browser. Despite trying different configurations, the error persists, and I am unable to use the library in my Create React App based project. Here is the current implementation of the Test.js component:
Would you be able to provide further guidance on how to resolve this issue? If you could identify any specific steps or configurations needed for the library to work correctly within a Create React App environment, it would be greatly appreciated. |
Hi, have you resolve the problem? I meet the same problem as yours. |
I have the same problem but in Next.js. I followed the example nextjs set up (same next config and forcing client-side rendering with dynamic, etc). I had to modify the code in the [node_modules/@ricky0123/vad-web/dist/asset-path.js] file because I may not be actively looking for a solution any time soon, but thought I would add some information to the issue here. Thanks for making this nice tool :-) |
Thanks for letting me know, @LLTOMZHOU. I don't have time to look into this at the moment but I will get to it at some point. |
I'm also facing this, hosting on AWS Amplify. My evaluation app was created following Amplify's tutorial, which uses Create React App. I'm able to instantiate a useMicVAD object, but the onSpeechX handlers are never called. Also tried webpack.config.js to get it working. |
Here's an ugly work-around. Import the dependencies in your index.html and define a global function that returns an instance of MicVAD. Then in App.js, you can use the useEffect hook to call that function and obtain the returned vad object. To get your hands on the audio data, pass in a callback. index.html at end of body tag:
App.js in App():
Hopefully @ricky0123 will be able to find some time for this before too long. This is the only browser friendly Silero I've been able to find. Thanks for the all the hard work! |
Works for me but for some reason its slower at least than the demo on the website... any idea about why that might be? |
Dear @ricky0123, is there a possibility that you find time to look into this? |
By using the Steps:
cp \
node_modules/@ricky0123/vad-web/dist/silero_vad.onnx \
node_modules/@ricky0123/vad-web/dist/vad.worklet.bundle.min.js \
node_modules/onnxruntime-web/dist/*.wasm \
public
// import it
import * as ort from "onnxruntime-web";
// change the config
ort.env.wasm.wasmPaths = {
"ort-wasm-simd-threaded.wasm": "/ort-wasm-simd-threaded.wasm",
"ort-wasm-simd.wasm": "/ort-wasm-simd.wasm",
"ort-wasm.wasm": "/ort-wasm.wasm",
"ort-wasm-threaded.wasm": "/ort-wasm-threaded.wasm",
};
const vad = useMicVAD({
modelURL: "/silero_vad.onnx",
workletURL: "/vad.worklet.bundle.min.js",
// other options It's not ideal but it works. I'll try to find a proper solution when I have a time. |
It seems like So, we need to configure the import { useMicVAD } from "@ricky0123/vad-react";
import * as ort from "onnxruntime-web";
ort.env.wasm.wasmPaths = "/_next/static/chunks/";
const vad = useMicVAD({
modelURL: "/_next/static/chunks/silero_vad.onnx",
workletURL: "/_next/static/chunks/vad.worklet.bundle.min.js",
}); |
Heya, I managed to figure out an alternative solution based on this next.config.js file in the next-onnx repository. This works without needing to manually move any files or do any manual configuration of the There are three steps required:
const CopyPlugin = require("copy-webpack-plugin");
const wasmPaths = [
"./node_modules/onnxruntime-web/dist/ort-wasm.wasm",
"./node_modules/onnxruntime-web/dist/ort-wasm-threaded.wasm",
"./node_modules/onnxruntime-web/dist/ort-wasm-simd.wasm",
"./node_modules/onnxruntime-web/dist/ort-wasm-simd.jsep.wasm",
"./node_modules/onnxruntime-web/dist/ort-wasm-simd-threaded.wasm",
"./node_modules/onnxruntime-web/dist/ort-wasm-simd-threaded.jsep.wasm",
"./node_modules/onnxruntime-web/dist/ort-training-wasm-simd.wasm",
];
/** @type {import('next').NextConfig} */
const nextConfig = {
webpack: (config) => {
config.resolve.fallback = {
...config.resolve.fallback,
fs: false,
};
//local dev server - copy wasm into static/chunks/app
config.plugins.push(
new CopyPlugin({ patterns: wasmPaths.map(p => ({from: p, to: "static/chunks/app"})) })
);
//vercel - copy wasm into static/chunks
config.plugins.push(
new CopyPlugin({ patterns: wasmPaths.map(p => ({from: p, to: "static/chunks"})) })
);
return config;
},
};
module.exports = nextConfig; This is using next.js 14 with my project organized to use the src/app directory structure. Perhaps there's a way to avoid having to have two separate plugins, but for whatever reason I noticed that VAD was looking for its files in |
Has there been any update on using VAD with create-react-app? I have followed all the provided installation steps, I have created webpack.config.js file, but still getting this error.
|
Hi all, yesterday I released a couple of relevant updates
|
I suspect the
Using the implementation in assetPath() is going to try and load the worklet and model relative to the current page, rather than from /_next/static/chunks. |
This is gross, but works if you have complex next.js paths: const vad = useMicVAD({
workletURL: "/_next/static/chunks/vad.worklet.bundle.min.js",
modelURL: "/_next/static/chunks/silero_vad.onnx",
modelFetcher: (path) => {
const filename = path.split('/').pop()
return fetch(/_next/static/chunks/${filename}).then((model) => model.arrayBuffer())
},
ortConfig: (ort) => {
ort.env.wasm.wasmPaths = "/_next/static/chunks/"
},
onSpeechEnd: (audio) => {
// ...
},
}) |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
this setting works on server? I have this issue |
after download files(ort.js and bundle.min.js), after import, it gives me an error. |
We implemented the following in Next.js and it worked without any problems.
Reference:. |
Are you able to do production build for it ? |
Yes, this worked fine when deploying to vercel. |
My application was built with create-react-app, which uses react-scripts to hide the webpack config behind the scenes and this appears to be causing issues when trying to follow your guide for react-vad.
I tried installing copy-webpack-plugin, adding the new CopyPlugin to the webpack.config.js (which is found inside node_modules > react-scripts > config), and using the useMicVAD hook as per the guide. However, the hook doesn't work as I never see the console log that should be triggered by onSpeechEnd.
I set up a new React app with Webpack and followed your implementation guide and that does appear to work.
Is it possible to use react-vad with create-react-app? Are you able to provide an example of this implementation?
The text was updated successfully, but these errors were encountered: