Skip to content

Instantly share code, notes, and snippets.

@lmcarreiro
Created July 29, 2021 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lmcarreiro/3a9426a934554c2388cfcba3ef8b41fc to your computer and use it in GitHub Desktop.
Save lmcarreiro/3a9426a934554c2388cfcba3ef8b41fc to your computer and use it in GitHub Desktop.
STT+VAD article - useSpeechToText.diff - 2
// Control the streaming flag, based on the voice activity detection (that uses hark) and the mute/unmute flag
React.useEffect(() => {
if (shouldStream) {
console.log("Voice activity detected, starting streaming current buffer + live streaming...");
streamingFlagRef.current = true;
} else {
console.log("No voice activity detected, stopped streaming.");
+ const timeout = setTimeout(() => {
streamingFlagRef.current = false;
+ }, 2_000);
+
+ return () => clearTimeout(timeout);
}
}, [shouldStream]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment