|
@@ -116,6 +116,11 @@ export default {
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
methods: {
|
|
methods: {
|
|
|
|
|
+ // 清理 iframe 录音会话(统一清理入口)
|
|
|
|
|
+ _cleanupTranscriber(iframe) {
|
|
|
|
|
+ iframe.contentWindow.onSessionStopped = null;
|
|
|
|
|
+ iframe.contentWindow.window.onRecognizedResult = null;
|
|
|
|
|
+ },
|
|
|
// 更新作业
|
|
// 更新作业
|
|
|
changeWorkData(newValue) {
|
|
changeWorkData(newValue) {
|
|
|
this.$emit("changeWorkData", JSON.stringify(newValue));
|
|
this.$emit("changeWorkData", JSON.stringify(newValue));
|
|
@@ -124,52 +129,64 @@ export default {
|
|
|
changeAnswer(newValue) {
|
|
changeAnswer(newValue) {
|
|
|
this.work.answer = newValue;
|
|
this.work.answer = newValue;
|
|
|
},
|
|
},
|
|
|
- // 开始录音
|
|
|
|
|
|
|
+ // 开始录音 — 先请求权限,权限通过后再启动转录
|
|
|
startRecord() {
|
|
startRecord() {
|
|
|
let iframe = this.$refs["iframeRef"];
|
|
let iframe = this.$refs["iframeRef"];
|
|
|
- if(this.lang.lang == 'com'){
|
|
|
|
|
- iframe.contentWindow.window.document.getElementById(
|
|
|
|
|
- "languageOptions"
|
|
|
|
|
- ).selectedIndex = 8;
|
|
|
|
|
- }else if(this.lang.lang == 'hk'){
|
|
|
|
|
- iframe.contentWindow.window.document.getElementById(
|
|
|
|
|
- "languageOptions"
|
|
|
|
|
- ).selectedIndex = 4;
|
|
|
|
|
- }else{
|
|
|
|
|
- iframe.contentWindow.window.document.getElementById(
|
|
|
|
|
- "languageOptions"
|
|
|
|
|
- ).selectedIndex = 2;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ const langMap = { com: 8, hk: 4 };
|
|
|
|
|
+ const idx = langMap[this.lang.lang] || 2;
|
|
|
|
|
+ iframe.contentWindow.window.document.getElementById("languageOptions").selectedIndex = idx;
|
|
|
|
|
|
|
|
- iframe.contentWindow.window.onRecognizedResult = e => {
|
|
|
|
|
- console.log("onRecognizedResult", e)
|
|
|
|
|
- let privText = e.privText;
|
|
|
|
|
- console.log("👇转译对象👇");
|
|
|
|
|
- console.log(e);
|
|
|
|
|
- console.log("👇转译结果👇");
|
|
|
|
|
- console.log(privText);
|
|
|
|
|
- if (!privText) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ const startTranscriber = () => {
|
|
|
|
|
+ iframe.contentWindow.window.onRecognizedResult = e => {
|
|
|
|
|
+ console.log("onRecognizedResult", e)
|
|
|
|
|
+ let privText = e.privText;
|
|
|
|
|
+ console.log("👇转译对象👇");
|
|
|
|
|
+ console.log(e);
|
|
|
|
|
+ console.log("👇转译结果👇");
|
|
|
|
|
+ console.log(privText);
|
|
|
|
|
+ if (!privText) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // 获取wangEnduit富文本组件实例
|
|
|
|
|
- const editorComponent = this.$refs.wangEnduitRef;
|
|
|
|
|
- if (editorComponent && editorComponent.editor) {
|
|
|
|
|
- // 获取当前光标位置并插入文本
|
|
|
|
|
- editorComponent.editor.cmd.do('insertText', privText);
|
|
|
|
|
- // 同步内容到work.answer
|
|
|
|
|
- this.work.answer = editorComponent.editor.txt.html();
|
|
|
|
|
- } else {
|
|
|
|
|
- // 如果获取不到富文本实例,则直接追加
|
|
|
|
|
- this.work.answer += privText;
|
|
|
|
|
- }
|
|
|
|
|
- console.log(privText)
|
|
|
|
|
|
|
+ // 获取wangEnduit富文本组件实例
|
|
|
|
|
+ const editorComponent = this.$refs.wangEnduitRef;
|
|
|
|
|
+ if (editorComponent && editorComponent.editor) {
|
|
|
|
|
+ // 获取当前光标位置并插入文本
|
|
|
|
|
+ editorComponent.editor.cmd.do('insertText', privText);
|
|
|
|
|
+ // 同步内容到work.answer
|
|
|
|
|
+ this.work.answer = editorComponent.editor.txt.html();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 如果获取不到富文本实例,则直接追加
|
|
|
|
|
+ this.work.answer += privText;
|
|
|
|
|
+ }
|
|
|
|
|
+ console.log(privText)
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
|
|
+ iframe.contentWindow.ConversationTranscriber();
|
|
|
|
|
+ this.recordObj.status = "1"
|
|
|
|
|
+ this.recordObj.startTime = new Date().getTime();
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- iframe.contentWindow.ConversationTranscriber();
|
|
|
|
|
- this.recordObj.status = "1"
|
|
|
|
|
- this.recordObj.startTime = new Date().getTime();
|
|
|
|
|
|
|
+ // 先通过 getUserMedia 主动请求麦克风权限,避免 ConversationTranscriber
|
|
|
|
|
+ // 在浏览器权限弹窗期间被中断导致内部状态异常
|
|
|
|
|
+ if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
|
|
|
|
|
+ navigator.mediaDevices.getUserMedia({ audio: true })
|
|
|
|
|
+ .then(stream => {
|
|
|
|
|
+ // 权限已获取,立即释放 stream,让 ConversationTranscriber 自己接管麦克风
|
|
|
|
|
+ stream.getTracks().forEach(t => t.stop());
|
|
|
|
|
+ startTranscriber();
|
|
|
|
|
+ })
|
|
|
|
|
+ .catch(() => {
|
|
|
|
|
+ // 用户拒绝权限
|
|
|
|
|
+ this._cleanupTranscriber(iframe);
|
|
|
|
|
+ this.$message.success(this.lang.ssNoPermStop);
|
|
|
|
|
+ });
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 降级:不支持 getUserMedia 的浏览器直接启动
|
|
|
|
|
+ startTranscriber();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 预留 2 秒后的兜底权限检查(处理用户后续在浏览器设置中撤销权限的情况)
|
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
|
navigator.permissions && navigator.permissions.query({ name: 'microphone' }).then(permissionStatus => {
|
|
navigator.permissions && navigator.permissions.query({ name: 'microphone' }).then(permissionStatus => {
|
|
|
if (permissionStatus.state !== "granted") {
|
|
if (permissionStatus.state !== "granted") {
|
|
@@ -177,7 +194,7 @@ export default {
|
|
|
this.recordObj.status = "0";
|
|
this.recordObj.status = "0";
|
|
|
this.recordObj.loading = false;
|
|
this.recordObj.loading = false;
|
|
|
iframe.contentWindow.onSessionStopped = null;
|
|
iframe.contentWindow.onSessionStopped = null;
|
|
|
- iframe.contentWindow.window.onRecognizedResult = null;
|
|
|
|
|
|
|
+ this._cleanupTranscriber(iframe);
|
|
|
this.$message.success(this.lang.ssNoPermStop);
|
|
this.$message.success(this.lang.ssNoPermStop);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
@@ -189,16 +206,14 @@ export default {
|
|
|
if (new Date().getTime() - this.recordObj.startTime < 2000) {
|
|
if (new Date().getTime() - this.recordObj.startTime < 2000) {
|
|
|
return this.$message.info(this.lang.ssRecordShort)
|
|
return this.$message.info(this.lang.ssRecordShort)
|
|
|
}
|
|
}
|
|
|
|
|
+ const iframe = this.$refs["iframeRef"];
|
|
|
// 判断浏览器是否有开启录音权限
|
|
// 判断浏览器是否有开启录音权限
|
|
|
navigator.permissions && navigator.permissions.query({ name: 'microphone' }).then(permissionStatus => {
|
|
navigator.permissions && navigator.permissions.query({ name: 'microphone' }).then(permissionStatus => {
|
|
|
if (permissionStatus.state !== "granted") {
|
|
if (permissionStatus.state !== "granted") {
|
|
|
// 没有开启录音权限,直接确定停止录音
|
|
// 没有开启录音权限,直接确定停止录音
|
|
|
this.recordObj.status = "0";
|
|
this.recordObj.status = "0";
|
|
|
this.recordObj.loading = false;
|
|
this.recordObj.loading = false;
|
|
|
- let iframe = this.$refs["iframeRef"];
|
|
|
|
|
- iframe.contentWindow.onSessionStopped = null;
|
|
|
|
|
- iframe.contentWindow.window.onRecognizedResult = null;
|
|
|
|
|
-
|
|
|
|
|
|
|
+ this._cleanupTranscriber(iframe);
|
|
|
this.$message.success(this.lang.ssNoPermStop);
|
|
this.$message.success(this.lang.ssNoPermStop);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
@@ -206,7 +221,6 @@ export default {
|
|
|
// 有权限再判断状态
|
|
// 有权限再判断状态
|
|
|
if (this.recordObj.status == '1' && !this.recordObj.loading) {
|
|
if (this.recordObj.status == '1' && !this.recordObj.loading) {
|
|
|
console.log("测试测3333")
|
|
console.log("测试测3333")
|
|
|
- let iframe = this.$refs["iframeRef"];
|
|
|
|
|
this.recordObj.loading = true;
|
|
this.recordObj.loading = true;
|
|
|
iframe.contentWindow.window.document
|
|
iframe.contentWindow.window.document
|
|
|
.getElementById("scenarioStopButton")
|
|
.getElementById("scenarioStopButton")
|
|
@@ -216,26 +230,21 @@ export default {
|
|
|
this.recordObj.loading = false;
|
|
this.recordObj.loading = false;
|
|
|
this.$message.success(this.lang.ssStoppedRec)
|
|
this.$message.success(this.lang.ssStoppedRec)
|
|
|
iframe.contentWindow.onSessionStopped = null;
|
|
iframe.contentWindow.onSessionStopped = null;
|
|
|
- iframe.contentWindow.window.onRecognizedResult = null;
|
|
|
|
|
|
|
+ this._cleanupTranscriber(iframe);
|
|
|
};
|
|
};
|
|
|
} else {
|
|
} else {
|
|
|
this.recordObj.status = "0";
|
|
this.recordObj.status = "0";
|
|
|
this.recordObj.loading = false;
|
|
this.recordObj.loading = false;
|
|
|
- let iframe = this.$refs["iframeRef"];
|
|
|
|
|
- iframe.contentWindow.onSessionStopped = null;
|
|
|
|
|
- iframe.contentWindow.window.onRecognizedResult = null;
|
|
|
|
|
|
|
+ this._cleanupTranscriber(iframe);
|
|
|
}
|
|
}
|
|
|
}).catch(() => {
|
|
}).catch(() => {
|
|
|
console.log("测试测4444试")
|
|
console.log("测试测4444试")
|
|
|
// 浏览器不支持或异常,默认直接停止
|
|
// 浏览器不支持或异常,默认直接停止
|
|
|
this.recordObj.status = "0";
|
|
this.recordObj.status = "0";
|
|
|
this.recordObj.loading = false;
|
|
this.recordObj.loading = false;
|
|
|
- let iframe = this.$refs["iframeRef"];
|
|
|
|
|
- iframe.contentWindow.onSessionStopped = null;
|
|
|
|
|
- iframe.contentWindow.window.onRecognizedResult = null;
|
|
|
|
|
|
|
+ this._cleanupTranscriber(this.$refs["iframeRef"]);
|
|
|
this.$message.success(this.lang.ssMicCheckStop);
|
|
this.$message.success(this.lang.ssMicCheckStop);
|
|
|
});
|
|
});
|
|
|
- // this.recordObj.status = "0"
|
|
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
mounted() {
|
|
mounted() {
|