From 0dced68876c754a90cc29a3b503eb89b51083699 Mon Sep 17 00:00:00 2001 From: hubian <908234780@qq.com> Date: Tue, 21 Apr 2026 18:45:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=94=A8=E6=88=B7=E8=AF=AD=E9=9F=B3?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E6=94=AF=E6=8C=81=E7=82=B9=E5=87=BB=E6=92=AD?= =?UTF-8?q?=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logs/server.log | Bin 3015 -> 4685 bytes static/index.html | 85 ++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 78 insertions(+), 7 deletions(-) diff --git a/logs/server.log b/logs/server.log index 4dc08ec0c336a9c825eff549f18dac284533baf0..9171fd90005c2a25d7dca6e63629a004c2496258 100644 GIT binary patch delta 64 zcmX>uepY3I3X7$Qg~ddTZLDSn#)ig|=iE-@YGlD7;eJ8S-TAG*`O;%tuWw)?0Ha51j0J1GWqNe6Rmg43* R#(d7nMS|B@O-xN acc + buf.length, 0) / 16000); + const formData = new FormData(); formData.append('audio', audioBlob, 'recording.wav'); if (conversationId) { @@ -489,8 +526,8 @@ const data = await resp.json(); conversationId = data.conversation_id; - // 显示消息 - addMessage('user', '🎵 语音消息'); + // 显示消息(带音频播放) + addMessage('user', audioBlob, duration); addMessage('assistant', data.reply); recordStatus.textContent = '点击按钮开始录音'; @@ -503,7 +540,7 @@ } // 添加消息 - function addMessage(role, content) { + function addMessage(role, content, audioDuration = null) { // 移除提示 const hint = chatSection.querySelector('.hint'); if (hint) hint.remove(); @@ -514,16 +551,50 @@ const msg = document.createElement('div'); msg.className = `message ${role}`; - msg.innerHTML = ` -
${role === 'user' ? '我' : 'AI'}
-
${content}
- `; + + // 用户消息可能是音频 + if (role === 'user' && content instanceof Blob) { + const audioUrl = URL.createObjectURL(content); + const durationText = audioDuration ? `${audioDuration}s` : ''; + msg.innerHTML = ` +
+
+ +
+ `; + } else { + msg.innerHTML = ` +
${role === 'user' ? '我' : 'AI'}
+
${content}
+ `; + } chatSection.appendChild(msg); // 滚动到底部 chatSection.scrollTop = chatSection.scrollHeight; } + // 播放音频 + function playAudio(audioUrl, btn) { + const audio = new Audio(audioUrl); + const icon = btn.querySelector('.play-icon'); + + audio.onplay = () => { + icon.textContent = '🔊'; + btn.classList.add('playing'); + }; + + audio.onended = () => { + icon.textContent = '▶️'; + btn.classList.remove('playing'); + }; + + audio.play(); + } + // 显示加载 function showLoading() { const hint = chatSection.querySelector('.hint');