compiled successfully
This commit is contained in:
parent
8edaa4b937
commit
7fd17ada80
72
agent-mobile/artimobile/VoiceHandler.js
Normal file
72
agent-mobile/artimobile/VoiceHandler.js
Normal 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;
|
@ -10,6 +10,7 @@
|
|||||||
"test": "jest"
|
"test": "jest"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@react-native-voice/voice": "^3.2.4",
|
||||||
"react": "18.2.0",
|
"react": "18.2.0",
|
||||||
"react-native": "0.73.4"
|
"react-native": "0.73.4"
|
||||||
},
|
},
|
||||||
|
@ -25,7 +25,7 @@ java -version
|
|||||||
#:host
|
#:host
|
||||||
sudo apt-get install adb
|
sudo apt-get install adb
|
||||||
|
|
||||||
#: emu
|
# : emu androidusr
|
||||||
cd /home/androidusr/tmp && npx react-native run-android
|
cd /home/androidusr/tmp && npx react-native run-android
|
||||||
# RUN ln -s ${ANDROID_HOME}/emulator/emulator /usr/bin/
|
# RUN ln -s ${ANDROID_HOME}/emulator/emulator /usr/bin/
|
||||||
/emulator/emulator -list-avds
|
/emulator/emulator -list-avds
|
||||||
@ -38,8 +38,19 @@ RUN apt-get update && \
|
|||||||
# Set JAVA_HOME environment variable to Java 17
|
# Set JAVA_HOME environment variable to Java 17
|
||||||
ENV JAVA_HOME /usr/lib/jvm/java-17-openjdk-amd64
|
ENV JAVA_HOME /usr/lib/jvm/java-17-openjdk-amd64
|
||||||
|
|
||||||
|
|
||||||
wget https://download.java.net/java/GA/jdk21.0.2/f2283984656d49d69e91c558476027ac/13/GPL/openjdk-21.0.2_linux-x64_bin.tar.gz
|
wget https://download.java.net/java/GA/jdk21.0.2/f2283984656d49d69e91c558476027ac/13/GPL/openjdk-21.0.2_linux-x64_bin.tar.gz
|
||||||
tar -xzf openjdk-21.0.2_linux-x64_bin.tar.gz -C /home/androidusr/jdk
|
tar -xzf openjdk-21.0.2_linux-x64_bin.tar.gz -C /home/androidusr/jdk
|
||||||
export JAVA_HOME=/home/androidusr/jdk
|
export JAVA_HOME=/home/androidusr/jdk/jdk-21.0.2
|
||||||
export PATH=$JAVA_HOME/bin:$PATH
|
export PATH=$JAVA_HOME/bin:$PATH
|
||||||
source ~/.bashrc
|
source ~/.bashrc
|
||||||
|
|
||||||
|
cd /home/androidusr/tmp
|
||||||
|
npx react-native start
|
||||||
|
npx react-native run-android
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# install voice on dev env (emulator)
|
||||||
|
npm install @react-native-voice/voice
|
||||||
|
react-native link @react-native-voice/voice
|
||||||
|
Loading…
x
Reference in New Issue
Block a user