diff --git a/agent-mobile/artimobile/VoiceHandler.js b/agent-mobile/artimobile/VoiceHandler.js new file mode 100644 index 0000000..c1e2181 --- /dev/null +++ b/agent-mobile/artimobile/VoiceHandler.js @@ -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 ( + + Press the button and start speaking. +