diff --git a/ui/src/components/ai-chat/OperationButton.vue b/ui/src/components/ai-chat/OperationButton.vue index dc8cb367d..08b48a409 100644 --- a/ui/src/components/ai-chat/OperationButton.vue +++ b/ui/src/components/ai-chat/OperationButton.vue @@ -8,8 +8,11 @@ - - + + + + + @@ -102,6 +105,7 @@ const props = defineProps({ const emit = defineEmits(['update:data', 'regeneration']) const audioPlayer = ref(null) +const audioPlayerStatus = ref(false) const buttonData = ref(props.data) const loading = ref(false) @@ -151,6 +155,12 @@ const playAnswerText = (text: string) => { window.speechSynthesis.speak(utterance) } if (props.tts_type === 'TTS') { + audioPlayerStatus.value = true + // 恢复上次暂停的播放 + if (audioPlayer.value?.src) { + audioPlayer.value?.play() + return + } applicationApi .postTextToSpeech(props.applicationId as string, { text: text }, loading) .then((res: any) => { @@ -171,6 +181,9 @@ const playAnswerText = (text: string) => { if (audioPlayer.value instanceof HTMLAudioElement) { audioPlayer.value.src = url audioPlayer.value.play() // 自动播放音频 + audioPlayer.value.onended = () => { + audioPlayerStatus.value = false + } } else { console.error('audioPlayer.value is not an instance of HTMLAudioElement') } @@ -180,5 +193,12 @@ const playAnswerText = (text: string) => { }) } } + +const pausePlayAnswerText = () => { + if (props.tts_type === 'TTS') { + audioPlayerStatus.value = false + audioPlayer.value?.pause() + } +}