voice icon indicating copy to clipboard operation
voice copied to clipboard

Error starting voice recognition: [TypeError: Cannot read property 'startSpeech' of null]

Open Spero-Sourabh opened this issue 1 year ago • 15 comments

Title: Error starting voice recognition: [TypeError: Cannot read property 'startSpeech' of null] this project it based on java 17 and i'm using java 17 but this package runs on java if you have any solution then help me

I am facing the following error when attempting to use voice recognition with @react-native-voice/voice:

import React, { useState, useEffect } from 'react'; import { View, Text, Button } from 'react-native'; import Voice from '@react-native-voice/voice';

const VoiceDetection = () => { const [recognizedText, setRecognizedText] = useState(''); const [isListening, setIsListening] = useState(false);

useEffect(() => { Voice.onSpeechStart = onSpeechStart; Voice.onSpeechEnd = onSpeechEnd; Voice.onSpeechResults = onSpeechResults; Voice.onSpeechError = onSpeechError;

// Clean up when the component unmounts
return () => {
  Voice.destroy().then(Voice.removeAllListeners);
};

}, []);

const startListening = async () => { try { setIsListening(true); await Voice.start('en-US'); // You can change the locale to your desired language } catch (error) { console.error('Error starting voice recognition:', error); } };

const stopListening = async () => { try { await Voice.stop(); setIsListening(false); } catch (error) { console.error('Error stopping voice recognition:', error); } };

const onSpeechStart = (e) => { console.log('Speech recognition started', e); };

const onSpeechEnd = (e) => { console.log('Speech recognition ended', e); };

const onSpeechResults = (e) => { const results = e.value; if (results && results.length > 0) { setRecognizedText(results[0]); } };

const onSpeechError = (e) => { console.error('Speech recognition error', e); };

return ( <View style={{marginTop:40}}> <Button title={isListening ? 'Stop Listening' : 'Start Listening'} onPress={isListening ? stopListening : startListening} /> <Text>Recognized Speech: {recognizedText}</Text> </View> ); };

export default VoiceDetection;

Error starting voice recognition: [TypeError: Cannot read property 'startSpeech' of null] Steps to Reproduce: Install the @react-native-voice/voice package and set it up as per the official documentation. Call Voice.startSpeech() to initiate speech recognition. Expected Behavior: The speech recognition should start without any issues.

Actual Behavior: I receive the error: [TypeError: Cannot read property 'startSpeech' of null], indicating that the Voice object is null when attempting to call startSpeech.

Environment: React Native version: [Your RN version] @react-native-voice/voice version: [Version you're using] Platform: [Android/iOS version] Permissions: Microphone permissions are granted. Additional Information: I have followed all the setup instructions from the official documentation. The Voice object is null when trying to access startSpeech. I have tried clearing the cache and rebuilding the project, but the issue persists.

Spero-Sourabh avatar Nov 15 '24 12:11 Spero-Sourabh

same error did you find the solution

tanzeel152 avatar Nov 18 '24 13:11 tanzeel152

set the new architecture in your android/gradl.properties file, like this newArchEnabled=false this library is not supported by new architecture yet. Worked for me

Prashantrajput11 avatar Jan 15 '25 09:01 Prashantrajput11

@Prashantrajput11 , but its working fine the functionality , while build the apk , i got the build failed/issues.

Reason: Task ':@react-native-voice_voice:bundleDebugAar' uses this output of task ':react-native-voice_voice:writeDebugAarMetadata' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.

when i change the newArchEnable=true , it was build successful and created apk also, But the voice functionality have same error , where previously comes.

Phimansu avatar Feb 03 '25 11:02 Phimansu

Same error here, doesn't work even with Java 11 and the newArchEnabled property in false

eloy-bermejo-qh avatar Feb 03 '25 12:02 eloy-bermejo-qh

For me, the same error is coming even though I have added the plugins in app.json

balkrish25 avatar Feb 20 '25 10:02 balkrish25

same expo sdk 52

umutsesen avatar Mar 14 '25 15:03 umutsesen

Same error guys, any probable solutions?

Update: It works fine on my ios device. I guess it doesn't work on web.

saumitra91 avatar Mar 16 '25 07:03 saumitra91

does this package support the new architecture yet? getting this error on react-native 0.78

mohshbool avatar Apr 06 '25 12:04 mohshbool

still same error

magical-to avatar Apr 30 '25 13:04 magical-to

Doing this fixed it for me

set the new architecture in your android/gradl.properties file, like this newArchEnabled=false this library is not supported by new architecture yet. Worked for me

fisher0fm3n avatar May 01 '25 22:05 fisher0fm3n

Doing this fixed it for me

set the new architecture in your android/gradl.properties file, like this newArchEnabled=false this library is not supported by new architecture yet. Worked for me

the released package doesn't yet support the new architecture but there was a commit that added support. I'm just unable to configure it to run with newArchEnabled. Anyone has any suggestion?

mohshbool avatar May 02 '25 11:05 mohshbool

set the new architecture in your android/gradl.properties file, like this newArchEnabled=false this library is not supported by new architecture yet. Worked for me

Setting newArch to false worked but I faced UI rendering issues like flickering of bottom tabs and headers of some screens went blank.

Note - Buttons situated on header were fully functional

Any solution?

ShahidPathan09 avatar May 07 '25 10:05 ShahidPathan09

setting newArch to false worked for me but faced UI issues like text color changed to white through out the app.

MaryamKhan05 avatar May 13 '25 10:05 MaryamKhan05

same issue

ezequiel88 avatar Jun 01 '25 22:06 ezequiel88