feat: 添加语音 AI 主动问候功能,优化问候文本发送逻辑和音频处理参数
This commit is contained in:
@@ -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');
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user