优化AI配置,模拟搜索需求
This commit is contained in:
parent
e0f37b6634
commit
4b32c459b1
|
|
@ -9,36 +9,21 @@
|
||||||
<div class="voice-control-container">
|
<div class="voice-control-container">
|
||||||
<div class="status-text">点击开始语音识别</div>
|
<div class="status-text">点击开始语音识别</div>
|
||||||
<button class="voice-btn" id="voice-btn" @click="toggleListening">
|
<button class="voice-btn" id="voice-btn" @click="toggleListening">
|
||||||
<svg
|
<svg style="
|
||||||
style="
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 50%;
|
left: 50%;
|
||||||
top: 50%;
|
top: 50%;
|
||||||
transform: translate3d(-50%, -50%, 0);
|
transform: translate3d(-50%, -50%, 0);
|
||||||
"
|
" t="1756171270753" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"
|
||||||
t="1756171270753"
|
p-id="14442" width="42" height="70">
|
||||||
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
|
<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"
|
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"
|
p-id="14443" data-spm-anchor-id="a313x.search_index.0.i2.72cc3a81bxN4ca" class="selected" fill="#ffffff">
|
||||||
data-spm-anchor-id="a313x.search_index.0.i2.72cc3a81bxN4ca"
|
</path>
|
||||||
class="selected"
|
|
||||||
fill="#ffffff"
|
|
||||||
></path>
|
|
||||||
<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"
|
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"
|
p-id="14444" data-spm-anchor-id="a313x.search_index.0.i3.72cc3a81bxN4ca" class="selected" fill="#ffffff">
|
||||||
data-spm-anchor-id="a313x.search_index.0.i3.72cc3a81bxN4ca"
|
</path>
|
||||||
class="selected"
|
|
||||||
fill="#ffffff"
|
|
||||||
></path>
|
|
||||||
</svg>
|
</svg>
|
||||||
<div class="pulse-ring"></div>
|
<div class="pulse-ring"></div>
|
||||||
</button>
|
</button>
|
||||||
|
|
@ -47,8 +32,7 @@
|
||||||
<div class="command-action" v-for="item in action">
|
<div class="command-action" v-for="item in action">
|
||||||
{{
|
{{
|
||||||
"执行操作:" +
|
"执行操作:" +
|
||||||
`${item.command} ${
|
`${item.command} ${item.params && item.params.keyword
|
||||||
item.params && item.params.keyword
|
|
||||||
? "-" + item.params.keyword
|
? "-" + item.params.keyword
|
||||||
: ""
|
: ""
|
||||||
}`
|
}`
|
||||||
|
|
@ -160,6 +144,7 @@ const config = {
|
||||||
isIframe: true,
|
isIframe: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 用于测试搜索设备管理列表
|
||||||
{
|
{
|
||||||
command: "search_project",
|
command: "search_project",
|
||||||
description: "搜索",
|
description: "搜索",
|
||||||
|
|
@ -172,6 +157,7 @@ const config = {
|
||||||
description: "要输入的项目名称",
|
description: "要输入的项目名称",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
isIframe: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
command: "input_project_name",
|
command: "input_project_name",
|
||||||
|
|
@ -231,6 +217,7 @@ class VoiceControl {
|
||||||
setupSpeechRecognition() {
|
setupSpeechRecognition() {
|
||||||
const SpeechRecognition =
|
const SpeechRecognition =
|
||||||
window.SpeechRecognition || window.webkitSpeechRecognition;
|
window.SpeechRecognition || window.webkitSpeechRecognition;
|
||||||
|
console.log("检测是否支持语音识别", SpeechRecognition);
|
||||||
if (!SpeechRecognition) {
|
if (!SpeechRecognition) {
|
||||||
this.showError("您的浏览器不支持语音识别API");
|
this.showError("您的浏览器不支持语音识别API");
|
||||||
return;
|
return;
|
||||||
|
|
@ -257,13 +244,15 @@ class VoiceControl {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.recognition.onresult = async (event) => {
|
this.recognition.onresult = async (event) => {
|
||||||
|
|
||||||
// 避免同时处理多个结果
|
// 避免同时处理多个结果
|
||||||
if (this.isProcessing) return;
|
if (this.isProcessing) return;
|
||||||
|
|
||||||
// 获取最新结果索引
|
// 获取最新结果索引
|
||||||
const lastResultIndex = event.results.length - 1;
|
const lastResultIndex = event.results.length - 1;
|
||||||
const result = event.results[lastResultIndex];
|
const result = event.results[lastResultIndex];
|
||||||
const transcript = result[0].transcript;
|
let transcript = result[0].transcript;
|
||||||
|
|
||||||
|
|
||||||
this.showTranscript(transcript);
|
this.showTranscript(transcript);
|
||||||
|
|
||||||
|
|
@ -322,6 +311,17 @@ class VoiceControl {
|
||||||
this.recognition.onend = () => {
|
this.recognition.onend = () => {
|
||||||
// 快速重启识别,减少等待时间
|
// 快速重启识别,减少等待时间
|
||||||
console.log("====> 走到这 ", listenStatus.value);
|
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) {
|
if (listenStatus.value) {
|
||||||
// 只有在用户希望继续聆听时才重启
|
// 只有在用户希望继续聆听时才重启
|
||||||
|
|
@ -346,6 +346,8 @@ class VoiceControl {
|
||||||
}
|
}
|
||||||
|
|
||||||
async queryDeepSeek(userQuery) {
|
async queryDeepSeek(userQuery) {
|
||||||
|
console.log("连接AI ", userQuery);
|
||||||
|
|
||||||
if (!this.apiKey) {
|
if (!this.apiKey) {
|
||||||
throw new Error("请先设置DeepSeek API密钥");
|
throw new Error("请先设置DeepSeek API密钥");
|
||||||
}
|
}
|
||||||
|
|
@ -419,9 +421,10 @@ class VoiceControl {
|
||||||
|
|
||||||
// 解析JSON响应
|
// 解析JSON响应
|
||||||
let result = JSON.parse(content);
|
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返回了无效的指令序列格式");
|
throw new Error("DeepSeek返回了无效的指令序列格式");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -573,7 +576,7 @@ class VoiceControl {
|
||||||
document.querySelector(".status-text").textContent = "正在聆听...";
|
document.querySelector(".status-text").textContent = "正在聆听...";
|
||||||
} else {
|
} else {
|
||||||
voiceBtn.classList.remove("listening");
|
voiceBtn.classList.remove("listening");
|
||||||
document.querySelector(".status-text").textContent = "点击开始语音识别";
|
document.querySelector(".status-text").textContent = "点击开始语音识别2-1";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -597,11 +600,12 @@ const callBackFun = (data) => {
|
||||||
action.value = data;
|
action.value = data;
|
||||||
};
|
};
|
||||||
const toggleListening = () => {
|
const toggleListening = () => {
|
||||||
|
console.log("开始语音", listenStatus);
|
||||||
if (!voiceControl.value) {
|
if (!voiceControl.value) {
|
||||||
alert("请先初始化语音控制系统");
|
alert("请先初始化语音控制系统");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
if (listenStatus.value) {
|
if (listenStatus.value) {
|
||||||
listenStatus.value = false;
|
listenStatus.value = false;
|
||||||
voiceControl.value.stopListening();
|
voiceControl.value.stopListening();
|
||||||
|
|
@ -613,6 +617,17 @@ const toggleListening = () => {
|
||||||
listenStatus.value = true;
|
listenStatus.value = true;
|
||||||
voiceControl.value.startListening();
|
voiceControl.value.startListening();
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("语音识别操作失败:", error);
|
||||||
|
// 重置状态
|
||||||
|
listenStatus.value = false;
|
||||||
|
const voiceBtn = document.getElementById("voice-btn");
|
||||||
|
if (voiceBtn) {
|
||||||
|
voiceBtn.classList.remove("listening");
|
||||||
|
}
|
||||||
|
alert("语音识别操作失败,请稍后再试");
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
|
@ -766,9 +781,11 @@ body {
|
||||||
0% {
|
0% {
|
||||||
box-shadow: 0 0 0 0 rgba(255, 94, 98, 0.7);
|
box-shadow: 0 0 0 0 rgba(255, 94, 98, 0.7);
|
||||||
}
|
}
|
||||||
|
|
||||||
70% {
|
70% {
|
||||||
box-shadow: 0 0 0 15px rgba(255, 94, 98, 0);
|
box-shadow: 0 0 0 15px rgba(255, 94, 98, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
100% {
|
100% {
|
||||||
box-shadow: 0 0 0 0 rgba(255, 94, 98, 0);
|
box-shadow: 0 0 0 0 rgba(255, 94, 98, 0);
|
||||||
}
|
}
|
||||||
|
|
@ -779,6 +796,7 @@ body {
|
||||||
transform: scale(1);
|
transform: scale(1);
|
||||||
opacity: 0.8;
|
opacity: 0.8;
|
||||||
}
|
}
|
||||||
|
|
||||||
100% {
|
100% {
|
||||||
transform: scale(2.5);
|
transform: scale(2.5);
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
|
|
@ -789,6 +807,7 @@ body {
|
||||||
from {
|
from {
|
||||||
transform: scale(1);
|
transform: scale(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
to {
|
to {
|
||||||
transform: scale(1.3);
|
transform: scale(1.3);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue