From d54a12e360aaaade04e361ccccf8f20b1cd4fefd Mon Sep 17 00:00:00 2001 From: liou Date: Sat, 15 Apr 2023 02:06:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E8=AF=AD=E9=80=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Content.vue | 11 ++++++++--- src/components/NewChat.vue | 9 +++++++++ src/hooks/useSpeechService.ts | 25 +++++++++++++++++++++++++ src/stores/index.ts | 2 ++ 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/components/Content.vue b/src/components/Content.vue index 7874160..1163fd7 100644 --- a/src/components/Content.vue +++ b/src/components/Content.vue @@ -18,9 +18,11 @@ const { el, scrollToBottom } = useScroll() const { language, voiceName, + rate, isRecognizing, recognizeSpeech, textToSpeak, + ssmlToSpeak, isSynthesizing, } = useSpeechService(getOpenAzureKey(), getOpenAzureRegion(), store.allLanguage as any) @@ -33,13 +35,14 @@ const speakIndex = ref(0) // record speak const translateIndex = ref(0) // record translate const messageLength = computed(() => store.getConversationsByCurrentProps('chatMessages').length) -const chatMessages = computed(() => store.getConversationsByCurrentProps('chatMessages').slice(1)) +const chatMessages = computed(() => store.getConversationsByCurrentProps('chatMessages').slice(1))// 除去第一条系统设置的消息 const currentChatMessages = computed(() => store.getConversationsByCurrentProps('chatMessages')) const currentKey = computed(() => store.currentKey) const currentName = computed(() => store.getConversationsByCurrentProps('name')) const currentAvatar = computed(() => store.getConversationsByCurrentProps('avatar')) const currentLanguage = computed(() => store.getConversationsByCurrentProps('language')) const currentVoice = computed(() => store.getConversationsByCurrentProps('voice')) +const currentRate = computed(() => store.getConversationsByCurrentProps('rate')) useTitle(currentName) @@ -47,7 +50,8 @@ useTitle(currentName) watch(messageLength, () => nextTick(() => scrollToBottom())) watch(currentKey, () => { language.value = currentLanguage.value as any - voiceName.value = currentVoice.value as any + voiceName.value = currentVoice.value + rate.value = currentRate.value }) // methods @@ -66,6 +70,7 @@ const fetchResponse = async (key: string) => { const onSubmit = async () => { const key = getOpenKey() + if (!verifyOpenKey(key)) return alert('请输入正确的API-KEY') if (!message.value) return @@ -96,7 +101,7 @@ const onSubmit = async () => { function speak(content: string, index: number) { speakIndex.value = index text.value = content - textToSpeak(content) + ssmlToSpeak(content) } const recognize = async () => { diff --git a/src/components/NewChat.vue b/src/components/NewChat.vue index 2abf2ef..88f043f 100644 --- a/src/components/NewChat.vue +++ b/src/components/NewChat.vue @@ -19,6 +19,7 @@ const filterVoices = ref([]) const selectVoiceName = ref('') const desc = ref('') const name = ref('') +const rate = ref('1.0') const canAdd = computed(() => !!(selectLanguage.value && selectVoiceName.value && desc.value && name.value)) @@ -43,6 +44,7 @@ const addChat = (event: any) => { name: name.value, key: uuid(), avatar: getAvatarUrl(avatarList.value[currentAvatarIndex.value]), + rate: +rate.value, }) emits('close') } @@ -84,6 +86,13 @@ const changeAvatar = () => { +
+ +
+ + {{ Number(rate).toFixed(1) }} +
+