优化实时语音对话组件,处理异常

This commit is contained in:
RockYang
2024-10-23 18:04:09 +08:00
parent ad6e2dd370
commit 1fe1e40a43
4 changed files with 79 additions and 70 deletions

View File

@@ -305,19 +305,22 @@ onUnmounted(() => {
const hangUp = async () => {
try {
isConnected.value = false
// 停止播放拨号音乐
if (backgroundAudio.value?.currentTime) {
backgroundAudio.value?.pause()
backgroundAudio.value.currentTime = 0
}
// 断开客户端的连接
client.value.disconnect()
client.value.reset()
// 中断语音输入和输出服务
await wavRecorder.value.end()
await wavStreamPlayer.value.interrupt()
// 停止播放拨号音乐
backgroundAudio.value?.pause()
backgroundAudio.value.currentTime = 0
} catch (e) {
console.error(e)
} finally {
// 播放挂断音乐
hangUpAudio.value?.play()
emits('close')
} catch (e) {
console.error(e)
}
};