react-native-voice/voice

Inconsistent delay before onSpeechStart is called

rewhsu opened this issue · 1 comments

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!

A related issue: #404