diff --git a/web/public/medias/calling.mp3 b/web/public/medias/calling.mp3 new file mode 100644 index 00000000..ff92bfb8 Binary files /dev/null and b/web/public/medias/calling.mp3 differ diff --git a/web/public/medias/hang-up.mp3 b/web/public/medias/hang-up.mp3 new file mode 100644 index 00000000..367973dd Binary files /dev/null and b/web/public/medias/hang-up.mp3 differ diff --git a/web/src/components/RealtimeConversation.vue b/web/src/components/RealtimeConversation.vue index a13da6cf..d4a72f4e 100644 --- a/web/src/components/RealtimeConversation.vue +++ b/web/src/components/RealtimeConversation.vue @@ -9,6 +9,14 @@
{{ connectingText }}
+ + @@ -126,12 +134,23 @@ const clientCanvasRef = ref(null); const serverCanvasRef = ref(null); const isConnected = ref(false); const isRecording = ref(false); - +const backgroundAudio = ref(null); +const hangUpAudio = ref(null); +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); +} const connect = async () => { if (isConnected.value) { return } - + // 播放背景音乐 + if (backgroundAudio.value) { + backgroundAudio.value.play().catch(error => { + console.error('播放失败,可能是浏览器的自动播放策略导致的:', error); + }); + } + // 模拟拨号延时 + await sleep(3000) try { await client.value.connect(); await wavRecorder.value.begin(); @@ -142,10 +161,12 @@ const connect = async () => { } isConnected.value = true; + backgroundAudio.value?.pause() + backgroundAudio.value.currentTime = 0 client.value.sendUserMessageContent([ { type: 'input_text', - text: '你好,我是老阳!', + text: '你好,我是极客学长!', }, ]); if (client.value.getTurnDetectionType() === 'server_vad') { @@ -283,10 +304,17 @@ onUnmounted(() => { // 挂断通话 const hangUp = async () => { try { - isConnected.value = false; - client.value.disconnect(); - await wavRecorder.value.end(); - await wavStreamPlayer.value.interrupt(); + isConnected.value = false + // 断开客户端的连接 + client.value.disconnect() + // 中断语音输入和输出服务 + await wavRecorder.value.end() + await wavStreamPlayer.value.interrupt() + // 停止播放拨号音乐 + backgroundAudio.value?.pause() + backgroundAudio.value.currentTime = 0 + // 播放挂断音乐 + hangUpAudio.value?.play() emits('close') } catch (e) { console.error(e) diff --git a/web/src/views/admin/ChatList.vue b/web/src/views/admin/ChatList.vue index fc94afc8..119b9a7b 100644 --- a/web/src/views/admin/ChatList.vue +++ b/web/src/views/admin/ChatList.vue @@ -145,13 +145,19 @@ -
+
+
+
@@ -354,15 +360,19 @@ const showMessages = (row) => { justify-content right } + .chat-detail { + max-height 90vh + overflow auto + } .chat-box { - overflow hidden + overflow auto // 变量定义 --content-font-size: 16px; --content-color: #c1c1c1; font-family: 'Microsoft YaHei', '微软雅黑', Arial, sans-serif; - height 90% + max-height 90vh .chat-line { // 隐藏滚动条 @@ -381,4 +391,4 @@ const showMessages = (row) => { } } - \ No newline at end of file +