SanHQin hai 4 meses
pai
achega
bdfbc76655

+ 82 - 33
src/components/pages/classroomObservation/components/baseMessage.vue

@@ -306,7 +306,7 @@
 		<previewVideoDialog ref="previewVideoDialogRef" />
 		<uploadFile v-if="progressData.uploadVideo" ref="uploadFileRef" @progressUpdate="videoProgressUpdate" @delUpload="videoDelUpload" @success="updateVideoSuccess" @startUpload="videoStartUpload"/>
 		<resourceLibraryDialog ref="resourceLibraryDialogRef" @addFile="resourceLibraryDialogAddFile"/>
-		<iframe ref="iframeFFmpegRef" allow="camera *; microphone *;display-capture;midi;encrypted-media;" src="https://beta.pbl.cocorobo.cn/pbl-teacher-table/dist/static/cocoroboffmpeg/index.html" v-show="false"></iframe>https://beta.pbl.cocorobo.cn/pbl-teacher-table/dist/#/cocoroboffmpeg  http://localhost:8080/#/cocoroboffmpeg
+		<!-- <iframe ref="iframeFFmpegRef" allow="camera *; microphone *;display-capture;midi;encrypted-media;" src="https://beta.pbl.cocorobo.cn/pbl-teacher-table/dist/static/cocoroboffmpeg/index.html" v-show="false"></iframe>https://beta.pbl.cocorobo.cn/pbl-teacher-table/dist/#/cocoroboffmpeg  http://localhost:8080/#/cocoroboffmpeg -->
 	</div>
 </template>
 
@@ -627,13 +627,13 @@ export default {
 					url: data.Location,
 			})
 			this.$message.success("上传成功");
-			this.uploadFileObj = null;
-			// this.$confirm("是否提取视频音频并上传?","提示").then(()=>{
-			// 	this.getVideoVoice({file:this.uploadFileObj});
-			// 	this.uploadFileObj = null;
-			// }).catch(err=>{
-			// 	this.uploadFileObj = null;
-			// })
+			// this.uploadFileObj = null;
+			this.$confirm("是否提取视频音频并上传?","提示").then(()=>{
+				this.getVideoVoice({file:this.uploadFileObj});
+				this.uploadFileObj = null;
+			}).catch(err=>{
+				this.uploadFileObj = null;
+			})
 		},
 		videoProgressUpdate(data){
 			if(data.status=="processing"){
@@ -871,9 +871,9 @@ ${this.data.editorBarData?this.data.editorBarData.content:""}
 			})
 			this.$message.success("上传成功")
 
-			// this.$confirm("是否提取视频音频并上传?","提示").then(()=>{
-			// 	this.getVideoVoice({url:_file.file});
-			// })
+			this.$confirm("是否提取视频音频并上传?","提示").then(()=>{
+				this.getVideoVoice({url:_file.file});
+			})
 		},
 		async getVideoVoice(obj){
 			if(this.loading)return this.$message.info("请稍等");
@@ -897,11 +897,37 @@ ${this.data.editorBarData?this.data.editorBarData.content:""}
 			if (!_file) return this.$message.error("文件不存在");
 
 			try {
-				await this.$refs.iframeFFmpegRef.contentWindow.postMessage({type:'extractAudio',file:_file},"https://beta.pbl.cocorobo.cn/");
+				const reader = new FileReader();
+				reader.onload = async (e) =>{
+					// 创建音频上下文
+					const audioContext = new (window.AudioContext || window.webkitAudioContext)();
+
+					//解码音频数据
+					const buffer = await audioContext.decodeAudioData(e.target.result);
+
+					//创建离线音频上下文
+					const offlineAudioContext = new OfflineAudioContext({numberOfChannels:buffer.numberOfChannels,length:buffer.length,sampleRate:buffer.sampleRate});
+
+					//创建音源节点
+					const source = offlineAudioContext.createBufferSource();
+					source.buffer = buffer;
+					source.connect(offlineAudioContext.destination);
+					source.start();
+
+					//渲染音频
+					const renderedBuffer = await offlineAudioContext.startRendering();
+					const wavBlob = this.bufferToWav(renderedBuffer);
 
-			// this.$message.success("提取音频成功")
-			// this.loading = false;
-			// console.log(data)
+					// blob转成file文件
+					const audioFile = new File([wavBlob], 'audio.wav', { type: 'audio/wav' });
+
+					// console.log(wavBlob)
+
+					this.$emit("getVideoAudioSuccess",audioFile)
+					this.$message.success("提取音频成功")
+					this.loading = false;
+				}
+				reader.readAsArrayBuffer(_file);
 			} catch (error) {
 				console.log(error);
 				this.$message.error("提取音频失败")
@@ -909,24 +935,47 @@ ${this.data.editorBarData?this.data.editorBarData.content:""}
 			}
 
 		},
