react-native-voice / voice

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

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

Open Spero-Sourabh opened 1 week ago

Spero-Sourabh commented 1 week ago

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 (

tanzeel152 commented 5 days ago

same error did you find the solution

Spero-Sourabh commented 2 days ago

same error did you find the solution

you can fix this by running your project in java 11 if your react native project supports java 11 but right now it didn't work on java 17 on later version