This below code is my codes. i don't know how can i next step for working in background mode in react-native for react-native-voice. would you check my codes
import Voice from '@react-native-voice/voice';
import BackgroundService from 'react-native-background-actions';
const sleep = (time) => new Promise((resolve) => setTimeout(() => resolve(), time));
const veryIntensiveTask = async (taskDataArguments) => {
// Example of an infinite loop task
const { delay } = taskDataArguments;
await new Promise( async (resolve) => {
for (let i = 0; BackgroundService.isRunning(); i++) {
console.log(i);
await Voice.start('ko-KR');
console.log('voice check');
console.log("voiceLabel",voiceLabel);
//you can call spi here
await BackgroundService.updateNotification({taskDesc: 'my counter is running' + i});
await sleep(delay);
}
});
};
const startBackgroundService = async () => {
console.log('test');
await BackgroundService.start(veryIntensiveTask, options);
await BackgroundService.updateNotification({taskDesc: 'my counter is running'});
};
const stopBackgroundService = async () =>{
await BackgroundService.stop();
};
useEffect(() => {
Voice.onSpeechStart = _onSpeechStart;
Voice.onSpeechEnd = _onSpeechEnd;
Voice.onSpeechResults = _onSpeechResults;
Voice.onSpeechError = _onSpeechError;
I try to like this, but this way bouble onSpeechStart.