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

Add a method to dynamically adjust VAD parameters at runtime #173

Open
uzimaru0000 opened this issue Dec 18, 2024 · 2 comments
Open

Add a method to dynamically adjust VAD parameters at runtime #173

uzimaru0000 opened this issue Dec 18, 2024 · 2 comments

Comments

@uzimaru0000
Copy link

Currently, the VAD parameters need to be fixed during initialization. However, in some scenarios, it would be beneficial to adjust these parameters dynamically at runtime.

For example:

Adjusting sensitivity according to changes in environmental noise
Relaxing or tightening detection criteria based on specific situations

Currently, the following patch is being applied:

diff --git a/node_modules/@ricky0123/vad-web/dist/real-time-vad.d.ts b/node_modules/@ricky0123/vad-web/dist/real-time-vad.d.ts
index 4d1a639..5db6e5a 100644
--- a/node_modules/@ricky0123/vad-web/dist/real-time-vad.d.ts
+++ b/node_modules/@ricky0123/vad-web/dist/real-time-vad.d.ts
@@ -54,6 +54,7 @@ export declare class MicVAD {
     pause: () => void;
     start: () => void;
     destroy: () => void;
+    setOptions: (options: Partial<FrameProcessorOptions>) => void;
 }
 export declare class AudioNodeVAD {
     ctx: AudioContext;
@@ -73,6 +74,7 @@ export declare class AudioNodeVAD {
         frame: Float32Array;
     }>) => void;
     destroy: () => void;
+    setFrameProcessorOptions: (options: Partial<FrameProcessorOptions>) => void;
 }
 export {};
 //# sourceMappingURL=real-time-vad.d.ts.map
\ No newline at end of file
diff --git a/node_modules/@ricky0123/vad-web/dist/real-time-vad.js b/node_modules/@ricky0123/vad-web/dist/real-time-vad.js
index 9b17631..a59fb83 100644
--- a/node_modules/@ricky0123/vad-web/dist/real-time-vad.js
+++ b/node_modules/@ricky0123/vad-web/dist/real-time-vad.js
@@ -114,6 +114,9 @@ class MicVAD {
             this.audioNodeVAD.destroy();
             this.audioContext.close();
         };
+        this.setOptions = (options) => {
+            this.audioNodeVAD.setFrameProcessorOptions(options);
+        }
     }
 }
 exports.MicVAD = MicVAD;
@@ -223,6 +226,12 @@ class AudioNodeVAD {
             });
             this.entryNode.disconnect();
         };
+        this.setFrameProcessorOptions = (options) => {
+            this.frameProcessor.options = {
+                ...this.frameProcessor.options,
+                ...options,
+            };
+        }
     }
 }
 exports.AudioNodeVAD = AudioNodeVAD;

If this request is accepted and further discussion is needed, I am happy to assist and, if necessary, create a Pull Request to integrate this feature into the library.

@tisDDM
Copy link

tisDDM commented Dec 19, 2024

Great Idea! This is exactly what I was looking for !

@ricky0123
Copy link
Owner

For sure, this would be cool

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

No branches or pull requests

3 participants