|
|
@@ -0,0 +1,665 @@
|
|
|
+<template>
|
|
|
+ <div class="matrix-record" @click.stop>
|
|
|
+ <div class="record-controls">
|
|
|
+ <SvgIcon
|
|
|
+ :icon-class="recording ? 'luyin-ing' : 'luyin-radio-button'"
|
|
|
+ size="24"
|
|
|
+ :style="{ color: attrib && attrib.topic_color }"
|
|
|
+ :class="['record-action', { unavailable: answerMode }]"
|
|
|
+ @click="start(false)"
|
|
|
+ />
|
|
|
+ <span class="record-time">{{
|
|
|
+ formatTime(recording ? elapsed : (selectedRecord && selectedRecord.toltime) || 0)
|
|
|
+ }}</span>
|
|
|
+ <el-select
|
|
|
+ v-model="selectedIndex"
|
|
|
+ placeholder="无录音"
|
|
|
+ :disabled="recording || busy || scoring"
|
|
|
+ @change="changeRecord"
|
|
|
+ >
|
|
|
+ <el-option v-for="(record, index) in records" :key="record.id || index" :label="record.name" :value="index" />
|
|
|
+ </el-select>
|
|
|
+ <div
|
|
|
+ class="play-back icon-mask"
|
|
|
+ :style="{
|
|
|
+ backgroundColor: selectedRecord ? (attrib && attrib.topic_color) || '#000' : '#aaa',
|
|
|
+ maskImage: playing
|
|
|
+ ? `url(${require('@/assets/voice_matrix/luyin-play-stop.png')})`
|
|
|
+ : `url(${require('@/assets/voice_matrix/luyin-play-active.png')})`,
|
|
|
+ }"
|
|
|
+ @click="playRecording"
|
|
|
+ ></div>
|
|
|
+ <a class="record-action" :class="{ unavailable: !selectedRecord || answerMode }" @click="deleteRecording">
|
|
|
+ <SvgIcon icon-class="luyin-delete" size="24" />
|
|
|
+ </a>
|
|
|
+ <slot name="record-extra"></slot>
|
|
|
+ <div class="record-tail">
|
|
|
+ <el-button type="text" :disabled="!selectedRecord || busy || scoring" @click="showScore">评分</el-button>
|
|
|
+ <el-button class="whole-btn" size="mini" :disabled="wholeDisabled" @click="start(true)">整体录音</el-button>
|
|
|
+ <span class="selection-tip" :title="selectionLabel">{{ selectionLabel }}</span>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div v-if="scoring" class="score-progress">
|
|
|
+ <i class="el-icon-loading"></i> 评测中… 已完成 {{ scoreIndex }} / {{ scoreTotal }} 词
|
|
|
+ </div>
|
|
|
+ <RecordProgressBar
|
|
|
+ v-if="recording"
|
|
|
+ :index="currentIndex"
|
|
|
+ :total="sessionWords.length"
|
|
|
+ unit="词"
|
|
|
+ :label="currentWordText"
|
|
|
+ :busy="busy"
|
|
|
+ @reset="next('reset')"
|
|
|
+ @next="next('next')"
|
|
|
+ @finish="next('finish')"
|
|
|
+ @cancel="cancel"
|
|
|
+ />
|
|
|
+ <RecordScoreWholeDetail
|
|
|
+ v-if="visibleScore"
|
|
|
+ :visible.sync="visibleScore"
|
|
|
+ :attrib="attrib"
|
|
|
+ :record-score-detail="scoreDetails"
|
|
|
+ :score-title="scoreTitle"
|
|
|
+ item-unit="词"
|
|
|
+ :show-index="false"
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import Recorder from 'js-audio-recorder';
|
|
|
+import { playAudioElement, releaseAudioElement, releaseRecorder } from '@/utils';
|
|
|
+import { blobToDataUrl, uploadRecording, trackUpload, registerRecorder } from '@/utils/recordingUpload';
|
|
|
+import { resolveAudioSrc } from '@/utils/audioSource';
|
|
|
+import { mergeAudio, recordSocreSingle } from '@/utils/recordScore';
|
|
|
+import RecordScoreWholeDetail from '../../../common/RecordScoreWholeDetail.vue';
|
|
|
+import RecordProgressBar from '../../../common/RecordProgressBar.vue';
|
|
|
+
|
|
|
+export default {
|
|
|
+ components: { RecordScoreWholeDetail, RecordProgressBar },
|
|
|
+ props: {
|
|
|
+ answerRecordList: { type: Array, default: () => [] },
|
|
|
+ selectData: { type: Object, default: () => ({}) },
|
|
|
+ selectedWords: { type: Array, default: () => [] },
|
|
|
+ allWords: { type: Array, default: () => [] },
|
|
|
+ attrib: { type: Object, default: () => ({}) },
|
|
|
+ standardUrl: { type: String, default: '' },
|
|
|
+ // 与课文录音组件一致:ANSWER(查看答案)模式下禁止录音与删除
|
|
|
+ taskModel: { type: String, default: '' },
|
|
|
+ },
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ records: [],
|
|
|
+ selectedIndex: null,
|
|
|
+ recording: false,
|
|
|
+ busy: false,
|
|
|
+ playing: false,
|
|
|
+ scoring: false,
|
|
|
+ scoreIndex: 0,
|
|
|
+ scoreTotal: 0,
|
|
|
+ scoreGeneration: 0,
|
|
|
+ sessionGeneration: 0,
|
|
|
+ visibleScore: false,
|
|
|
+ elapsed: 0,
|
|
|
+ currentIndex: 0,
|
|
|
+ sessionWords: [],
|
|
|
+ sessionSelection: null,
|
|
|
+ sessionAll: false,
|
|
|
+ audio: new window.Audio(),
|
|
|
+ };
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ answerMode() {
|
|
|
+ return this.taskModel === 'ANSWER';
|
|
|
+ },
|
|
|
+ wholeDisabled() {
|
|
|
+ return this.busy || this.scoring || this.answerMode;
|
|
|
+ },
|
|
|
+ selectedRecord() {
|
|
|
+ return this.selectedIndex === null ? null : this.records[this.selectedIndex] || null;
|
|
|
+ },
|
|
|
+ selectionLabel() {
|
|
|
+ if (this.recording) {
|
|
|
+ return this.sessionAll
|
|
|
+ ? '整体录音中'
|
|
|
+ : `已选:${this.describeSelection(this.sessionSelection, this.sessionWords)}`;
|
|
|
+ }
|
|
|
+ if (!this.selectedWords.length) return '未选择词汇';
|
|
|
+ return `已选:${this.describeSelection(this.selectData, this.selectedWords)}`;
|
|
|
+ },
|
|
|
+ scoreDetails() {
|
|
|
+ const words = this.selectedRecord && this.selectedRecord.words;
|
|
|
+ if (!words) return [];
|
|
|
+ // 兼容历史答案中缺少逐词评分的情况,避免详情弹窗读到 undefined
|
|
|
+ return words.map((word) => word.score || { text: word.text, isShow: false });
|
|
|
+ },
|
|
|
+ // 得分明细小标题:单个单元格为逐字得分,整行/整列为第 x 行(词1、词2)
|
|
|
+ scoreTitle() {
|
|
|
+ const record = this.selectedRecord;
|
|
|
+ if (!record || !record.words || !record.words.length) return '逐字得分';
|
|
|
+ const selection = record.selectData || {};
|
|
|
+ const texts = record.words.map((word) => word.text).join('、');
|
|
|
+ if (selection.type === 'row') return `第 ${selection.index + 1} 行(${texts})`;
|
|
|
+ if (selection.type === 'column') return `第 ${selection.index + 1} 列(${texts})`;
|
|
|
+ if (selection.type === 'all') return '整体录音(逐词连录)';
|
|
|
+ return '逐字得分';
|
|
|
+ },
|
|
|
+ currentWordText() {
|
|
|
+ const word = this.sessionWords[this.currentIndex];
|
|
|
+ return word ? word.text : '';
|
|
|
+ },
|
|
|
+ },
|
|
|
+ watch: {
|
|
|
+ answerRecordList(value) {
|
|
|
+ if (value === this.records) return;
|
|
|
+ if (this.recording) this.abortSession();
|
|
|
+ this.scoreGeneration += 1;
|
|
|
+ this.scoring = false;
|
|
|
+ this.visibleScore = false;
|
|
|
+ this.records = Array.isArray(value) ? value : [];
|
|
|
+ this.selectedIndex = this.records.length ? 0 : null;
|
|
|
+ this.changeRecord(this.selectedIndex);
|
|
|
+ },
|
|
|
+ },
|
|
|
+ mounted() {
|
|
|
+ this.segmentTasks = new WeakMap();
|
|
|
+ this.records = this.answerRecordList || [];
|
|
|
+ this.selectedIndex = this.records.length ? 0 : null;
|
|
|
+ this.changeRecord(this.selectedIndex);
|
|
|
+ this.audio.addEventListener('play', this.onPlay);
|
|
|
+ this.audio.addEventListener('pause', this.onPause);
|
|
|
+ this.unregisterRecorder = registerRecorder({ stopIfRecording: () => this.stopIfRecording() });
|
|
|
+ },
|
|
|
+ beforeDestroy() {
|
|
|
+ this.tearingDown = true;
|
|
|
+ this.sessionGeneration += 1;
|
|
|
+ this.scoreGeneration += 1;
|
|
|
+ if (this.unregisterRecorder) this.unregisterRecorder();
|
|
|
+ clearInterval(this.timer);
|
|
|
+ this.clearSegmentGap();
|
|
|
+ if (this.recorder && !this.startPromise) releaseRecorder(this.recorder);
|
|
|
+ if (this.recording) this.$root.isRecording = false;
|
|
|
+ releaseAudioElement(this.audio);
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ formatTime(seconds) {
|
|
|
+ const time = Math.max(0, Math.floor(seconds || 0));
|
|
|
+ return `${String(Math.floor(time / 60)).padStart(2, '0')}:${String(time % 60).padStart(2, '0')}`;
|
|
|
+ },
|
|
|
+ // 已选对象描述:单词用引号,整行/整列带序号和词汇列表
|
|
|
+ describeSelection(selection, words) {
|
|
|
+ const texts = words.map((word) => word.text).join('、');
|
|
|
+ if (selection.type === 'row') return `第 ${selection.index + 1} 行(${texts})`;
|
|
|
+ if (selection.type === 'column') return `第 ${selection.index + 1} 列(${texts})`;
|
|
|
+ return `词汇「${texts}」`;
|
|
|
+ },
|
|
|
+ onPlay() {
|
|
|
+ this.playing = true;
|
|
|
+ },
|
|
|
+ onPause() {
|
|
|
+ this.playing = false;
|
|
|
+ },
|
|
|
+ emitRecords() {
|
|
|
+ this.$emit('handleWav', this.records);
|
|
|
+ },
|
|
|
+ changeRecord(index) {
|
|
|
+ this.audio.pause();
|
|
|
+ const record = index === null ? null : this.records[index];
|
|
|
+ this.$emit('getWavblob', record ? record.wavData || null : null);
|
|
|
+ // 与课文组件一致:切换录音后对比播放回到标准音
|
|
|
+ this.$emit('sentPause', false);
|
|
|
+ this.$emit('selectRecord', record || null);
|
|
|
+ },
|
|
|
+ async start(all) {
|
|
|
+ if (this.answerMode) return;
|
|
|
+ if (this.recording || this.busy || this.scoring) return;
|
|
|
+ const words = all ? this.allWords : this.selectedWords;
|
|
|
+ if (!words.length) {
|
|
|
+ this.$message.warning(all ? '没有可录音的词汇' : '请先选择:词汇卡片 / 列头 / 行首,或点「整体录音」');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.audio.pause();
|
|
|
+ this.$emit('handleParentPlay');
|
|
|
+ this.$emit('sentPause', false);
|
|
|
+ this.sessionWords = words.map((word) => ({ ...word, lrc_data: { ...word.lrc_data } }));
|
|
|
+ this.sessionSelection = all ? { type: 'all' } : { ...this.selectData };
|
|
|
+ this.sessionAll = all;
|
|
|
+ this.sessionGeneration += 1;
|
|
|
+ const generation = this.sessionGeneration;
|
|
|
+ this.currentIndex = 0;
|
|
|
+ this.elapsed = 0;
|
|
|
+ this.recording = true;
|
|
|
+ this.$emit('recordProgress', this.sessionWords[0]);
|
|
|
+ if (all) this.$emit('selectRecord', { selectData: { type: 'all' } });
|
|
|
+ this.busy = true;
|
|
|
+ try {
|
|
|
+ this.operation = this.startSegment();
|
|
|
+ await this.operation;
|
|
|
+ } catch (error) {
|
|
|
+ if (generation === this.sessionGeneration) {
|
|
|
+ this.abortSession();
|
|
|
+ if (!this.tearingDown) this.$message.warning('录音启动失败,请检查麦克风权限后重试');
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ this.operation = null;
|
|
|
+ this.busy = false;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ async startSegment() {
|
|
|
+ const generation = this.sessionGeneration;
|
|
|
+ const recorder = new Recorder({ sampleBits: 16, sampleRate: 16000, numChannels: 1 });
|
|
|
+ this.recorder = recorder;
|
|
|
+ this.startPromise = recorder.start();
|
|
|
+ try {
|
|
|
+ await this.startPromise;
|
|
|
+ } catch (error) {
|
|
|
+ this.startPromise = null;
|
|
|
+ releaseRecorder(recorder);
|
|
|
+ if (this.recorder === recorder) this.recorder = null;
|
|
|
+ throw error;
|
|
|
+ }
|
|
|
+ this.startPromise = null;
|
|
|
+ if (this.tearingDown || generation !== this.sessionGeneration) {
|
|
|
+ releaseRecorder(recorder);
|
|
|
+ if (this.recorder === recorder) this.recorder = null;
|
|
|
+ throw new Error('录音组件已销毁');
|
|
|
+ }
|
|
|
+ this.$root.isRecording = true;
|
|
|
+ // 与课文组件一致:时长按当前这一段计,不累计前面录过的词
|
|
|
+ this.elapsed = 0;
|
|
|
+ clearInterval(this.timer);
|
|
|
+ this.timer = setInterval(() => {
|
|
|
+ this.elapsed += 1;
|
|
|
+ if (this.elapsed >= 600) {
|
|
|
+ this.$message.warning('单次录音最多可以录音10分钟');
|
|
|
+ this.stopIfRecording();
|
|
|
+ }
|
|
|
+ }, 1000);
|
|
|
+ },
|
|
|
+ async stopSegment() {
|
|
|
+ if (this.startPromise) await this.startPromise;
|
|
|
+ if (!this.recorder) throw new Error('录音尚未启动');
|
|
|
+ const recorder = this.recorder;
|
|
|
+ recorder.stop();
|
|
|
+ const wav = recorder.getWAVBlob();
|
|
|
+ const duration = Math.floor(recorder.duration);
|
|
|
+ const fileSize = recorder.fileSize;
|
|
|
+ releaseRecorder(recorder);
|
|
|
+ this.recorder = null;
|
|
|
+ this.$root.isRecording = false;
|
|
|
+ clearInterval(this.timer);
|
|
|
+ return { wavData: await blobToDataUrl(wav), toltime: duration, fileSize, upload_state: 'uploading' };
|
|
|
+ },
|
|
|
+ // 与课文组件一致:停止即上传,与后续录音并行,不必等整段录完
|
|
|
+ uploadSegment(segment) {
|
|
|
+ const task = uploadRecording(segment.wavData)
|
|
|
+ .then((res) => {
|
|
|
+ this.$set(segment, 'wavData', res.file_id);
|
|
|
+ this.$set(segment, 'file_url', res.file_url || '');
|
|
|
+ this.$set(segment, 'upload_state', 'done');
|
|
|
+ return res;
|
|
|
+ })
|
|
|
+ .catch((error) => {
|
|
|
+ this.$set(segment, 'upload_state', 'failed');
|
|
|
+ this.$set(segment, 'upload_error', (error && error.message) || '录音上传失败');
|
|
|
+ throw error;
|
|
|
+ });
|
|
|
+ // 登记到提交前统一等待;拒绝由具体使用方处理,这里吞掉避免未处理异常
|
|
|
+ trackUpload(task);
|
|
|
+ task.catch(() => {});
|
|
|
+ return task;
|
|
|
+ },
|
|
|
+ next(action) {
|
|
|
+ if (!this.recording || this.busy) return;
|
|
|
+ this.busy = true;
|
|
|
+ const operation = this.advance(action);
|
|
|
+ this.operation = operation;
|
|
|
+ return operation.finally(() => {
|
|
|
+ if (this.operation === operation) this.operation = null;
|
|
|
+ this.busy = false;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ async advance(action) {
|
|
|
+ const generation = this.sessionGeneration;
|
|
|
+ try {
|
|
|
+ const segment = await this.stopSegment();
|
|
|
+ // 会话已取消/销毁,本次录音作废,不再上传
|
|
|
+ if (this.tearingDown || !this.recording) return;
|
|
|
+ if (action !== 'reset') {
|
|
|
+ this.$set(this.sessionWords[this.currentIndex], 'segment', segment);
|
|
|
+ this.segmentTasks.set(segment, this.uploadSegment(segment));
|
|
|
+ }
|
|
|
+ if (action === 'finish') {
|
|
|
+ this.saveSession();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (action === 'next') this.currentIndex += 1;
|
|
|
+ this.$emit('recordProgress', this.sessionWords[this.currentIndex]);
|
|
|
+ // 与课文组件一致:停止与下一次开始之间留 800ms,等麦克风释放、上传启动
|
|
|
+ await this.waitSegmentGap();
|
|
|
+ if (this.tearingDown || !this.recording) return;
|
|
|
+ await this.startSegment();
|
|
|
+ } catch (error) {
|
|
|
+ if (generation === this.sessionGeneration) {
|
|
|
+ this.abortSession();
|
|
|
+ if (!this.tearingDown) this.$message.error('录音保存或启动失败,请重新录制');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ waitSegmentGap() {
|
|
|
+ return new Promise((resolve) => {
|
|
|
+ this.segmentGapResolve = resolve;
|
|
|
+ this.segmentGapTimer = setTimeout(() => {
|
|
|
+ this.segmentGapTimer = null;
|
|
|
+ this.segmentGapResolve = null;
|
|
|
+ resolve();
|
|
|
+ }, 800);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 结束切词间隔。
|
|
|
+ * cancel/销毁时必须让等待中的 advance 立即继续,否则 next() 的 finally 不会执行,
|
|
|
+ * busy 会一直为 true,提交前 stopIfRecording 也会卡在这里。
|
|
|
+ */
|
|
|
+ clearSegmentGap() {
|
|
|
+ if (this.segmentGapTimer) clearTimeout(this.segmentGapTimer);
|
|
|
+ this.segmentGapTimer = null;
|
|
|
+ const resolve = this.segmentGapResolve;
|
|
|
+ this.segmentGapResolve = null;
|
|
|
+ if (resolve) resolve();
|
|
|
+ },
|
|
|
+ saveSession() {
|
|
|
+ const words = this.sessionWords.filter((word) => word.segment);
|
|
|
+ if (!words.length) {
|
|
|
+ this.abortSession();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const record = {
|
|
|
+ id: `${Date.now()}-${Math.random().toString(36).slice(2)}`,
|
|
|
+ name: `${this.sessionAll ? '整体录音' : '选词录音'}${this.records.length + 1}${
|
|
|
+ words.length < this.sessionWords.length ? '(未完成)' : ''
|
|
|
+ }`,
|
|
|
+ selectData: this.sessionSelection,
|
|
|
+ words,
|
|
|
+ toltime: words.reduce((sum, word) => sum + word.segment.toltime, 0),
|
|
|
+ src: '',
|
|
|
+ wavData: words.length === 1 ? words[0].segment.wavData : '',
|
|
|
+ upload_state: 'uploading',
|
|
|
+ };
|
|
|
+ this.records.push(record);
|
|
|
+ this.selectedIndex = this.records.length - 1;
|
|
|
+ this.recording = false;
|
|
|
+ this.$emit('recordProgress', null);
|
|
|
+ this.$root.isRecording = false;
|
|
|
+ this.emitRecords();
|
|
|
+ this.changeRecord(this.selectedIndex);
|
|
|
+ const upload = this.finalizeRecord(record);
|
|
|
+ trackUpload(upload);
|
|
|
+ upload.catch((error) => {
|
|
|
+ this.$set(record, 'upload_state', 'failed');
|
|
|
+ this.$set(record, 'upload_error', error.message || '录音上传失败');
|
|
|
+ if (this.records.includes(record)) {
|
|
|
+ this.emitRecords();
|
|
|
+ this.$message.error('录音上传或合并失败,请检查网络后重新录制');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 逐词上传在停止录音时就已开始,这里等它们完成后再合并整条录音。
|
|
|
+ * 与课文组件一致:合并结果同时保留可播放地址(src)与 file_id。
|
|
|
+ */
|
|
|
+ async finalizeRecord(record) {
|
|
|
+ await Promise.all(record.words.map((word) => this.segmentTasks.get(word.segment) || Promise.resolve()));
|
|
|
+ if (record.words.length === 1) {
|
|
|
+ const segment = record.words[0].segment;
|
|
|
+ this.$set(record, 'wavData', segment.wavData);
|
|
|
+ this.$set(record, 'src', segment.file_url || '');
|
|
|
+ } else {
|
|
|
+ const merged = await mergeAudio(record.words.map((word) => word.segment.wavData));
|
|
|
+ if (!merged.audio_file_id) throw new Error('合并录音失败');
|
|
|
+ this.$set(record, 'wavData', merged.audio_file_id);
|
|
|
+ this.$set(record, 'src', merged.audio_file_url || '');
|
|
|
+ if (merged.media_duration) this.$set(record, 'toltime', merged.media_duration);
|
|
|
+ }
|
|
|
+ this.$set(record, 'upload_state', 'done');
|
|
|
+ if (this.records.includes(record)) {
|
|
|
+ this.emitRecords();
|
|
|
+ if (this.selectedRecord === record) this.$emit('getWavblob', record.wavData);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ async stopIfRecording() {
|
|
|
+ if (!this.recording) return;
|
|
|
+ if (this.operation) await this.operation;
|
|
|
+ if (!this.recording) return;
|
|
|
+ if (this.currentIndex + 1 < this.sessionWords.length) this.$message.warning('录音提前结束,已保存已录制的词');
|
|
|
+ await this.next('finish');
|
|
|
+ },
|
|
|
+ abortSession() {
|
|
|
+ clearInterval(this.timer);
|
|
|
+ this.clearSegmentGap();
|
|
|
+ this.sessionGeneration += 1;
|
|
|
+ if (this.recorder && !this.startPromise) releaseRecorder(this.recorder);
|
|
|
+ this.recorder = null;
|
|
|
+ this.startPromise = null;
|
|
|
+ if (this.recording) this.$root.isRecording = false;
|
|
|
+ this.recording = false;
|
|
|
+ this.$emit('recordProgress', null);
|
|
|
+ },
|
|
|
+ pausePlayback() {
|
|
|
+ this.audio.pause();
|
|
|
+ },
|
|
|
+ async cancel() {
|
|
|
+ try {
|
|
|
+ await this.$confirm('取消将放弃本次录音,确定?', '提示', { type: 'warning' });
|
|
|
+ } catch (error) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.abortSession();
|
|
|
+ this.changeRecord(this.selectedIndex);
|
|
|
+ },
|
|
|
+ async playRecording() {
|
|
|
+ if (!this.selectedRecord || this.recording) return;
|
|
|
+ if (this.playing) {
|
|
|
+ this.audio.pause();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const record = this.selectedRecord;
|
|
|
+ if (!record.src && !record.wavData) {
|
|
|
+ this.$message.warning('录音正在合并或合并失败,请稍后重试');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 与课文组件一致:优先播放合并返回的地址,历史答案才按 file_id 解析
|
|
|
+ const src = record.src || (await resolveAudioSrc(record.wavData));
|
|
|
+ if (record !== this.selectedRecord) return;
|
|
|
+ if (!src) {
|
|
|
+ this.$message.warning('录音加载失败,请稍后重试');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.$emit('handleParentPlay');
|
|
|
+ this.audio.src = src;
|
|
|
+ playAudioElement(this.audio);
|
|
|
+ },
|
|
|
+ deleteRecording() {
|
|
|
+ if (this.answerMode) return;
|
|
|
+ if (!this.selectedRecord || this.recording || this.busy || this.scoring) return;
|
|
|
+ this.audio.pause();
|
|
|
+ this.records.splice(this.selectedIndex, 1);
|
|
|
+ this.selectedIndex = this.records.length ? this.records.length - 1 : null;
|
|
|
+ this.emitRecords();
|
|
|
+ this.changeRecord(this.selectedIndex);
|
|
|
+ },
|
|
|
+ async showScore() {
|
|
|
+ const record = this.selectedRecord;
|
|
|
+ if (!record || this.recording || this.busy || this.scoring) return;
|
|
|
+ if (!record.words || !record.words.length) {
|
|
|
+ this.$message.warning('历史录音缺少逐词数据,无法评分,请重新录制');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (record.hasScore) {
|
|
|
+ this.visibleScore = true;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.scoring = true;
|
|
|
+ this.scoreIndex = 0;
|
|
|
+ this.scoreTotal = record.words.length;
|
|
|
+ this.scoreGeneration += 1;
|
|
|
+ const generation = this.scoreGeneration;
|
|
|
+ const scores = [];
|
|
|
+ const needPosition = Boolean(record.selectData && record.selectData.type !== 'cell');
|
|
|
+ const withPosition = (score, word) => {
|
|
|
+ if (needPosition && Number.isFinite(word.row) && Number.isFinite(word.column)) {
|
|
|
+ this.$set(score, 'position', `第${word.row + 1}行 第${word.column + 1}列`);
|
|
|
+ }
|
|
|
+ return score;
|
|
|
+ };
|
|
|
+ try {
|
|
|
+ for (const word of record.words) {
|
|
|
+ try {
|
|
|
+ const value = word.segment.wavData;
|
|
|
+ const lrc = word.lrc_data || {};
|
|
|
+ const hasStandard = this.standardUrl && Number.isFinite(lrc.begin_time) && lrc.end_time > lrc.begin_time;
|
|
|
+ const score = await recordSocreSingle({
|
|
|
+ text: word.text,
|
|
|
+ base64: value,
|
|
|
+ audio_paramter_type: value.startsWith('data:audio/') ? 0 : 1,
|
|
|
+ standard: hasStandard ? 'false' : 'true',
|
|
|
+ });
|
|
|
+ if (generation !== this.scoreGeneration || !this.records.includes(record)) return;
|
|
|
+ if (![score.accuracy, score.fluency, score.integrity].every(Number.isFinite)) {
|
|
|
+ throw new Error('评分结果不完整');
|
|
|
+ }
|
|
|
+ score.score_total = Math.max(
|
|
|
+ 0,
|
|
|
+ Math.min(100, Math.round((score.accuracy + score.fluency + score.integrity) / 3)),
|
|
|
+ );
|
|
|
+ score.text = word.text;
|
|
|
+ score.isShow = false;
|
|
|
+ if (hasStandard) {
|
|
|
+ score.audio_url_standard = this.standardUrl;
|
|
|
+ score.audio_url_standard_bg = lrc.begin_time;
|
|
|
+ score.audio_url_standard_ed = lrc.end_time;
|
|
|
+ }
|
|
|
+ scores.push(withPosition(score, word));
|
|
|
+ } catch (error) {
|
|
|
+ // 与课文组件一致:单个词失败留占位继续,详情里显示「未读」,单元格气泡显示未读样式
|
|
|
+ console.error('语音矩阵单词评分失败', error);
|
|
|
+ scores.push(withPosition({ text: word.text, isShow: false }, word));
|
|
|
+ }
|
|
|
+ this.scoreIndex += 1;
|
|
|
+ }
|
|
|
+ if (generation !== this.scoreGeneration || !this.records.includes(record)) return;
|
|
|
+ record.words.forEach((word, index) => this.$set(word, 'score', scores[index]));
|
|
|
+ this.$set(record, 'hasScore', true);
|
|
|
+ this.emitRecords();
|
|
|
+ this.$emit('selectRecord', record);
|
|
|
+ this.visibleScore = true;
|
|
|
+ } finally {
|
|
|
+ if (generation === this.scoreGeneration) this.scoring = false;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ handleReset() {
|
|
|
+ this.scoreGeneration += 1;
|
|
|
+ this.scoring = false;
|
|
|
+ this.visibleScore = false;
|
|
|
+ this.abortSession();
|
|
|
+ this.audio.pause();
|
|
|
+ this.records = [];
|
|
|
+ this.selectedIndex = null;
|
|
|
+ this.emitRecords();
|
|
|
+ this.changeRecord(null);
|
|
|
+ },
|
|
|
+ },
|
|
|
+};
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="scss" scoped>
|
|
|
+.matrix-record {
|
|
|
+ display: block;
|
|
|
+ flex: 1 1 auto;
|
|
|
+ min-width: 0;
|
|
|
+}
|
|
|
+
|
|
|
+.record-controls {
|
|
|
+ display: flex;
|
|
|
+ flex-wrap: nowrap;
|
|
|
+ gap: 8px;
|
|
|
+ align-items: center;
|
|
|
+ min-width: 0;
|
|
|
+ min-height: 32px;
|
|
|
+
|
|
|
+ :deep .el-select {
|
|
|
+ flex: 0 0 136px;
|
|
|
+ width: 136px;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+.record-action,
|
|
|
+.play-back {
|
|
|
+ flex: 0 0 auto;
|
|
|
+ cursor: pointer;
|
|
|
+}
|
|
|
+
|
|
|
+.record-action.unavailable {
|
|
|
+ color: #b0b0b0;
|
|
|
+}
|
|
|
+
|
|
|
+.play-back {
|
|
|
+ width: 20px;
|
|
|
+ height: 20px;
|
|
|
+}
|
|
|
+
|
|
|
+.record-time {
|
|
|
+ flex: 0 0 auto;
|
|
|
+ min-width: 42px;
|
|
|
+ font-size: 14px;
|
|
|
+}
|
|
|
+
|
|
|
+.selection-tip {
|
|
|
+ flex: 0 1 auto;
|
|
|
+ min-width: 0;
|
|
|
+ overflow: hidden;
|
|
|
+ font-size: 12px;
|
|
|
+ color: #8b97a8;
|
|
|
+ text-overflow: ellipsis;
|
|
|
+ white-space: nowrap;
|
|
|
+}
|
|
|
+
|
|
|
+// 评分、整体录音、已选提示固定为录音条最后一组
|
|
|
+.record-tail {
|
|
|
+ display: flex;
|
|
|
+ flex: 0 1 auto;
|
|
|
+ flex-wrap: nowrap;
|
|
|
+ gap: 8px;
|
|
|
+ align-items: center;
|
|
|
+ min-width: 0;
|
|
|
+}
|
|
|
+
|
|
|
+.whole-btn {
|
|
|
+ flex: 0 0 auto;
|
|
|
+ color: #e05252;
|
|
|
+ border-color: #e05252;
|
|
|
+ border-radius: 16px;
|
|
|
+}
|
|
|
+
|
|
|
+.score-progress {
|
|
|
+ position: fixed;
|
|
|
+ top: 50%;
|
|
|
+ left: 50%;
|
|
|
+ z-index: 1;
|
|
|
+ display: flex;
|
|
|
+ flex-wrap: wrap;
|
|
|
+ gap: 8px;
|
|
|
+ align-items: center;
|
|
|
+ padding: 10px 18px;
|
|
|
+ font-size: 14px;
|
|
|
+ color: #44515f;
|
|
|
+ background: rgba(255, 255, 255, 97%);
|
|
|
+ border-radius: 14px;
|
|
|
+ box-shadow: 0 8px 30px rgba(30, 50, 80, 25%);
|
|
|
+ transform: translate(-50%, -50%);
|
|
|
+
|
|
|
+ .el-icon-loading {
|
|
|
+ font-size: 20px;
|
|
|
+ }
|
|
|
+}
|
|
|
+</style>
|