voice
voice copied to clipboard
Auto stop or SilenceDetection
in my app , I want to stop recording if user does not speak for 2 sec. is there any way to achieve this ?
I built this functionality in the app with the following:
let silenceTimer = useRef(null);
Voice.onSpeechResults = onSpeechResults;
const onSpeechResults = (e) => {
clearTimeout(silenceTimer.current);
silenceTimer.current = setTimeout(async () => {
Voice.stop();
}, 2000);
};
The basic idea is that when voice is detected, onSpeechResults will be called. the silenceTimer is cleared (wont be one on the first call) and then setTimeout is used to stop detection after 2 seconds. If more voice is detected, onSpeechResults will reset the timer each time until 2 seconds of no voice detection happens.
I built this functionality in the app with the following:
let silenceTimer = useRef(null); Voice.onSpeechResults = onSpeechResults; const onSpeechResults = (e) => { clearTimeout(silenceTimer.current); silenceTimer.current = setTimeout(async () => { Voice.stop(); }, 2000); };The basic idea is that when voice is detected, onSpeechResults will be called. the silenceTimer is cleared (wont be one on the first call) and then setTimeout is used to stop detection after 2 seconds. If more voice is detected, onSpeechResults will reset the timer each time until 2 seconds of no voice detection happens.
it can work for ios but on android it auto stops recording after detecting silence
I built this functionality in the app with the following:
let silenceTimer = useRef(null); Voice.onSpeechResults = onSpeechResults; const onSpeechResults = (e) => { clearTimeout(silenceTimer.current); silenceTimer.current = setTimeout(async () => { Voice.stop(); }, 2000); };The basic idea is that when voice is detected, onSpeechResults will be called. the silenceTimer is cleared (wont be one on the first call) and then setTimeout is used to stop detection after 2 seconds. If more voice is detected, onSpeechResults will reset the timer each time until 2 seconds of no voice detection happens.
best anw thanks brother perfectly working for IOS . when user stop speaking voice rec auto stop after 5 sec
In my case it is best way to handle it inside TS-code by results from micro.
useEffect(() => {
if (isEmpty(results)) {
const newTimer = setTimeout(() => {
_stopRecognizing();
}, 10000); // 10 seconds
setTimer(newTimer);
return () => {
if (timer) {
clearTimeout(timer);
}
};
}
}, [results]);