Explorar el Código

对话课文录音评分功能

natasha hace 3 semanas
padre
commit
194f270852

+ 254 - 0
src/views/book/courseware/preview/components/dialogue_article/Practicechs.vue

@@ -831,6 +831,21 @@
                       </template>
                     </div>
                   </div>
+                  <template v-if="wholeRecordList[wholeRecordIndex] && whileRecordScoreList[wholeRecordIndex]">
+                    <a
+                      v-if="
+                        wholeRecordList[wholeRecordIndex][index] && wholeRecordList[wholeRecordIndex][index].detail_list
+                      "
+                      @click.stop="
+                        recordScoreDetail = wholeRecordList[wholeRecordIndex][index];
+                        visibleRecordSingle = true;
+                      "
+                      class="badge"
+                      :style="recordScoreStyle(wholeRecordList[wholeRecordIndex][index].score_total)"
+                      >{{ wholeRecordList[wholeRecordIndex][index].score_total }}</a
+                    >
+                    <a class="badge" v-else>—</a>
+                  </template>
                   <div style="overflow: hidden; clear: both"></div>
                   <div
                     v-if="
@@ -873,6 +888,8 @@
                   @handleParentPlay="handleParentPlay"
                   @sentPause="sentPause"
                   @handleWav="handleWav"
+                  @handleScoreList="handleScoreList"
+                  @getRecordIndex="getRecordIndex"
                 />
                 <div v-if="curQue.mp3_list && curQue.mp3_list.length > 0" class="compare-box">
                   <Audio-compare
@@ -891,6 +908,39 @@
                     :attrib="attrib"
                   />
                 </div>
+                <el-button
+                  type="text"
+                  v-if="!(curQue.property.is_enable_score && curQue.property.is_enable_score === 'false')"
+                  :class="['record-score-btn', wavblob ? 'record-score-btn-has' : '']"
+                  @click="handleSingleScore(item, index)"
+                  :loading="scoreLoading"
+                  >评分</el-button
+                >
+                <template
+                  v-if="
+                    curQue.Bookanswer.practiceModel[index] &&
+                    curQue.Bookanswer.practiceModel[index].scoreList &&
+                    curQue.Bookanswer.practiceModel[index].scoreList[selectIndex]
+                  "
+                >
+                  <span
+                    class="record-score-content"
+                    :style="recordScoreStyle(curQue.Bookanswer.practiceModel[index].scoreList[selectIndex].score_total)"
+                    @click="
+                      recordScoreDetail = curQue.Bookanswer.practiceModel[index].scoreList[selectIndex];
+                      visibleRecordSingle = true;
+                    "
+                    >{{ curQue.Bookanswer.practiceModel[index].scoreList[selectIndex].score_total }}分</span
+                  >
+                  <b
+                    class="record-score-tips"
+                    @click="
+                      recordScoreDetail = curQue.Bookanswer.practiceModel[index].scoreList[selectIndex];
+                      visibleRecordSingle = true;
+                    "
+                    >详情</b
+                  >
+                </template>
               </div>
               <span class="full-screen-icon" @click="fullScreen">
                 <svg-icon
@@ -928,6 +978,30 @@
           </div>
         </div>
       </template>
+      <div
+        style="display: flex; padding-left: 24px"
+        v-if="!(curQue.property.is_enable_score && curQue.property.is_enable_score === 'false')"
+      >
+        <RecordScoreWholeBtn
+          v-if="resObj && resObj.sentList"
+          ref="recordScoreWholeBtn"
+          class="luyin-box"
+          :TaskModel="TaskModel"
+          :tmIndex="sentIndex"
+          :totalIndex="resObj.sentList.length"
+          :answerRecordList="wholeRecordList"
+          recordType="sentence"
+          :attrib="attrib"
+          :standardUrl="curQue.mp3_list && curQue.mp3_list[0] ? curQue.mp3_list[0].url : ''"
+          :wordTime="curQue.wordTime"
+          :sentList="resObj.sentList"
+          @changeWholeStatus="changeWholeStatus"
+          @getRecordIndex="getRecordScoreIndex"
+          @getWholeRecordIndex="getWholeRecordIndex"
+          @handleDeleteWholeRecord="handleDeleteWholeRecord"
+          @updataWholeRecordList="updataWholeRecordList"
+        />
+      </div>
     </div>
     <div
       v-if="
@@ -1015,6 +1089,12 @@
         @changeIsFull="changeIsFull"
       />
     </div>
