react-native-voice / voice

:microphone: React Native Voice Recognition library for iOS and Android (Online and Offline Support)
MIT License
1.81k stars 488 forks source link

Inconsistent delay before onSpeechStart is called #497

Open rewhsu opened 5 months ago

rewhsu commented 5 months ago

I realize that this project is essentially abandoned, but am wondering if anyone else is experiencing this issue or has found a fix. onSpeechStart seems to experience an inconsistent delay, usually after the first time the Voice.start() method is called.

I've logged this line in the module, and it seems to essentially be firing immediately, as expected:

console.log('Voice.startSpeech', new Date().toISOString()) // 2024-04-24T22:35:23.832Z
Voice.startSpeech(locale, callback);

The callback also seems to be firing at essentially the same time.

However, my implementation's onSpeechStart sometimes fires immediately, or can experience a delay of up to a couple seconds:

useEffect(() => {
    Voice.onSpeechStart = onSpeechStart;
    Voice.onSpeechRecognized = onSpeechRecognized;
    Voice.onSpeechEnd = onSpeechEnd;
    Voice.onSpeechError = onSpeechError;
    Voice.onSpeechResults = onSpeechResults;
    Voice.onSpeechPartialResults = onSpeechPartialResults;
    Voice.onSpeechVolumeChanged = onSpeechVolumeChanged;
    return () => {
      Voice.destroy().then(Voice.removeAllListeners);
    };
}, []);

const onSpeechStart = (_e: SpeechStartEvent) => {
    console.log('onSpeechStart', new Date().toISOString()); // 2024-04-24T22:35:26.447Z
    setStarted(true);
};

Any help, alternatives, or discussion would be greatly appreciated, thanks!

rewhsu commented 5 months ago

A related issue: #404