I am using both react-native-voice and expo-speech libraries to transcript my voice and to convert a text to a speech. The problem is, in android only, when I start the code runs Voice.onSpeechStarts then it returns false and does not record anything. But in iOS it is working fine. I am also using expo speech to speak out some component immediate after recording voice.
package.json versions:
"react": "18.2.0",
"react-native": "0.71.0",
"@react-native-voice/voice": "^3.2.4",
Note: I have tried with voice versions : 3.1.5, 3.2.4
Android sdk version : 31
Code:
export const Screen = () => {
const [isRecording, setIsRecording] = useState(false);
const [userMessage, setUserMessage] = useState('');
useEffect(() => {
Voice.onSpeechStart = onSpeechStartHandler;
Voice.onSpeechEnd = onSpeechEndHandler;
Voice.onSpeechResults = onSpeechResultsHandler;
return () => {
Voice.destroy().then(Voice.removeAllListeners);
};
}, []);
const onSpeechStartHandler = e => {
console.log('start handler=»', e);
};
const onSpeechEndHandler = e => {
console.log('stop handler', e);
};
const onSpeechResultsHandler = e => {
console.log('speech result handler', e);
setUserMessage(e.value[0]);
};
const startRecording = async () => {
setIsRecording(true);
try {
await Voice.start('en-US');
} catch (e) {
console.log('error -> ', e);
}
};
const stopRecording = () => {
setIsRecording(false);
try {
Voice.stop();
console.log(userMessage);
} catch (e) {
console.log('error -> ', e);
}
};
return (
<View
style={{
alignContent: 'center',
justifyContent: 'center',
backgroundColor: 'black',
flex: 1,
}}>
<Button
title={isRecording ? 'Stop Speaking' : 'Start Speaking'}
onPress={isRecording ? stopRecording : startRecording}
/>
</View>
);
};
When I try to check available speech services
Thanks for your time.