This commit is contained in:
Dobromir Popov 2024-02-16 22:11:48 +02:00
parent c049dc3844
commit e5358562f4
2 changed files with 27 additions and 23 deletions

View File

@ -54,30 +54,14 @@ class VoiceHandler extends Component {
onSpeechResults(e) { onSpeechResults(e) {
this.setState({ this.setState({
results: e.value, results: e.value,
recognized: recognized + " " + e.value, // recognized: recognized + " " + e.value,
status: this.state.status+ "\nonSpeechResults():" + e.value // status: this.state.status+ "\nonSpeechResults():" + e.value
}); });
this.logRemote("onSpeechResults():" + e.value); this.logRemote("onSpeechResults():" + e.value.join(' '));
} }
async logRemote(message){
try{
fetch(process.env.LOG_ENDPOINT, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({"message":message}),
});
}
catch(e){
console.log("error logging:" + e);
}
console.log( message );
}
async _startRecognizing(e) { async _startRecognizing(e) {
this.setState({ this.setState({
recognized: '', recognized: '',
@ -99,18 +83,20 @@ class VoiceHandler extends Component {
async _stopRecognizing() { async _stopRecognizing() {
try { try {
await Voice.stop(); await Voice.stop();
const input = this.state.results.join(' ')
this.setState({ this.setState({
isRecording: false, isRecording: false,
isProcessing:true, isProcessing:true,
recognized: this.state.results.join(' ') recognized: input
}); });
// Assuming you have the audio data, send it to your backend // Assuming you have the audio data, send it to your backend
// this._sendTranscribedTextToLLM("who is the president of thr USA"); // this._sendTranscribedTextToLLM("who is the president of thr USA");
this._sendTranscribedTextToLLM(this.state.results.join(' ')); this._sendTranscribedTextToLLM(input);
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} }
} }
async _sendTranscribedTextToLLM(transcribedText) { async _sendTranscribedTextToLLM(transcribedText) {
const model = "openhermes:latest"; const model = "openhermes:latest";
@ -145,7 +131,7 @@ class VoiceHandler extends Component {
// Update your app state or UI based on LLM response // Update your app state or UI based on LLM response
this.setState(prevState => ({ this.setState(prevState => ({
status: "LLM responded", status: "LLM responded",
results: [...prevState.results, responseJson.message.content], // Append the response to the existing results response: [...prevState.response, responseJson.message.content], // Append the response to the existing results
})); }));
} }
} else { } else {
@ -188,6 +174,22 @@ class VoiceHandler extends Component {
console.error('Failed to send audio:', error); console.error('Failed to send audio:', error);
}); });
} }
async logRemote(message){
try{
fetch(process.env.LOG_ENDPOINT, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({"message":message}),
});
}
catch(e){
console.log("error logging:" + e);
}
console.log( message );
}
render() { render() {
return ( return (
<View> <View>
@ -206,6 +208,8 @@ class VoiceHandler extends Component {
<Text key={index}>{r}</Text> <Text key={index}>{r}</Text>
))} ))}
</View> </View>
<Text>AI: </Text>
</View> </View>
); );
} }

View File

@ -120,7 +120,7 @@ app.get('/', (req, res) => {
//accept LOG messages on /log //accept LOG messages on /log
app.post('/log', (req, res) => { app.post('/log', (req, res) => {
console.log("log>" + req.body.message); console.log("log["+new Date().toISOString() + '] ' + req.body.message);
res.send('OK', 200, { 'Content-Type': 'text/plain' }); res.send('OK', 200, { 'Content-Type': 'text/plain' });
}); });