-		// testFFmpeg(){
-		// 	let input = document.createElement("input");
-		// 	input.type = "file";
-		// 	input.accept = "video/*";
-		// 	input.click();
-		// 	input.onchange = () => {
-		// 		let file = input.files[0];
-		// 		setTimeout(()=>{
-		// 			var testwindow = window.open("http://localhost:8082/");
-
-		// 			setTimeout(()=>{
-		// 				console.log("测试测试")
-		// 				testwindow.postMessage({type:'extractAudio',file:file},'*');
-		// 			},5000)
-		// 		})
-		// 	}
-			
-		// }
+		bufferToWav(audioBuffer) {
+        const numOfChan = audioBuffer.numberOfChannels;
+        const length = audioBuffer.length * numOfChan * 2;
+        const buffer = new ArrayBuffer(44 + length);
+        const view = new DataView(buffer);
+        const channels = [];
+        let pos = 0;
+        // 获取通道数据
+        for (let i = 0; i < audioBuffer.numberOfChannels; i++) {
+            channels.push(audioBuffer.getChannelData(i));
+        }
+        // 写入WAV头
+        this.writeUTFBytes(view, 0, 'RIFF');
+        view.setUint32(4, 44 + length - 8, true);
+        this.writeUTFBytes(view, 8, 'WAVE');
+        this.writeUTFBytes(view, 12, 'fmt ');
+        view.setUint32(16, 16, true);
+        view.setUint16(20, 1, true);
+        view.setUint16(22, numOfChan, true);
+        view.setUint32(24, audioBuffer.sampleRate, true);
+        view.setUint32(28, audioBuffer.sampleRate * 2 * numOfChan, true);
+        view.setUint16(32, numOfChan * 2, true);
+        view.setUint16(34, 16, true);
+        this.writeUTFBytes(view, 36, 'data');
+        view.setUint32(40, length, true);
+        // 写入PCM数据
+        pos = 44;
+        for (let i = 0; i < audioBuffer.length; i++) {
+            for (let j = 0; j < numOfChan; j++) {
+                const sample = Math.max(-1, Math.min(1, channels[j][i]));
+                view.setInt16(pos, sample < 0 ? sample * 0x8000 : sample * 0x7FFF, true);
+                pos += 2;
+            }
+        }
+        return new Blob([buffer], { type: 'audio/wav' });
+    },
+		writeUTFBytes(view, offset, string) {
+        for (let i = 0; i < string.length; i++) {
+            view.setUint8(offset + i, string.charCodeAt(i));
+        }
+    }
 	},
 	mounted() {
 		window.addEventListener('message',(e)=>{

+ 37 - 3
src/components/pages/classroomObservation/components/chatArea.vue

@@ -64,6 +64,15 @@
         v-if="pageStatus == 2 && !showIndexPage && editorBarData.type == '0'"
         v-loading="uploadFileLoading"
       >
+				
+				<el-button
+          style="position: absolute; bottom: 20px; right: 185px; z-index: 10002"
+          size="small"
+					v-if="wavGetTextLoading"
+          type="danger"
+          @click.stop="stopWavGetText()"
+          >终止转译</el-button
+        >
         <el-popover placement="top" trigger="hover">
           <el-button size="small" @click.stop="startContinuousJobs('role')">
             说话人编码
@@ -680,7 +689,9 @@ export default {
       textareaLoading: false,
       showRoleList: false,
       showGetTextLoading: false,
+			wavGetTextLoading:false,
       roleListIndex: 0,
+
       userId: this.$route.query["userid"],
       recordedForm: {
         time: "00:00:00", //时间
@@ -1480,7 +1491,9 @@ ${JSON.stringify(_list)}
       console.log("将转录的文件👇");
       console.log(_file);
 
-      iiframe.contentWindow.window.document.getElementById(
+      try {
+				this.wavGetTextLoading = true;
+				iiframe.contentWindow.window.document.getElementById(
         "languageOptions"
       ).selectedIndex = this.languageRadio;
       _this.transcriptionData.content = "";
@@ -1498,7 +1511,8 @@ ${JSON.stringify(_list)}
           _this.editorBarData.content = "";
           textList = [];
         }
-        _this.showGetTextLoading = true;
+					_this.wavGetTextLoading = true;
+				_this.showGetTextLoading = true;
         let privText = e.privText;
         console.log("👇转译对象👇");
         console.log(e);
@@ -1557,19 +1571,39 @@ ${JSON.stringify(_list)}
         _this.editorBarData.content = _result;
         // _this.editorBarData.content += privText;
       };
-
+			
       iiframe.contentWindow.onSessionStopped = function(e) {
         console.log("转译完成");
         console.log(e);
         _this.$message.success("转译完成");
         _this.showGetTextLoading = false;
+				_this.wavGetTextLoading = false;
         _this.saveEditorBar();
       };
 
       iiframe.contentWindow.doContinuousPronunciationAssessment("", {
         files: [_file]
       });
+			} catch (error) {
+				this.wavGetTextLoading = false;
+				this.showGetTextLoading = false;
+			}
     },
+		stopWavGetText(){
+			if(this.wavGetTextLoading){
+				try {
+					let iiframe = this.$refs["iiframe"];
+					iiframe.contentWindow.scenarioStopButton.click();
+					this.wavGetTextLoading = false;
+					this.showGetTextLoading = false;
+					this.$message.success("终止转译成功")
+				} catch (error) {
+					this.$message.error("终止转译失败")
+				}
+			}else {
+				this.$message.error("转译未开始")
+			}
+		},
     uploadFile(file, { changeText = true, flag = true }) {
       var credentials = {
         accessKeyId: "AKIATLPEDU37QV5CHLMH",

+ 1 - 0
static/cocoroboffmpeg/css/app.1d41ea99.css

@@ -0,0 +1 @@
+.ffmpeg[data-v-f4706aa4]{width:100vw;height:100vh;background-color:#fff}

+ 0 - 1
static/cocoroboffmpeg/css/app.eccff850.css

@@ -1 +0,0 @@
-.ffmpeg[data-v-3f0ba4f2]{width:100vw;height:100vh;background-color:#fff}

+ 1 - 1
static/cocoroboffmpeg/index.html

@@ -6,7 +6,7 @@
 			rel="icon" href="./favicon.ico"><base
 			target="_blank"><title>ffmpeg</title><script defer="defer"
 			src="./js/chunk-vendors.8366e8e5.js"></script><script defer="defer"
-			src="./js/app.a548209a.js"></script><link href="./css/app.eccff850.css"
+			src="./js/app.5c23ccd0.js"></script><link href="./css/app.1d41ea99.css"
 			rel="stylesheet"></head><body><noscript><strong>We're sorry but vue2-project
 				doesn't work properly without JavaScript enabled. Please enable it to
 				continue.</strong></noscript><div

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
static/cocoroboffmpeg/js/app.5c23ccd0.js


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
static/cocoroboffmpeg/js/app.5c23ccd0.js.map


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
static/cocoroboffmpeg/js/app.a548209a.js


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
static/cocoroboffmpeg/js/app.a548209a.js.map


Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio