compiled successfully

This commit is contained in:
Dobromir Popov
2024-02-14 18:27:15 +02:00
parent 8edaa4b937
commit 7fd17ada80
3 changed files with 87 additions and 3 deletions

View File

@ -0,0 +1,72 @@
// VoiceHandler.js
import React, { Component } from 'react';
import { View, Text, Button } from 'react-native';
import Voice from '@react-native-voice/voice';
class VoiceHandler extends Component {
constructor(props) {
super(props);
this.state = {
recognized: '',
started: '',
results: [],
};
Voice.onSpeechStart = this.onSpeechStart.bind(this);
Voice.onSpeechRecognized = this.onSpeechRecognized.bind(this);
Voice.onSpeechResults = this.onSpeechResults.bind(this);
}
componentWillUnmount() {
Voice.destroy().then(Voice.removeAllListeners);
}
onSpeechStart(e) {
this.setState({
started: '√',
});
}
onSpeechRecognized(e) {
this.setState({
recognized: '√',
});
}
onSpeechResults(e) {
this.setState({
results: e.value,
});
}
async _startRecognizing(e) {
this.setState({
recognized: '',
started: '',
results: [],
});
try {
await Voice.start('en-US');
} catch (e) {
console.error(e);
}
}
render() {
return (
<View>
<Text>Press the button and start speaking.</Text>
<Button
onPress={this._startRecognizing.bind(this)}
title="Start Recognizing"
/>
<Text>Recognized: {this.state.recognized}</Text>
<Text>Started: {this.state.started}</Text>
<Text>Results: {this.state.results.join(' ')}</Text>
</View>
);
}
}
export default VoiceHandler;

View File

@ -10,6 +10,7 @@
"test": "jest"
},
"dependencies": {
"@react-native-voice/voice": "^3.2.4",
"react": "18.2.0",
"react-native": "0.73.4"
},