Merge branch 'main' of gitee.com:blackfox/geekai-plus

This commit is contained in:
RockYang 2024-10-21 18:21:21 +08:00
commit bb63f23414
4 changed files with 49 additions and 11 deletions

Binary file not shown.

Binary file not shown.

View File

@ -9,6 +9,14 @@
<div class="phone"></div>
</div>
<div class="status-text">{{ connectingText }}</div>
<audio ref="backgroundAudio" loop>
<source src="/medias/calling.mp3" type="audio/mp3" />
您的浏览器不支持音频元素
</audio>
<audio ref="hangUpAudio">
<source src="/medias/hang-up.mp3" type="audio/mp3" />
您的浏览器不支持音频元素
</audio>
</el-container>
<!-- conversation body -->
@ -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)

View File

@ -145,13 +145,19 @@
<el-dialog
v-model="showContentDialog"
title="消息详情"
class="chat-dialog"
style="--el-dialog-width:60%"
>
<div class="chat-detail">
<div class="chat-line" v-html="dialogContent"></div>
</div>
</el-dialog>
<el-dialog
v-model="showChatItemDialog"
title="对话详情"
class="chat-dialog"
style="--el-dialog-width:60%"
>
<div class="chat-box chat-page">
<div v-for="item in messages" :key="item.id">
@ -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 {
//