From 7fd17ada8083ae04e06985362f31460ff74c226d Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Wed, 14 Feb 2024 18:27:15 +0200 Subject: [PATCH] compiled successfully --- agent-mobile/artimobile/VoiceHandler.js | 72 +++++++++++++++++++++++++ agent-mobile/artimobile/package.json | 1 + agent-mobile/idea.md | 17 ++++-- 3 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 agent-mobile/artimobile/VoiceHandler.js 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. +