+    <RecordScoreSingleDetail
+      v-if="visibleRecordSingle"
+      :attrib="attrib"
+      :visible.sync="visibleRecordSingle"
+      :recordScoreDetail="recordScoreDetail"
+    />
   </div>
 </template>
 
@@ -1025,6 +1105,9 @@ import Soundrecord from '../../common/SoundRecord.vue'; // 录音模板
 import RoleChs from './RoleChs.vue';
 import AudioCompare from '../article/components/AudioCompare.vue';
 import Voicefullscreen from '../article/Voicefullscreen.vue';
+import RecordScoreSingleDetail from '../../common/RecordScoreSingleDetail.vue';
+import RecordScoreWholeBtn from '../../common/RecordScoreWholeBtn.vue';
+import { recordSocreSingle } from '@/utils/recordScore.js';
 export default {
   name: 'ArticleView',
   components: {
@@ -1033,6 +1116,8 @@ export default {
     RoleChs,
     AudioCompare,
     Voicefullscreen,
+    RecordScoreSingleDetail,
+    RecordScoreWholeBtn,
   },
   filters: {
     handlePinyin(wordsList) {
@@ -1097,6 +1182,14 @@ export default {
       highIndex: 0,
       newWordList: [],
       multilingualTextList: {},
+      selectIndex: null, // 记录录音列表里选择的索引
+      scoreLoading: false, // 单个评分按钮loading
+      visibleRecordSingle: false, // 单个评分详情页面
+      recordScoreDetail: null, // 单个评分数据
+      isWholeRecord: false, // 是否为全篇录音
+      wholeRecordList: [], // 保存多次整篇录音数据
+      wholeRecordIndex: 0, // 整偏录音索引
+      whileRecordScoreList: [], // 保存多次整篇录音每次是否已评分
     };
   },
   computed: {
@@ -1220,6 +1313,9 @@ export default {
     sentPause(isRecord) {
       this.isRecord = isRecord;
     },
+    getRecordIndex(index) {
+      this.selectIndex = index;
+    },
     getCurTime(curTime) {
       let _this = this;
       if (_this.isRepeat) {
@@ -1445,6 +1541,11 @@ export default {
     // 点击播放某个句子
     handleChangeTime(time, index, ed) {
       let _this = this;
+      _this.sentIndex = index;
+      if (this.isWholeRecord) {
+        _this.$refs.recordScoreWholeBtn.handleNext('reset');
+        return;
+      }
       if (_this.isRepeat) {
         _this.currSent = _this.curQue.wordTime[index];
       }
@@ -1460,11 +1561,28 @@ export default {
     },
     handleWav(list, tmIndex) {
       let _tmIndex = tmIndex || 0;
+      let scoreLists = [];
+      if (this.curQue.Bookanswer.practiceModel[_tmIndex] && this.curQue.Bookanswer.practiceModel[_tmIndex].scoreList) {
+        scoreLists = this.curQue.Bookanswer.practiceModel[_tmIndex].scoreList;
+      }
+      // 评分数组如果短的话按照录音数组补齐null
+      const fillArray = (shortArr, longArr, fillValue = null) => {
+        return Array.from({ length: longArr.length }, (_, index) => {
+          return index < shortArr.length ? shortArr[index] : fillValue;
+        });
+      };
+      let scoreList = fillArray(scoreLists, list, null);
       this.curQue.Bookanswer.practiceModel[_tmIndex] = {
         recordList: [],
+        scoreList: scoreList,
       };
       this.$set(this.curQue.Bookanswer.practiceModel[_tmIndex], 'recordList', list);
     },
+    // 删除录音时先删除对应位置的评分数据
+    handleScoreList(tmIndex, selectIndex) {
+      this.curQue.Bookanswer.practiceModel[tmIndex].scoreList.splice(selectIndex, 1);
+      this.selectIndex = this.curQue.Bookanswer.practiceModel[tmIndex].scoreList.length - 1;
+    },
     // 录音时暂停音频播放
     handleParentPlay() {
       this.stopAudio = true;
@@ -1504,6 +1622,91 @@ export default {
       });
       this.newWordList = JSON.parse(JSON.stringify(NewWordList));
     },
+    // 单句录音评分
+    async handleSingleScore(item, index) {
+      if (
+        this.curQue.Bookanswer.practiceModel[this.sentIndex] &&
+        this.curQue.Bookanswer.practiceModel[this.sentIndex].scoreList &&
+        this.curQue.Bookanswer.practiceModel[this.sentIndex].scoreList[this.selectIndex]
+      ) {
+        // 显示单句评分详情
+        this.recordScoreDetail = this.curQue.Bookanswer.practiceModel[this.sentIndex].scoreList[this.selectIndex];
+        this.visibleRecordSingle = true;
+        return;
+      }
+      if (!this.wavblob) return;
+      this.scoreLoading = true;
+      let text = item.sentArr.map((item) => item.chs).join('');
+      let scoreObj = await recordSocreSingle({
+        text: text,
+        base64: this.wavblob,
+        audio_paramter_type: this.wavblob.indexOf('data:audio/wav') > -1 ? 0 : 1,
+        standard:
+          this.curQue.mp3_list &&
+          this.curQue.mp3_list.length > 0 &&
+          this.curQue.mp3_list[0].url &&
+          this.curQue.wordTime &&
+          this.curQue.wordTime[index]
+            ? 'false'
+            : 'true',
+      });
+      this.scoreLoading = false;
+      if (scoreObj) {
+        let score_total = Math.min(Math.round((scoreObj.accuracy + scoreObj.fluency + scoreObj.integrity) / 3), 100); // 算单句总得分 三个值取平均值四舍五入
+        this.$set(scoreObj, 'score_total', score_total);
+        // 如果有音频 记录课文音频及开始结束时间
+        if (
+          this.curQue.mp3_list &&
+          this.curQue.mp3_list.length > 0 &&
+          this.curQue.mp3_list[0].url &&
+          this.curQue.wordTime &&
+          this.curQue.wordTime[index]
+        ) {
+          this.$set(scoreObj, 'audio_url_standard', this.curQue.mp3_list[0].url);
+          this.$set(scoreObj, 'audio_url_standard_bg', this.curQue.wordTime[index].bg);
+          this.$set(scoreObj, 'audio_url_standard_ed', this.curQue.wordTime[index].ed);
+        }
+      }
+      this.curQue.Bookanswer.practiceModel[this.sentIndex].scoreList[this.selectIndex] = scoreObj;
+    },
+    recordScoreStyle(score) {
+      let style = {
+        backgroundColor: score >= 80 ? '#2f7d34' : score <= 79 && score >= 60 ? '#b8860b' : '#c0392b',
+      };
+      return style;
+    },
+    // 获取全篇录音状态
+    changeWholeStatus(status, index) {
+      // 点击全屏录音时音频播放暂停 从第一句开始录音
+      this.pauseAudio();
+      if (this.$refs.audioLine) this.$refs.audioLine.onTimeupdateTime(0, false);
+      this.isWholeRecord = status;
+      this.sentIndex = index;
+    },
+    // 切换录音句子索引
+    getRecordScoreIndex(index) {
+      this.sentIndex = index;
+    },
+    // 整体录音的索引
+    getWholeRecordIndex(index) {
+      this.wholeRecordIndex = index;
+    },
+    // 删除某条整篇录音数据
+    handleDeleteWholeRecord(index) {
+      this.wholeRecordList.splice(index, 1);
+      this.wholeRecordIndex = this.wholeRecordList.length - 1;
+      this.whileRecordScoreList.splice(index, 1);
+    },
+    // 更新全篇录音评分数据
+    updataWholeRecordList(list) {
+      if (list) {
+        this.wholeRecordList.push(list);
+        this.whileRecordScoreList.push(false);
+      } else {
+        this.whileRecordScoreList[this.wholeRecordIndex] = true;
+      }
+      this.$forceUpdate();
+    },
   }, // 如果页面有keep-alive缓存功能,这个函数会触发
 };
 </script>
@@ -1807,5 +2010,56 @@ export default {
   img {
     max-width: 100%;
   }
+
+  .record-score-btn {
+    padding: 0 9px;
+    font-weight: bold;
+    color: #3b6fd4;
+    cursor: not-allowed;
+    opacity: 0.35;
+
+    &-has {
+      cursor: pointer;
+      opacity: 1;
+    }
+
+    &:focus {
+      outline: none;
+    }
+  }
+
+  .record-score-content {
+    padding: 0 10px;
+    font-size: 13px;
+    font-weight: bold;
+    line-height: 24px;
+    color: #fff;
+    cursor: pointer;
+    border-radius: 12px;
+  }
+
+  .record-score-tips {
+    margin-left: 8px;
+    font-size: 12px;
+    color: #2f9e78;
+    cursor: pointer;
+  }
+}
+
+.badge {
+  display: block;
+  align-items: center;
+  justify-content: center;
+  float: left;
+  width: 40px;
+  height: 40px;
+  font-size: 17px;
+  font-weight: bold;
+  line-height: 40px;
+  color: #fff;
+  text-align: center;
+  cursor: pointer;
+  background: #e05252;
+  border-radius: 50%;
 }
 </style>