Explorar o código

图片文本组件 字幕时间节点接口

natasha hai 11 horas
pai
achega
2a6724c2f9

+ 5 - 0
src/api/article.js

@@ -24,3 +24,8 @@ export function getWordTime(data) {
 export function analysSubmit(data) {
   return http.post(`/OtherSysTool/TeachingServer/TextAnalyser/Analyse`, data);
 }
+
+// 音频转为base64流
+export function fileToBase64Text(data) {
+  return http.post(`${process.env.VUE_APP_EepServer}?MethodName=file_store_manager-GetFileByteBase64Text`, data);
+}

+ 54 - 1
src/views/book/courseware/create/components/question/image_text/ImageText.vue

@@ -1,5 +1,5 @@
 <template>
-  <ModuleBase :type="data.type">
+  <ModuleBase :type="data.type" v-loading="loading">
     <template #content>
       <UploadFile
         key="upload_image"
@@ -37,6 +37,10 @@
         </div>
         <SvgIcon icon-class="delete-black" size="12" @click="removeFile" />
       </div>
+      <el-button v-if="data.mp3_list.length > 0" type="primary" size="small" @click="handleTime">{{
+        data.word_time.length === 0 ? '自动生成字幕节点' : '重新生成字幕节点'
+      }}</el-button>
+
       <el-radio-group v-model="isText" style="width: 100%; margin: 20px 0; text-align: center">
         <el-radio-button :label="true">文字框</el-radio-button>
         <el-radio-button :label="false">输入框</el-radio-button>
@@ -194,6 +198,7 @@ import UploadFile from '../../base/common/UploadFile.vue';
 import { getImageTextData } from '@/views/book/courseware/data/imageText';
 import SelectUpload from '@/views/book/courseware/create/components/common/SelectUpload.vue';
 import { GetFileURLMap } from '@/api/app';
+import { fileToBase64Text, prepareTranscribe, getWordTime } from '@/api/article';
 
 export default {
   name: 'ImageTextPage',
@@ -214,6 +219,7 @@ export default {
       genloading: false, // 字幕节点loading
       isText: true, // 框选是文本还是输入框
       inputActiveIndex: null, // 当前编辑输入框热区索引
+      loading: false,
     };
   },
   watch: {
@@ -328,6 +334,53 @@ export default {
       });
       this.data.mind_map.node_list = node_list;
     },
+    // 生成字幕
+    handleTime() {
+      let verseList = [];
+      this.data.text_list.forEach((item) => {
+        verseList = verseList.concat(item.text);
+      });
+      if (verseList.length > 0) {
+      } else {
+        this.$message.warning('请先录入文本内容');
+        return;
+      }
+      this.loading = true;
+      fileToBase64Text({
+        file_id: this.data.mp3_list[0].file_id,
+      })
+        .then((res) => {
+          let taskIddata = {
+            fileName: this.data.mp3_list[0].name,
+            speechBase64: res.base64_text,
+            language: 'ch',
+          };
+          prepareTranscribe(taskIddata)
+            .then((res) => {
+              let taskId = res.data.taskId;
+              let data = {
+                taskId: taskId,
+                verseList: JSON.stringify(verseList),
+                matchType: 'chinese',
+                language: 'ch',
+              };
+              getWordTime(data)
+                .then((res) => {
+                  this.data.word_time = res.data.result;
+                  this.loading = false;
+                })
+                .catch(() => {
+                  this.loading = false;
+                });
+            })
+            .catch(() => {
+              this.loading = false;
+            });
+        })
+        .catch(() => {
+          this.loading = false;
+        });
+    },
   },
 };
 </script>

+ 1 - 0
src/views/book/courseware/data/imageText.js

@@ -36,6 +36,7 @@ export function getImageTextData() {
     text_list: [], // 文字框列表
     input_list: [], // 输入框列表
     file_id_list: [], // 文件 id
+    word_time:[], // 时间字幕
     mind_map: {
       node_list: [
       ], // 思维导图数据