I am using speech to text using react-native-community/voice. For android, it is working fine but for iOS, it is not giving proper results. I tried using hooks also but getting the same result.
I used timer of 5 seconds to handle destroy voice method(It was also not working on my iOS project).
I'm using
react-native-cli: 2.0.1react-native: 0.59.8
Can someone help me in this regard?
Thanks in advance.Here is my code: -
state = { recognized: '', pitch: '', error: '', end: '', started: '', results: [], partialResults: [], dataSource: [], isNet:false, isLoading : false, }; constructor(props: Props) { super(props); Voice.onSpeechStart = this.onSpeechStart; Voice.onSpeechRecognized = this.onSpeechRecognized; Voice.onSpeechEnd = this.onSpeechEnd; Voice.onSpeechError = this.onSpeechError; Voice.onSpeechResults = this.onSpeechResults; Voice.onSpeechPartialResults = this.onSpeechPartialResults; Voice.onSpeechVolumeChanged = this.onSpeechVolumeChanged; } componentWillUnmount() { Voice.destroy().then(Voice.removeAllListeners); } onSpeechStart = (e: any) => { this.setState({ started: '', }); }; onSpeechRecognized = (e: SpeechRecognizedEvent) => { this.setState({ recognized: '', }); }; onSpeechEnd = (e: any) => { this.setState({ end: '', }); }; onSpeechError = (e: SpeechErrorEvent) => { this.setState({ error: JSON.stringify(e.error), }); }; onSpeechResults = (e: SpeechResultsEvent) => { this.setState({ results: e.value, }); // My Own Method this.getSearchResult(e.value[0]) }; onSpeechPartialResults = (e: SpeechResultsEvent) => { this.setState({ partialResults: e.value, }); }; onSpeechVolumeChanged = (e: any) => { this.setState({ pitch: e.value, }); }; _startRecognizing = async () => { this.setState({ recognized: '', pitch: '', error: '', started: '', results: [], partialResults: [], end: 'Listning ...', }); try { Platform.OS === 'ios' { setTimeout(() => { this._destroyRecognizer() }, 5000) } await Voice.start('en-US'); } catch (e) { console.error(e); } }; _stopRecognizing = async () => { try { await Voice.stop(); } catch (e) { console.error(e); } }; _cancelRecognizing = async () => { try { await Voice.cancel(); } catch (e) { console.error(e); } }; _destroyRecognizer = async () => { try { await Voice.destroy(); } catch (e) { console.error(e); } this.setState({ recognized: '', pitch: '', error: '', started: '', results: [], partialResults: [], end: '', }); };
Any help will appreciate