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
+1 -1
View File
@@ -90,7 +90,7 @@ class Settings:
# 语音助手基础提示词(.env 设 DPM_S2S_INSTRUCTIONS 可覆盖;知识库内容由 rag 自动拼接)
S2S_INSTRUCTIONS = _env(
"DPM_S2S_INSTRUCTIONS",
"你是 PineSound 园区智能语音助手。可用工具:get_park_overview(园区实时数据)、"
"你是昆小园,昆明市大学生创业园的专属智能语音助手。可用工具:get_park_overview(园区实时数据)、"
"query_companies(企业名录)、control_display(大屏控制)、get_time(时间)。"
"涉及园区数据/企业/大屏控制时务必调用工具获取准确信息。请用简洁专业的中文回答,不超过三句话。",
)
+2 -2
View File
@@ -41,8 +41,8 @@ def _build_pool(stop_event: threading.Event):
"--qwen3_cloud_model", settings.S2S_TTS_MODEL,
"--qwen3_cloud_voice", settings.S2S_TTS_VOICE,
"--enable_live_transcription", "false",
"--thresh", "0.8",
"--min_silence_ms", "600",
"--thresh", "0.6",
"--min_silence_ms", "500",
"--min_speech_ms", "500",
"--log_level", settings.S2S_LOG_LEVEL,
]
+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');
});
});
})();
+19
View File
@@ -242,6 +242,25 @@
</div>
</div>
<!-- 语音 AI 测试(admin → 前端主动问候) -->
<div class="card">
<div class="card-header">
<div class="card-icon"><svg viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="#1D5DCE" stroke-width="1.6"><path d="M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z"/><path d="M19 10v2a7 7 0 0 1-14 0v-2M12 19v3"/></svg></div>
<h3>语音 AI 测试</h3>
</div>
<div class="form-inline">
<div class="form-group" style="flex:2;">
<label>问候语(前端将主动播报,测试语音 AI)</label>
<input type="text" id="voiceGreetText" value="您好呀,我是园区智能语音助手,有什么可以帮您?" style="width:100%;">
</div>
<div class="form-group">
<label>&nbsp;</label>
<button class="btn-primary" id="btnVoiceGreet" style="width:100%;">播报问候</button>
</div>
</div>
<div class="hint" id="voiceGreetHint">点击后展播端将自动进入语音对话页并主动播报上述问候(LLM 生成 + TTS),用于验证语音链路。</div>
</div>
<!-- 显示控制 -->
<div class="card">
<div class="card-header">