优化语音输入/普通文本输入

This commit is contained in:
minghanchen
2026-09-03 13:36:40 +08:00
parent 009d8ca73e
commit 32d179143f
26 changed files with 2318 additions and 53 deletions
+13 -3
View File
@@ -380,15 +380,21 @@
const { input } = elements();
if (!input) throw new Error("没有找到一句话编排输入框");
const cleanText = String(result.clean_text || result.text || "").trim();
const peripheralEligible = result.peripheral_routing?.execution_eligible === true;
const inputText = peripheralEligible
? String(result.routing_text || result.raw_text || cleanText).trim()
: cleanText;
const commands = Array.isArray(result.commands) ? result.commands : [];
if (!cleanText || commands.length === 0) {
if (!inputText || (commands.length === 0 && !peripheralEligible)) {
window.dispatchEvent(new CustomEvent("cognitive-agent:speech-result", { detail: result }));
return false;
}
speech.applyingResult = true;
input.value = cleanText.slice(0, input.maxLength || 1000);
input.value = inputText.slice(0, input.maxLength || 1000);
input.dataset.speechUncertain = String(result.uncertain === true);
input.dataset.speechExecutionEligible = String(result.execution_eligible === true);
input.dataset.speechExecutionEligible = String(
result.execution_eligible === true || peripheralEligible,
);
input.dataset.speechSemanticStatus = String(result.semantic_status || "");
input.dataset.speechValue = input.value.trim();
input.dataset.speechUtteranceId = String(result.utterance_id || "");
@@ -423,6 +429,10 @@
if (!applied) {
setPhase("success", `未形成可执行控制指令 · ${latency} ms`);
announce("已保留原始转录,但没有激活控制指令");
} else if (result.peripheral_routing?.execution_eligible === true) {
const count = Number(result.peripheral_routing.action_count || 1);
setPhase("success", `已识别为 ${count} 条外设控制指令 · ${latency} ms`);
announce("语音已匹配当前 NFC 外设的已学习控制指令");
} else if (result.semantic_status === "recognized_unsupported") {
setPhase("success", `已识别,但当前车辆能力不支持 · ${latency} ms`);
announce("已完整保留用户语义,但当前车辆能力不支持执行");