优化AI配置,模拟搜索需求
This commit is contained in:
parent
e0f37b6634
commit
4b32c459b1
|
|
@ -9,36 +9,21 @@
|
|||
<div class="voice-control-container">
|
||||
<div class="status-text">点击开始语音识别</div>
|
||||
<button class="voice-btn" id="voice-btn" @click="toggleListening">
|
||||
<svg
|
||||
style="
|
||||
<svg style="
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
transform: translate3d(-50%, -50%, 0);
|
||||
"
|
||||
t="1756171270753"
|
||||
class="icon"
|
||||
viewBox="0 0 1024 1024"
|
||||
version="1.1"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
p-id="14442"
|
||||
width="42"
|
||||
height="70"
|
||||
>
|
||||
" t="1756171270753" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"
|
||||
p-id="14442" width="42" height="70">
|
||||
<path
|
||||
d="M704 192v368c0 52.8-21.6 100.8-56.4 135.6S564.8 752 512 752c-105.6 0-192-86.4-192-192V192C320 86.4 406.4 0 512 0s192 86.4 192 192z"
|
||||
p-id="14443"
|
||||
data-spm-anchor-id="a313x.search_index.0.i2.72cc3a81bxN4ca"
|
||||
class="selected"
|
||||
fill="#ffffff"
|
||||
></path>
|
||||
p-id="14443" data-spm-anchor-id="a313x.search_index.0.i2.72cc3a81bxN4ca" class="selected" fill="#ffffff">
|
||||
</path>
|
||||
<path
|
||||
d="M816 496v144c0 2.8-0.4 5.6-1.1 8.4-18.5 68.2-58.9 126.1-112.3 166.9-43.5 33.2-95.6 55.2-151.6 62.2-4 0.5-7 3.9-7 7.9V944c0 8.8 7.2 16 16 16h80c35.3 0 64 28.7 64 64H320c0-35.3 28.7-64 64-64h80c8.8 0 16-7.2 16-16v-58.5c0-4-3-7.4-7-7.9-124.8-15.7-230.3-105.5-263.9-229.2-0.7-2.7-1.1-5.6-1.1-8.4V496.7c0-17.4 13.7-32.2 31.1-32.7 18.1-0.5 32.9 14 32.9 32v129.8c0 6.9 1.1 13.8 3.3 20.3C309.3 746.9 404.6 816 512 816s202.7-69.1 236.7-169.9c2.2-6.5 3.3-13.4 3.3-20.3V496.7c0-17.4 13.7-32.2 31.1-32.7 18.1-0.5 32.9 14 32.9 32z"
|
||||
p-id="14444"
|
||||
data-spm-anchor-id="a313x.search_index.0.i3.72cc3a81bxN4ca"
|
||||
class="selected"
|
||||
fill="#ffffff"
|
||||
></path>
|
||||
p-id="14444" data-spm-anchor-id="a313x.search_index.0.i3.72cc3a81bxN4ca" class="selected" fill="#ffffff">
|
||||
</path>
|
||||
</svg>
|
||||
<div class="pulse-ring"></div>
|
||||
</button>
|
||||
|
|
@ -47,10 +32,9 @@
|
|||
<div class="command-action" v-for="item in action">
|
||||
{{
|
||||
"执行操作:" +
|
||||
`${item.command} ${
|
||||
item.params && item.params.keyword
|
||||
? "-" + item.params.keyword
|
||||
: ""
|
||||
`${item.command} ${item.params && item.params.keyword
|
||||
? "-" + item.params.keyword
|
||||
: ""
|
||||
}`
|
||||
}}
|
||||
</div>
|
||||
|
|
@ -58,7 +42,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<script setup>
|
||||
<script setup>
|
||||
import { ref, onMounted, watch, nextTick } from "vue";
|
||||
|
||||
const config = {
|
||||
|
|
@ -159,7 +143,8 @@ const config = {
|
|||
params: [],
|
||||
isIframe: true,
|
||||
},
|
||||
|
||||
|
||||
// 用于测试搜索设备管理列表
|
||||
{
|
||||
command: "search_project",
|
||||
description: "搜索",
|
||||
|
|
@ -172,6 +157,7 @@ const config = {
|
|||
description: "要输入的项目名称",
|
||||
},
|
||||
],
|
||||
isIframe: true,
|
||||
},
|
||||
{
|
||||
command: "input_project_name",
|
||||
|
|
@ -208,7 +194,7 @@ const listenStatus = ref(false);
|
|||
const props = defineProps({
|
||||
config: {
|
||||
type: Object,
|
||||
default: () => {},
|
||||
default: () => { },
|
||||
},
|
||||
});
|
||||
|
||||
|
|
@ -231,6 +217,7 @@ class VoiceControl {
|
|||
setupSpeechRecognition() {
|
||||
const SpeechRecognition =
|
||||
window.SpeechRecognition || window.webkitSpeechRecognition;
|
||||
console.log("检测是否支持语音识别", SpeechRecognition);
|
||||
if (!SpeechRecognition) {
|
||||
this.showError("您的浏览器不支持语音识别API");
|
||||
return;
|
||||
|
|
@ -257,13 +244,15 @@ class VoiceControl {
|
|||
};
|
||||
|
||||
this.recognition.onresult = async (event) => {
|
||||
|
||||
// 避免同时处理多个结果
|
||||
if (this.isProcessing) return;
|
||||
|
||||
// 获取最新结果索引
|
||||
const lastResultIndex = event.results.length - 1;
|
||||
const result = event.results[lastResultIndex];
|
||||
const transcript = result[0].transcript;
|
||||
let transcript = result[0].transcript;
|
||||
|
||||
|
||||
this.showTranscript(transcript);
|
||||
|
||||
|
|
@ -322,6 +311,17 @@ class VoiceControl {
|
|||
this.recognition.onend = () => {
|
||||
// 快速重启识别,减少等待时间
|
||||
console.log("====> 走到这 ", listenStatus.value);
|
||||
// TODO 模拟指令
|
||||
setTimeout(async () => {
|
||||
const sequence = await this.queryDeepSeek("搜索项目风冷热泵");
|
||||
this.executeSequence(sequence);
|
||||
if (sequence && sequence.sequence && sequence.sequence.length > 0) {
|
||||
this.callback(sequence.sequence);
|
||||
} else {
|
||||
this.callback([]);
|
||||
}
|
||||
}, 100);
|
||||
// END TODO
|
||||
|
||||
if (listenStatus.value) {
|
||||
// 只有在用户希望继续聆听时才重启
|
||||
|
|
@ -346,6 +346,8 @@ class VoiceControl {
|
|||
}
|
||||
|
||||
async queryDeepSeek(userQuery) {
|
||||
console.log("连接AI ", userQuery);
|
||||
|
||||
if (!this.apiKey) {
|
||||
throw new Error("请先设置DeepSeek API密钥");
|
||||
}
|
||||
|
|
@ -419,9 +421,10 @@ class VoiceControl {
|
|||
|
||||
// 解析JSON响应
|
||||
let result = JSON.parse(content);
|
||||
console.log(result, "=====> deepseek 返回");
|
||||
console.log(result, "=====> deepseek 返回", data);
|
||||
// 验证响应结构
|
||||
if (!result.sequence || !Array.isArray(result.sequence)) {
|
||||
if (!result.sequence || !Array.isArray(result.sequence) || result.sequence.length === 0) {
|
||||
console.log(result, "DeepSeek返回了无效的指令序列格式");
|
||||
throw new Error("DeepSeek返回了无效的指令序列格式");
|
||||
}
|
||||
|
||||
|
|
@ -573,7 +576,7 @@ class VoiceControl {
|
|||
document.querySelector(".status-text").textContent = "正在聆听...";
|
||||
} else {
|
||||
voiceBtn.classList.remove("listening");
|
||||
document.querySelector(".status-text").textContent = "点击开始语音识别";
|
||||
document.querySelector(".status-text").textContent = "点击开始语音识别2-1";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -597,29 +600,41 @@ const callBackFun = (data) => {
|
|||
action.value = data;
|
||||
};
|
||||
const toggleListening = () => {
|
||||
console.log("开始语音", listenStatus);
|
||||
if (!voiceControl.value) {
|
||||
alert("请先初始化语音控制系统");
|
||||
return;
|
||||
}
|
||||
|
||||
if (listenStatus.value) {
|
||||
try {
|
||||
if (listenStatus.value) {
|
||||
listenStatus.value = false;
|
||||
voiceControl.value.stopListening();
|
||||
const voiceBtn = document.getElementById("voice-btn");
|
||||
if (voiceBtn) {
|
||||
voiceBtn.classList.remove("listening");
|
||||
}
|
||||
} else {
|
||||
listenStatus.value = true;
|
||||
voiceControl.value.startListening();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("语音识别操作失败:", error);
|
||||
// 重置状态
|
||||
listenStatus.value = false;
|
||||
voiceControl.value.stopListening();
|
||||
const voiceBtn = document.getElementById("voice-btn");
|
||||
if (voiceBtn) {
|
||||
voiceBtn.classList.remove("listening");
|
||||
}
|
||||
} else {
|
||||
listenStatus.value = true;
|
||||
voiceControl.value.startListening();
|
||||
alert("语音识别操作失败,请稍后再试");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
initVoiceControl();
|
||||
});
|
||||
</script>
|
||||
<style scoped>
|
||||
<style scoped>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
|
|
@ -766,9 +781,11 @@ body {
|
|||
0% {
|
||||
box-shadow: 0 0 0 0 rgba(255, 94, 98, 0.7);
|
||||
}
|
||||
|
||||
70% {
|
||||
box-shadow: 0 0 0 15px rgba(255, 94, 98, 0);
|
||||
}
|
||||
|
||||
100% {
|
||||
box-shadow: 0 0 0 0 rgba(255, 94, 98, 0);
|
||||
}
|
||||
|
|
@ -779,6 +796,7 @@ body {
|
|||
transform: scale(1);
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
100% {
|
||||
transform: scale(2.5);
|
||||
opacity: 0;
|
||||
|
|
@ -789,6 +807,7 @@ body {
|
|||
from {
|
||||
transform: scale(1);
|
||||
}
|
||||
|
||||
to {
|
||||
transform: scale(1.3);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue