try to fix sending text
This commit is contained in:
parent
169488818b
commit
e72b03f5dc
@ -5,7 +5,13 @@ import Voice from '@react-native-voice/voice';
|
|||||||
|
|
||||||
// import Config from 'react-native-config';
|
// import Config from 'react-native-config';
|
||||||
// process.env.TTS_BACKEND_URL = Config.TTS_BACKEND_URL;
|
// process.env.TTS_BACKEND_URL = Config.TTS_BACKEND_URL;
|
||||||
process.env.TTS_BACKEND_URL = "http://192.168.0.10:9008/asr"
|
// process.env.TTS_BACKEND_URL = "http://192.168.0.10:9008/asr"
|
||||||
|
process.env.TTS_BACKEND_URL = "https://tts.d-popov.com/asr"
|
||||||
|
|
||||||
|
const LLM_ENDPOINT = "https://ws.ai.d-popov.com/api/chat";
|
||||||
|
// const LLM_ENDPOINT = "http://192.168.0.11:11434/api/chat";
|
||||||
|
|
||||||
|
const LOG_ENDPOINT = "ws://192.168.0.11:9999";
|
||||||
|
|
||||||
class VoiceHandler extends Component {
|
class VoiceHandler extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@ -31,19 +37,23 @@ class VoiceHandler extends Component {
|
|||||||
onSpeechStart(e) {
|
onSpeechStart(e) {
|
||||||
this.setState({
|
this.setState({
|
||||||
started: '√',
|
started: '√',
|
||||||
|
status: "listening..."
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onSpeechRecognized(e) {
|
onSpeechRecognized(e) {
|
||||||
this.setState({
|
this.setState({
|
||||||
recognized: '√',
|
status: "Recognized"
|
||||||
});
|
});
|
||||||
|
console.log("onSpeechRecognized()");
|
||||||
}
|
}
|
||||||
|
|
||||||
onSpeechResults(e) {
|
onSpeechResults(e) {
|
||||||
this.setState({
|
this.setState({
|
||||||
results: e.value,
|
recognized: [...recognized, e.value],
|
||||||
|
status: this.state.status+ "\nonSpeechResults():" + e.value
|
||||||
});
|
});
|
||||||
|
console.log("onSpeechResults():" + e.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
async _startRecognizing(e) {
|
async _startRecognizing(e) {
|
||||||
@ -51,6 +61,7 @@ class VoiceHandler extends Component {
|
|||||||
recognized: '',
|
recognized: '',
|
||||||
started: '',
|
started: '',
|
||||||
results: [],
|
results: [],
|
||||||
|
status: "Starting...",
|
||||||
isRecording: true,
|
isRecording: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -69,28 +80,29 @@ class VoiceHandler extends Component {
|
|||||||
this.setState({
|
this.setState({
|
||||||
isRecording: false,
|
isRecording: false,
|
||||||
isProcessing:true,
|
isProcessing:true,
|
||||||
recognized: this.state.results.join(' ')
|
status: this.state.status+ "\nstopRecognizing()" + this.state.recognized
|
||||||
});
|
});
|
||||||
// Assuming you have the audio data, send it to your backend
|
// Assuming you have the audio data, send it to your backend
|
||||||
this._sendTranscribedTextToLLM(this.state.results.join(' '));
|
this._sendTranscribedTextToLLM("who is the president of thr USA");
|
||||||
|
//this._sendTranscribedTextToLLM(this.state.recognized);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async _sendTranscribedTextToLLM(transcribedText) {
|
async _sendTranscribedTextToLLM(transcribedText) {
|
||||||
|
|
||||||
const LLM_ENDPOINT = "http://192.168.0.11:11434/api/chat";
|
|
||||||
const model = "openhermes:latest";
|
const model = "openhermes:latest";
|
||||||
|
const prompt = "I have a question. Answer briefly and precise as an expert: \n" + transcribedText ;
|
||||||
const data = {
|
const data = {
|
||||||
model: model,
|
model: model,
|
||||||
messages: [{ role: "user", content: "I have a request: " + transcribedText }],
|
messages: [{ role: "user", content: `${prompt}`}],
|
||||||
stream: false,
|
stream: false,
|
||||||
};
|
};
|
||||||
this.setState({
|
this.setState({
|
||||||
status: ["sending to LLM:" + transcribedText]
|
status: this.state.status + "\nsending to LLM:\n" + prompt
|
||||||
})
|
})
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
console.log('sending text to LLM at ', LLM_ENDPOINT, ": '", transcribedText, "'");
|
console.log('sending text to LLM at ', LLM_ENDPOINT, ": '", transcribedText, "'");
|
||||||
const response = await fetch(LLM_ENDPOINT, {
|
const response = await fetch(LLM_ENDPOINT, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@ -165,7 +177,12 @@ class VoiceHandler extends Component {
|
|||||||
<Text>Status: {this.state.status}</Text>
|
<Text>Status: {this.state.status}</Text>
|
||||||
<Text>Recognized: {this.state.recognized}</Text>
|
<Text>Recognized: {this.state.recognized}</Text>
|
||||||
<Text>Started: {this.state.started}</Text>
|
<Text>Started: {this.state.started}</Text>
|
||||||
<Text>Results: {this.state.results.join(' ')}</Text>
|
<Text>Results: </Text>
|
||||||
|
<View>
|
||||||
|
{this.state.results.map((r, index) => (
|
||||||
|
<Text key={index}>{r}</Text>
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user