feat: 添加语音 AI 主动问候功能,优化问候文本发送逻辑和音频处理参数

This commit is contained in:
Pine
2026-08-18 08:20:44 +08:00
parent 49c0975fdc
commit f75fe7b9b3
7 changed files with 97 additions and 12 deletions
+31
View File
@@ -358,3 +358,34 @@
post('/api/delete', { path: current.path }, function () { closePreview(); reload('已删除'); });
});
})();
/* ---------- 语音 AI 测试(主动问候) ---------- */
(function () {
var greetBtn = document.getElementById('btnVoiceGreet');
var greetInput = document.getElementById('voiceGreetText');
var greetHint = document.getElementById('voiceGreetHint');
if (!greetBtn || !greetInput) return;
greetBtn.addEventListener('click', function () {
var text = (greetInput.value || '').trim();
if (!text) { toast('请输入问候语'); return; }
greetBtn.disabled = true;
greetBtn.textContent = '发送中…';
fetch('/api/display/command', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ action: 'voice_start', params: { text: text } }),
})
.then(function (r) { return r.json().catch(function () { return {}; }); })
.then(function (d) {
greetBtn.disabled = false;
greetBtn.textContent = '播报问候';
if (d && d.ok === false) { toast('发送失败:MQTT 未发布(' + (d.error || '未知') + '', 'error'); return; }
if (greetHint) greetHint.textContent = '✅ 已发送:展播端将进入语音对话页并主动播报「' + text + '」,请留意展播端声音。';
toast('语音问候已发送');
})
.catch(function () {
greetBtn.disabled = false;
greetBtn.textContent = '播报问候';
toast('发送失败:后端不可达', 'error');
});
});
})();