| | |
| | | import { ElMessage } from 'element-plus'; |
| | | import type { ComputedRef } from 'vue'; |
| | | import { computed, nextTick, ref } from 'vue'; |
| | | import { computed, nextTick, onDeactivated, ref } from 'vue'; |
| | | // import useClipboard from 'vue-clipboard3'; |
| | | import { onClickOutside, useClipboard } from '@vueuse/core'; |
| | | import type { ChatMessage } from '../model/types'; |
| | | import markdownToTxt from 'markdown-to-txt'; |
| | | import { AnswerState, AnswerType, RoleEnum } from '../model/types'; |
| | | import { SetHistoryAnswerState } from '/@/api/ai/chat'; |
| | | import { isSharePage } from '/@/stores/chatRoom'; |
| | | import BrowserSpeechSynthesis from '/@/utils/speech/synthesis'; |
| | | import markdownToTxt from 'markdown-to-txt'; |
| | | export type AssistantContentOptOption = { |
| | | sendChatMessage: any; |
| | | }; |
| | | const activeSpeakItem = ref(null); |
| | | |
| | | export const useAssistantContentOpt = (option: AssistantContentOptOption) => { |
| | | const isSpeaking = ref(false); |
| | |
| | | }); |
| | | }; |
| | | |
| | | const isItemSpeaking = (item) => { |
| | | const checkSpeak = activeSpeakItem.value === item && isSpeaking.value; |
| | | return checkSpeak; |
| | | }; |
| | | |
| | | onClickOutside( |
| | | computed(() => feedbackPanelRef.value?.[curFeedbackIndex.value]), |
| | | (e) => { |
| | |
| | | |
| | | let isEnterStop = false; |
| | | |
| | | const resetSpeak = () => { |
| | | isSpeaking.value = false; |
| | | isEnterStop = false; |
| | | const instance = BrowserSpeechSynthesis.getInstance(); |
| | | instance.cancel(); |
| | | activeSpeakItem.value = null; |
| | | }; |
| | | |
| | | const speechClick = (item) => { |
| | | if (!checkIsText(item)) return; |
| | | if (activeSpeakItem.value !== item) { |
| | | resetSpeak(); |
| | | } |
| | | isSpeaking.value = !isSpeaking.value; |
| | | if (isSpeaking.value) { |
| | | startSpeechClick(item); |
| | |
| | | }; |
| | | |
| | | const startSpeechClick = (item) => { |
| | | activeSpeakItem.value = item; |
| | | |
| | | const instance = BrowserSpeechSynthesis.getInstance(); |
| | | instance.onEnd(() => { |
| | | resetSpeak(); |
| | | }); |
| | | if (isEnterStop) { |
| | | instance.resume(); |
| | | } else { |
| | |
| | | instance.pause(); |
| | | }; |
| | | |
| | | onDeactivated(() => { |
| | | const instance = BrowserSpeechSynthesis.getInstance(); |
| | | instance.cancel(); |
| | | }); |
| | | |
| | | return { |
| | | copyClick, |
| | | likeClick, |
| | |
| | | showFixQuestion, |
| | | speechClick, |
| | | isSpeaking, |
| | | isItemSpeaking, |
| | | checkIsText, |
| | | }; |
| | | }; |