Browse Source

听后辩调和听说训练增加汉字录入,用作生成音频使用

natasha 1 year ago
parent
commit
b69465759a

+ 23 - 18
src/views/exercise_questions/create/components/exercises/ChooseToneQuestion.vue

@@ -18,11 +18,10 @@
             <span class="question-number" title="双击切换序号类型" @dblclick="changeOptionType(data)">
               {{ computedQuestionNumber(i, data.option_number_show_mode) }}
             </span>
+            <el-input v-model="item.character" :placeholder="'汉字'" style="flex-shrink: 0; width: 80px" />
             <el-input
               v-model="item.content"
-              placeholder="
-                拼音间用空格隔开,如:ni3 hao3
-              "
+              placeholder="拼音间用空格隔开,如:ni3 hao3"
               @blur="handleItemAnswer(item)"
               @change="changePinyin(item)"
             />
@@ -263,27 +262,33 @@ export default {
     },
     // 自动生成音频
     handleMatically(item, i) {
-      if (item.content.trim()) {
-        this.loading_list[i].loading = true;
+      let MethodName = 'tool-TextToVoiceFile';
+      let data = {};
+      if (item.character.trim() || item.content_hz) {
+        data = {
+          text: item.character.trim() || item.content_hz,
+        };
+      } else if (item.content.trim()) {
         if (!this.matically_pinyin_obj[item.mark]) {
           this.handleItemAnswer(item);
         }
-        let MethodName = 'tool-PinyinToVoiceFile';
-        let data = {
+        MethodName = 'tool-PinyinToVoiceFile';
+        data = {
           pinyin: this.matically_pinyin_obj[item.mark],
         };
-        GetStaticResources(MethodName, data)
-          .then((res) => {
-            this.loading_list[i].loading = false;
-            if (res.status === 1) {
-              item.audio_file_id = res.file_id;
-              this.data.file_id_list.push(res.file_id);
-            }
-          })
-          .catch(() => {
-            this.loading_list[i].loading = false;
-          });
       }
+      this.loading_list[i].loading = true;
+      GetStaticResources(MethodName, data)
+        .then((res) => {
+          this.loading_list[i].loading = false;
+          if (res.status === 1) {
+            item.audio_file_id = res.file_id;
+            this.data.file_id_list.push(res.file_id);
+          }
+        })
+        .catch(() => {
+          this.loading_list[i].loading = false;
+        });
     },
     handleReplaceTone(value, mark, itemIndex) {
       if (!value) return;

+ 22 - 16
src/views/exercise_questions/create/components/exercises/RepeatQuestion.vue

@@ -19,6 +19,7 @@
             <span class="question-number" title="双击切换序号类型" @dblclick="changeOptionType(data)">
               {{ computedQuestionNumber(i, data.option_number_show_mode) }}
             </span>
+            <el-input v-model="item.character" :placeholder="'汉字'" style="width: 80px" />
             <div class="option-content">
               <RichText
                 v-model="item.content"
@@ -294,29 +295,34 @@ export default {
     },
     // 自动生成音频
     handleMatically(item, i) {
-      if (
+      let MethodName = 'tool-TextToVoiceFile';
+      let data = {};
+      if (item.character.trim()) {
+        data = {
+          text: item.character.trim(),
+        };
+      } else if (
         document.getElementsByClassName('repeat-richtext') &&
         document.getElementsByClassName('repeat-richtext')[i] &&
         document.getElementsByClassName('repeat-richtext')[i].innerText
       ) {
-        this.loading_list[i].loading = true;
-
-        let MethodName = 'tool-PinyinToVoiceFile';
-        let data = {
+        MethodName = 'tool-PinyinToVoiceFile';
+        data = {
           pinyin: document.getElementsByClassName('repeat-richtext')[i].innerText.trim().split(' ').join(','),
         };
-        GetStaticResources(MethodName, data)
-          .then((res) => {
-            this.loading_list[i].loading = false;
-            if (res.status === 1) {
-              item.audio_file_id = res.file_id;
-              this.data.file_id_list.push(res.file_id);
-            }
-          })
-          .catch(() => {
-            this.loading_list[i].loading = false;
-          });
       }
+      this.loading_list[i].loading = true;
+      GetStaticResources(MethodName, data)
+        .then((res) => {
+          this.loading_list[i].loading = false;
+          if (res.status === 1) {
+            item.audio_file_id = res.file_id;
+            this.data.file_id_list.push(res.file_id);
+          }
+        })
+        .catch(() => {
+          this.loading_list[i].loading = false;
+        });
     },
   },
 };

+ 1 - 0
src/views/exercise_questions/data/chooseTone.js

@@ -11,6 +11,7 @@ import { getRandomNumber } from '@/utils/index';
 export function getOption(content = '') {
   return {
     content,
+    character: '',
     mark: getRandomNumber(),
     content_view: [],
     audio_file_id: '',

+ 4 - 4
src/views/exercise_questions/data/repeat.js

@@ -9,7 +9,7 @@ import {
 import { getRandomNumber } from '@/utils/index';
 
 export function getOption(content = '') {
-  return { content, mark: getRandomNumber(), audio_file_id: '' };
+  return { content, character: '', mark: getRandomNumber(), audio_file_id: '' };
 }
 // 音频生成方式类型
 export const audioGenerationMethodList = [
@@ -44,9 +44,9 @@ export const repeatData = {
   option_number_show_mode: optionTypeList[0].value, // 选项类型
   description: '', // 描述
   option_list: [
-    { content: '', mark: getRandomNumber(), audio_file_id: '' },
-    { content: '', mark: getRandomNumber(), audio_file_id: '' },
-    { content: '', mark: getRandomNumber(), audio_file_id: '' },
+    { content: '', character: '', mark: getRandomNumber(), audio_file_id: '' },
+    { content: '', character: '', mark: getRandomNumber(), audio_file_id: '' },
+    { content: '', character: '', mark: getRandomNumber(), audio_file_id: '' },
   ], // 选项
   file_id_list: [],
   answer: { score: 1, score_type: scoreTypeList[0].value }, // 答案