diff --git a/agent-mobile/artimobile/.env b/agent-mobile/artimobile/.env new file mode 100644 index 0000000..dc8dba7 --- /dev/null +++ b/agent-mobile/artimobile/.env @@ -0,0 +1 @@ +TTS_BACKEND_URL=http://192.168.0.10:9008/asr diff --git a/agent-mobile/artimobile/VoiceHandler.js b/agent-mobile/artimobile/VoiceHandler.js index c1e2181..c477f7f 100644 --- a/agent-mobile/artimobile/VoiceHandler.js +++ b/agent-mobile/artimobile/VoiceHandler.js @@ -2,6 +2,7 @@ import React, { Component } from 'react'; import { View, Text, Button } from 'react-native'; import Voice from '@react-native-voice/voice'; +import Config from 'react-native-config'; class VoiceHandler extends Component { constructor(props) { @@ -10,6 +11,7 @@ class VoiceHandler extends Component { recognized: '', started: '', results: [], + isRecording: false, }; Voice.onSpeechStart = this.onSpeechStart.bind(this); @@ -44,22 +46,57 @@ class VoiceHandler extends Component { recognized: '', started: '', results: [], + isRecording: true, }); try { - await Voice.start('en-US'); + await Voice.start('en-US'); // Start the voice recognition + } catch (error) { + console.error('There was an error starting voice recognition:', error); + this.setState({ + isRecording: false, + }); + } + } + async _stopRecognizing() { + try { + await Voice.stop(); + this.setState({ + isRecording: false, + }); + // Assuming you have the audio data, send it to your backend + this._sendAudioToBackend(this.state.results); } catch (e) { console.error(e); } } - + _sendAudioToBackend(results) { + // Placeholder: Convert `results` or actual audio data to a format acceptable by your backend + const formData = new FormData(); + // formData.append('audio', {uri: 'path_to_audio_file', type: 'audio/x-m4a', name: 'audio.m4a'}); + + fetch(process.env.TTS_BACKEND_URL, { + method: 'POST', + body: formData, + headers: { + 'Content-Type': 'multipart/form-data', + }, + }) + .then(response => response.text()) + .then(body => { + console.log('Audio sent to backend, response:', body); + }) + .catch(error => { + console.error('Failed to send audio:', error); + }); + } render() { return ( Press the button and start speaking.