瀏覽代碼

语音包

CzRger 1 月之前
父節點
當前提交
ca9cab4ca1

+ 2 - 1
src/api/interceptors.ts

@@ -46,7 +46,8 @@ export class Interceptors {
     this.instance.interceptors.response.use(
       // 请求成功
       (res: any) => {
-        if (res.data.success) {
+        // if (res.data.success) {
+        if (res.status === 200) {
           return Promise.resolve(res.data)
         } else {
           this.errorHandle(res)

+ 13 - 0
src/api/modules/app/chat.ts

@@ -0,0 +1,13 @@
+import { del, get, post, put } from '@/api/request'
+
+const proxy = (import.meta as any).env.VITE_WORKFLOW_API_PROXY
+// 文本转语音
+export const appTextToAudio = (params) =>
+  post(
+    `/app/text-to-audio`,
+    params,
+    {
+      responseType: 'blob', // 关键!指定响应类型为二进制
+    },
+    proxy,
+  )

+ 1 - 1
src/stores/modules/dictionary.ts

@@ -307,7 +307,7 @@ export const useDictionaryStore = defineStore('dictionary', {
       if (!this.workflows.waiting) {
         this.workflows.waiting = true
         workflowMetaPage({
-          page: 1 - 1,
+          page: 1,
           size: 100000,
         })
           .then(({ data }: any) => {

+ 26 - 12
src/views/manage/app/make/index.vue

@@ -408,8 +408,12 @@
                         v-model:param="state.form.voicePackage"
                         link="select"
                         :options="[
-                          { value: 1, label: '语音包1' },
-                          { value: 2, label: '语音包2' },
+                          { value: 'Echo', label: 'Echo' },
+                          { value: 'Alloy', label: 'Alloy' },
+                          { value: 'Fable', label: 'Fable' },
+                          { value: 'Onyx', label: 'Onyx' },
+                          { value: 'Nova', label: 'Nova' },
+                          { value: 'Shimmer', label: 'Shimmer' },
                         ]"
                         :clearable="false"
                       >
@@ -418,7 +422,7 @@
                             {{ row.label }}
                             <div
                               class="__hover ml-auto text-[var(--czr-main-color)]"
-                              @click.stop=""
+                              @click.stop="onTryVoice(row.value)"
                             >
                               试听
                             </div>
@@ -428,6 +432,7 @@
                     </div>
                     <div
                       class="__hover ml-4 text-sm text-[var(--czr-main-color)]"
+                      @click="onTryVoice(state.form.voicePackage)"
                     >
                       试听
                     </div>
@@ -469,7 +474,7 @@
                       link="select"
                       :options="DictionaryStore.models.list"
                       placeholder="点击选择模型"
-                      @click="onAdviseModel"
+                      @click.capture.stop="onAdviseModel"
                       default-error-msg="请选择问题建议模型"
                       :clearable="false"
                     />
@@ -700,6 +705,7 @@ import {
   appModelConfigSave,
 } from '@/api/modules/app/make'
 import { appDetail } from '@/api/modules/app'
+import { appTextToAudio } from '@/api/modules/app/chat'
 
 const DictionaryStore = useDictionaryStore()
 const AppStore = useAppStore()
@@ -878,12 +884,6 @@ const initDetail = () => {
       .finally(() => {
         state.loading = false
       })
-    // pluginDetail(state.ID)
-    //   .then(({ data }: any) => {
-    //     state.detail = data
-    //   })
-    //   .catch(() => {})
-    //   .finally(() => {})
     initDrag()
   } else {
     router.push({ name: 'd446bfb3-4605-477f-a0f4-b7a0a1aa78fe' })
@@ -974,12 +974,12 @@ const getModel = (val) => {
   switch (state.modelSelect.transfer.type) {
     case 'model':
       {
-        state.form.modelId = val.value
+        state.form.modelId = val.id
       }
       break
     case 'advise':
       {
-        state.form.advise.modelId = val
+        state.form.advise.modelId = val.id
       }
       break
   }
@@ -1085,6 +1085,20 @@ const onAddWorkflow = () => {
 const getWorkflow = (val) => {
   state.form.workflowId = val.id
 }
+const onTryVoice = (type) => {
+  appTextToAudio({
+    voice: type,
+    text: `您好,欢迎使用${(import.meta as any).env.VITE_TITLE}。`,
+  }).then((bolb: any) => {
+    const url = URL.createObjectURL(new Blob([bolb], { type: 'audio/mp3' }))
+    const audio = new Audio(url)
+    audio.play()
+    // 播放结束后释放内存
+    audio.onended = function () {
+      URL.revokeObjectURL(url)
+    }
+  })
+}
 onMounted(() => {
   initDictionary()
   initDetail()

+ 1 - 1
src/views/manage/app/make/workflow-select.vue

@@ -186,7 +186,7 @@ const onPage = (pageNum, pageSize) => {
     pageSize: pageSize,
   }
   const params = {
-    page: state.query.page.pageNum - 1,
+    page: state.query.page.pageNum,
     size: state.query.page.pageSize,
     queryVO: {},
   }