SanHQin 11 months ago
parent
commit
57bcdcdc96
1 changed files with 80 additions and 50 deletions
  1. 80 50
      src/components/classRoomHelper/component/levitatedSphere.vue

+ 80 - 50
src/components/classRoomHelper/component/levitatedSphere.vue

@@ -86,6 +86,11 @@ export default {
   },
   methods: {
     recordStart(_text) {
+      var OpenCC = require("opencc-js");
+      let converter = OpenCC.Converter({
+        from: "hk",
+        to: "cn"
+      });
       // try {
       // this.$parent.changeRecordType(1);
       // return this.$message.success("已开启语音助手,请说“可可同学”来唤醒")
@@ -100,12 +105,14 @@ export default {
       this.$parent.changeRecordType(1);
       this.isOpen = true;
       iiframe.contentWindow.onRecognizedResult = e => {
-        let _msg = e.privText;
+        let _msg = converter(e.privText);
+        // let _msg2 = e.privText;
         // let _msg = _text;
         console.log("👇");
         console.log(_msg);
+        // _msg = converter(_msg)
         if (!_msg) return console.log("输出为空");
-        if (_msg.indexOf("可可同学") != -1 && !this.show) {
+        if (_msg.indexOf(converter("可可同学")) != -1 && !this.show) {
           this.aiText = "您好,我是小可,有什么可以帮助您的?";
           this.aiStatus = 0;
           this.showIndex = 0;
@@ -113,12 +120,19 @@ export default {
           console.log("已唤醒");
           return;
         } else if (this.show == true) {
-					if(_msg.indexOf('可可同学')!=-1 && _msg.indexOf("停止")!=-1){
-						this.stopTalk();
-          }else if (this.showTextIndex == 2 || this.chatLoading || this.talkLoading) {
+          if (
+            _msg.indexOf(converter("可可同学")) != -1 &&
+            _msg.indexOf(converter("停止")) != -1
+          ) {
+            this.stopTalk();
+          } else if (
+            this.showTextIndex == 2 ||
+            this.chatLoading ||
+            this.talkLoading
+          ) {
             return console.log("组织语言中");
-					// }else if(_msg.indexOf('可可同学')!=-1 && _msg.indexOf("停止")!=-1){
-					// 	this.stopTalk();
+            // }else if(_msg.indexOf('可可同学')!=-1 && _msg.indexOf("停止")!=-1){
+            // 	this.stopTalk();
           } else {
             this.showTextIndex = 1;
             this.aiText = "";
@@ -129,10 +143,10 @@ export default {
               this.timer = null;
             }
             this.timer = setTimeout(() => {
-              if (this.userText.indexOf("关闭语音助手") != -1) {
+              if (this.userText.indexOf(converter("关闭语音助手")) != -1) {
                 // return setTimeout(()=>{
                 this.show = false;
-								this.showTextIndex = 3;
+                this.showTextIndex = 3;
                 this.aiStatus = 2;
                 this.aiText = "";
                 this.userText = "";
@@ -142,9 +156,12 @@ export default {
               }
               this.showTextIndex = 2;
               this.aiText = "";
-              if (/计时(.+)分钟/.test(this.userText)) {
+              let regExp = new RegExp(
+                converter("计时") + "(.+)" + converter("分钟")
+              );
+              if (regExp.test(this.userText)) {
                 // setTimeout(() => {
-                let _number = this.userText.match(/计时(.+)分钟/)[1];
+                let _number = this.userText.match(regExp)[1];
                 let _time = 0;
                 if (!/^\d+$/.test(_number)) {
                   _time = this.chineseToNumber(_number) * 60;
@@ -156,7 +173,7 @@ export default {
                 this.showTextIndex = 0;
                 this.aiText =
                   "好的,我已为您计时" +
-                  this.userText.match(/计时(.+)分钟/)[1] +
+                  this.userText.match(regExp)[1] +
                   "分钟。";
                 this.userText = "";
                 this.timer = setTimeout(() => {
@@ -185,7 +202,10 @@ export default {
                     params
                   )
                   .then(res => {
-                    if (res.data.FunctionResponse.result == "发送成功") {
+                    if (
+                      converter(res.data.FunctionResponse.result) ==
+                      converter("发送成功")
+                    ) {
                       this.userText = "";
                     } else {
                       // this.$message.warning(res.data.FunctionResponse.result);
@@ -240,16 +260,16 @@ export default {
       iiframe.contentWindow.window.document
         .getElementById("scenarioStopButton")
         .click();
-				if(this.talkLoading){
-					this.stopTalk();
-				}
-			// this.stopTalk();
+      if (this.talkLoading) {
+        this.stopTalk();
+      }
+      // this.stopTalk();
       // 录音借宿
       iiframe.contentWindow.onSessionStopped = (s, e) => {
         this.isOpen = false;
         this.show = false;
         this.showTextIndex = 3;
-				this.showIndex = 2;
+        this.showIndex = 2;
         this.$parent.changeRecordType(0);
         this.$message.success("已关闭语音助手");
         if (this.talkLoading) {
@@ -260,6 +280,12 @@ export default {
       };
     },
     chineseToNumber(chinese) {
+      var OpenCC = require("opencc-js");
+      let converter = OpenCC.Converter({
+        from: "hk",
+        to: "cn"
+      });
+      chinese = converter(chinese);
       const chineseNumbers = {
         零: 0,
         一: 1,
@@ -399,15 +425,19 @@ export default {
           this.timer = null;
         }
         console.log(`👉转语音:${_text}`);
-				// if(this.talkTextList.length==0){
-				// 	console.log("👉最后一个了,执行结束 👈")
-				// 	_talkTextIiframe2.contentWindow.closesynthesizer();
-				// }
+        // if(this.talkTextList.length==0){
+        // 	console.log("👉最后一个了,执行结束 👈")
+        // 	_talkTextIiframe2.contentWindow.closesynthesizer();
+        // }
         // setTimeout(()=>{
         // 	this.talkText();
         // },2000)
-        _talkTextIiframe2.contentWindow.texttospeech(_text, this.talkText,this.endTalk);
-      }else {
+        _talkTextIiframe2.contentWindow.texttospeech(
+          _text,
+          this.talkText,
+          this.endTalk
+        );
+      } else {
         // console.log("👉转语音结束👈");
         _talkTextIiframe2.contentWindow.closesynthesizer();
         // this.talkLoading = false;
@@ -420,24 +450,24 @@ export default {
         // }, 5000);
       }
     },
-		endTalk(){
-			console.log("👉转语音结束👈");
-			// let _talkTextIiframe2 = this.$refs.iiframe2;
-			// _talkTextIiframe2.contentWindow.closesynthesizer();
-			this.talkLoading = false;
-		},
-		stopTalk(){
-			this.talkTextList = [];
+    endTalk() {
+      console.log("👉转语音结束👈");
+      // let _talkTextIiframe2 = this.$refs.iiframe2;
+      // _talkTextIiframe2.contentWindow.closesynthesizer();
+      this.talkLoading = false;
+    },
+    stopTalk() {
+      this.talkTextList = [];
 
-			let _talkTextIiframe2 = this.$refs.iiframe2;
-			_talkTextIiframe2.contentWindow.closesynthesizer();
-			_talkTextIiframe2.contentWindow.pausesynthesizer();
-			this.talkLoading = false;
-			// this.talkLoading = false;
-			// this.talkLoading = false;
-			// let _talkTextIiframe2 = this.$refs.iiframe2;
-			// _talkTextIiframe2.contentWindow.closesynthesizer();
-		},
+      let _talkTextIiframe2 = this.$refs.iiframe2;
+      _talkTextIiframe2.contentWindow.closesynthesizer();
+      _talkTextIiframe2.contentWindow.pausesynthesizer();
+      this.talkLoading = false;
+      // this.talkLoading = false;
+      // this.talkLoading = false;
+      // let _talkTextIiframe2 = this.$refs.iiframe2;
+      // _talkTextIiframe2.contentWindow.closesynthesizer();
+    }
   },
   mounted() {
     // // this.recordStart()
@@ -471,19 +501,19 @@ export default {
   position: absolute;
   top: 0;
   right: 0;
-	animation: smallToBig 1s both;
+  animation: smallToBig 1s both;
 }
 
 /* 定义渐入动画 */
 @keyframes smallToBig {
-    from {
-        opacity: 0;
-        transform: scale(0.1);
-    }
-    to {
-        opacity: 1;
-        transform: scale(1);
-    }
+  from {
+    opacity: 0;
+    transform: scale(0.1);
+  }
+  to {
+    opacity: 1;
+    transform: scale(1);
+  }
 }
 
 .ls_text {