SanHQin 8 months ago
parent
commit
55fdcc431c

+ 232 - 202
src/components/classRoomHelper/component/levitatedSphere.vue

@@ -27,7 +27,10 @@
       }"
     >
       <div class="ls_t_ai" v-if="[0, 2].includes(showTextIndex)">
-        <span v-if="[0].includes(showTextIndex)" v-html="htmlContent(aiText)"></span>
+        <span
+          v-if="[0].includes(showTextIndex)"
+          v-html="htmlContent(aiText)"
+        ></span>
         <span v-if="[2].includes(showTextIndex)">正在组织语言...</span>
       </div>
       <div class="ls_t_user" v-if="[1].includes(showTextIndex)">
@@ -42,7 +45,7 @@
       v-show="false"
     ></iframe>
 
-		<!-- 文字转语音-->
+    <!-- 文字转语音-->
     <iframe
       allow="camera *; microphone *;display-capture;midi;encrypted-media;"
       src="https://beta.cloud.cocorobo.cn/browser/public/index1.html"
@@ -65,134 +68,139 @@ export default {
       userText: "",
       showTextIndex: 0, //0:ai,1:用户, 2:组织语言  3: 无
       timer: null,
-			isOpen:false,
-			userId:this.$route.query.userid,
-			chatLoading:false,
-			talkLoading:false,
-			source:null,
-			talkTextList:[],
-
+      isOpen: false,
+      userId: this.$route.query.userid,
+      chatLoading: false,
+      talkLoading: false,
+      source: null,
+      talkTextList: []
     };
   },
   computed: {
-		htmlContent() {
+    htmlContent() {
       const md = new MarkdownIt();
       return _md => {
         return md.render(_md);
       };
-    },
+    }
   },
   methods: {
     recordStart(_text) {
       // try {
-			// this.$parent.changeRecordType(1);
-			// return this.$message.success("已开启语音助手,请说“可可同学”来唤醒")
-				if(this.isOpen)return this.$message.info("已开启语音助手,无需重复开启")
-        let iiframe = this.$refs["iiframe"];
-        iiframe.contentWindow.window.document.getElementById(
-          "languageOptions"
-        ).selectedIndex = 2; //普通话
-        iiframe.contentWindow.testdoContinuousPronunciationAssessment();
-				this.$message.success("已开启语音助手,请说“可可同学”来唤醒")
-				this.$parent.changeRecordType(1);
-				this.isOpen = true;
-        iiframe.contentWindow.onRecognizedResult = e => {
-					
-          let _msg = e.privText;
-          // let _msg = _text;
-          console.log("👇");
-          console.log(_msg);
-					if(!_msg)return console.log('输出为空');
-          if (_msg.indexOf("可可同学") != -1 && !this.show) {
-            this.aiText = "您好,我是小可,有什么可以帮助您的?";
-            this.aiStatus = 0;
-            this.showIndex = 0;
-            this.show = true;
-            console.log("已唤醒");
-						return;
-          } else if (this.show == true) {
-            if (this.showTextIndex == 2 || this.chatLoading || this.talkLoading) {
-              return console.log("组织语言中");
-            } else {
-              this.showTextIndex = 1;
-              this.aiText = "";
-              this.userText += _msg;
-              this.aiStatus = 1;
-              if (this.timer) {
-                clearTimeout(this.timer);
-                this.timer = null;
-              }
-              this.timer = setTimeout(() => {
-								if(this.userText.indexOf("关闭语音助手") != -1){
-									// return setTimeout(()=>{
-										this.show = false,
-										this.showTextIndex = 3;
-                    this.aiStatus = 2;
-                    this.aiText = "";
-                    this.userText = "";
-										this.stopRecord();
-										return;
-									// },1000)
-								}
-                this.showTextIndex = 2;
+      // this.$parent.changeRecordType(1);
+      // return this.$message.success("已开启语音助手,请说“可可同学”来唤醒")
+      if (this.isOpen)
+        return this.$message.info("已开启语音助手,无需重复开启");
+      let iiframe = this.$refs["iiframe"];
+      iiframe.contentWindow.window.document.getElementById(
+        "languageOptions"
+      ).selectedIndex = 2; //普通话
+      iiframe.contentWindow.testdoContinuousPronunciationAssessment();
+      this.$message.success("已开启语音助手,请说“可可同学”来唤醒");
+      this.$parent.changeRecordType(1);
+      this.isOpen = true;
+      iiframe.contentWindow.onRecognizedResult = e => {
+        let _msg = e.privText;
+        // let _msg = _text;
+        console.log("👇");
+        console.log(_msg);
+        if (!_msg) return console.log("输出为空");
+        if (_msg.indexOf("可可同学") != -1 && !this.show) {
+          this.aiText = "您好,我是小可,有什么可以帮助您的?";
+          this.aiStatus = 0;
+          this.showIndex = 0;
+          this.show = true;
+          console.log("已唤醒");
+          return;
+        } else if (this.show == true) {
+          if (this.showTextIndex == 2 || this.chatLoading || this.talkLoading) {
+            return console.log("组织语言中");
+          } else {
+            this.showTextIndex = 1;
+            this.aiText = "";
+            this.userText += _msg;
+            this.aiStatus = 1;
+            if (this.timer) {
+              clearTimeout(this.timer);
+              this.timer = null;
+            }
+            this.timer = setTimeout(() => {
+              if (this.userText.indexOf("关闭语音助手") != -1) {
+                // return setTimeout(()=>{
+                (this.show = false), (this.showTextIndex = 3);
+                this.aiStatus = 2;
                 this.aiText = "";
-                if (/计时(.+)分钟/.test(this.userText)) {
-                  // setTimeout(() => {
-										let _number = this.userText.match(/计时(.+)分钟/)[1]
-										let _time = 0;
-										if(!/^\d+$/.test(_number)){
-											_time = this.chineseToNumber(_number)*60;
-										}else{
-											_time = parseInt(_numberList[1])*60
-										}
-                    this.$emit("startTime", _time);
-										this.aiStatus = 0;
-										this.showTextIndex = 0;
-										this.aiText = "好的,我已为您计时"+this.userText.match(/计时(.+)分钟/)[1]+"分钟。";
-										this.userText = "";
-										this.timer = setTimeout(() => {
-											this.showTextIndex = 3;
-											this.aiStatus = 2;
-											this.aiText = "";
-											this.userText = "";
-										}, 3000);
-                  // }, 2000);
-								} else {
-									this.chatLoading = true;
-									const _uuid = uuidv4();
-									let params = {
-      						  assistant_id: 'f8e1ebb2-2e0d-11ef-8bf4-12e77c4cb76b',
-      						  userId: this.userId,
-      						  message: this.userText,
-      						  session_name: _uuid+"-qgt",
-										uid:_uuid,
-      						  file_ids: [],
-      						};
-									this.ajax
-        					// .post("https://claude3.cocorobo.cn/chat", params)
-        					// .post("https://gpt4.cocorobo.cn/chat", params)
-									.post("https://gpt4.cocorobo.cn/ai_agent_park_chat_new", params)
-        					.then(res => {
-        					  if (res.data.FunctionResponse.result == "发送成功") {
-        					  } else {
-        					    // this.$message.warning(res.data.FunctionResponse.result);
-											console.log(res.data.FunctionResponse.result)
-											this.chatLoading = false;
-											this.aiStatus = 0;
-                    	this.showTextIndex = 0;
-                    	this.aiText = "对不起,我无法理解您的问题,请重新提问";
-                    	this.timer = setTimeout(() => {
-                    	  this.showTextIndex = 3;
-                    	  this.aiStatus = 2;
-                    	  this.aiText = "";
-                    	  this.userText = "";
-                    	}, 3000);
-        					  }
-        					})
-        					.catch(e => {
-        					  console.log(e);
-        					  this.chatLoading = false;
-										this.aiStatus = 0;
+                this.userText = "";
+                this.stopRecord();
+                return;
+                // },1000)
+              }
+              this.showTextIndex = 2;
+              this.aiText = "";
+              if (/计时(.+)分钟/.test(this.userText)) {
+                // setTimeout(() => {
+                let _number = this.userText.match(/计时(.+)分钟/)[1];
+                let _time = 0;
+                if (!/^\d+$/.test(_number)) {
+                  _time = this.chineseToNumber(_number) * 60;
+                } else {
+                  _time = parseInt(_numberList[1]) * 60;
+                }
+                this.$emit("startTime", _time);
+                this.aiStatus = 0;
+                this.showTextIndex = 0;
+                this.aiText =
+                  "好的,我已为您计时" +
+                  this.userText.match(/计时(.+)分钟/)[1] +
+                  "分钟。";
+                this.userText = "";
+                this.timer = setTimeout(() => {
+                  this.showTextIndex = 3;
+                  this.aiStatus = 2;
+                  this.aiText = "";
+                  this.userText = "";
+                }, 3000);
+                // }, 2000);
+              } else {
+                this.chatLoading = true;
+                const _uuid = uuidv4();
+                let params = {
+                  assistant_id: "f8e1ebb2-2e0d-11ef-8bf4-12e77c4cb76b",
+                  userId: this.userId,
+                  message: this.userText,
+                  session_name: _uuid + "-qgt",
+                  uid: _uuid,
+                  file_ids: []
+                };
+                this.ajax
+                  // .post("https://claude3.cocorobo.cn/chat", params)
+                  // .post("https://gpt4.cocorobo.cn/chat", params)
+                  .post(
+                    "https://gpt4.cocorobo.cn/ai_agent_park_chat_new",
+                    params
+                  )
+                  .then(res => {
+                    if (res.data.FunctionResponse.result == "发送成功") {
+                      this.userText = "";
+                    } else {
+                      // this.$message.warning(res.data.FunctionResponse.result);
+                      console.log(res.data.FunctionResponse.result);
+                      this.chatLoading = false;
+                      this.aiStatus = 0;
+                      this.showTextIndex = 0;
+                      this.aiText = "对不起,我无法理解您的问题,请重新提问";
+                      this.timer = setTimeout(() => {
+                        this.showTextIndex = 3;
+                        this.aiStatus = 2;
+                        this.aiText = "";
+                        this.userText = "";
+                      }, 3000);
+                    }
+                  })
+                  .catch(e => {
+                    console.log(e);
+                    this.chatLoading = false;
+                    this.aiStatus = 0;
                     this.showTextIndex = 0;
                     this.aiText = "对不起,我无法理解您的问题,请重新提问";
                     this.timer = setTimeout(() => {
@@ -201,16 +209,16 @@ export default {
                       this.aiText = "";
                       this.userText = "";
                     }, 3000);
-        					});
-									// 通过流获取ai对话数据
-									this.getAtAuContent(_uuid)
-                }
-              }, 5000);
-            }
-          } else {
-            console.log("不响应");
+                  });
+                // 通过流获取ai对话数据
+                this.getAtAuContent(_uuid);
+              }
+            }, 5000);
           }
-        };
+        } else {
+          console.log("不响应");
+        }
+      };
       // } catch (error) {
       //   console.log("ai录音报错👇");
       //   console.log(error);
@@ -219,28 +227,28 @@ export default {
       //   }, 1000);
       // }
     },
-		stopRecord(){
-			// this.$parent.changeRecordType(0);
-			// this.$message.success("已关闭语音助手")
-			// return 
-			let iiframe = this.$refs["iiframe"];
-				iiframe.contentWindow.window.document
-					.getElementById("scenarioStopButton")
-					.click();
-				// 录音借宿
-				iiframe.contentWindow.onSessionStopped = (s, e) => {
-					this.isOpen = false;
-					this.$parent.changeRecordType(0);
-					this.$message.success("已关闭语音助手")
-					if(this.talkLoading){
-						this.talkLoading = false;
-						this.$refs.iiframe2.closesynthesizer();
-					}
-					this.userText = "";
-					this.aiText = "";
-				};
-				
-		},
+    stopRecord() {
+      // this.$parent.changeRecordType(0);
+      // this.$message.success("已关闭语音助手")
+      // return
+      let iiframe = this.$refs["iiframe"];
+      iiframe.contentWindow.window.document
+        .getElementById("scenarioStopButton")
+        .click();
+      // 录音借宿
+      iiframe.contentWindow.onSessionStopped = (s, e) => {
+        this.isOpen = false;
+        this.show = false;
+        this.showTextIndex = 3;
+        this.$parent.changeRecordType(0);
+        this.$message.success("已关闭语音助手");
+        if (this.talkLoading) {
+          this.$refs.iiframe2.contentWindow.closesynthesizer();
+        }
+        this.userText = "";
+        this.aiText = "";
+      };
+    },
     chineseToNumber(chinese) {
       const chineseNumbers = {
         零: 0,
@@ -296,13 +304,27 @@ export default {
       result += sectionNum + tempNum;
       return result;
     },
-		getAtAuContent(_uid) {
-      this.source = new EventSource(`https://gpt4.cocorobo.cn/question/${_uid}`); 
-			//http://gpt4.cocorobo.cn:8011/question/   https://gpt4.cocorobo.cn/question/
+    removeMarkdown(text) {
+      return text
+        .replace(/[#*_~`>+\-]/g, "") // 移除 #、*、_、~、`、>、+、- 符号
+        .replace(/!\[.*?\]\(.*?\)/g, "") // 移除图片
+        .replace(/\[.*?\]\(.*?\)/g, "") // 移除链接
+        .replace(/```[\s\S]*?```/g, "") // 移除代码块(不使用 s 标志)
+        .replace(/`[^`]*`/g, "") // 移除行内代码
+        .replace(/\d+\./g, "") // 移除有序列表
+        .replace(/^\s*[-*+]\s+/gm, "") // 移除无序列表
+        .replace(/\s+/g, " ") // 将多个空白字符替换为一个空格
+        .trim(); // 去除字符串两端的空白字符
+    },
+    getAtAuContent(_uid) {
+      this.source = new EventSource(
+        `https://gpt4.cocorobo.cn/question/${_uid}`
+      );
+      //http://gpt4.cocorobo.cn:8011/question/   https://gpt4.cocorobo.cn/question/
       let _allText = "";
       let _mdText = "";
-			let _talkText = "";
-			let _talkIndex = 0;
+      let _talkText = "";
+      // let _talkIndex = 0;
       // const md = new MarkdownIt();
       this.source.onmessage = _e => {
         let _eData = JSON.parse(_e.data);
@@ -315,79 +337,87 @@ export default {
             }
           }
           _mdText = _mdText.replace("_", "");
-					this.aiText = _mdText;
-					if(_talkText!=''){
-						this.talkTextList.push(_talkText)
-						if(!this.talkLoading)this.talkText();
-					}
-					this.chatLoading = false;
+          this.aiText = _mdText;
+          if (_talkText != "") {
+            let _resultText = this.removeMarkdown(_talkText);
+            this.talkTextList.push(_resultText);
+            _talkText = "";
+            if (!this.talkLoading) this.talkText();
+          }
+          this.chatLoading = false;
           this.source.close();
         } else {
-					_talkIndex+=1;
+          // _talkIndex+=1;
           let _text = _eData.content.replace("'", "").replace("'", "");
           if (_allText == "") {
             _allText = _text.replace(/^\n+/, ""); //去掉回复消息中偶尔开头就存在的连续换行符
-						_talkText+=_text.replace(/^\n+/, "");
+            _talkText += _text.replace(/^\n+/, "");
           } else {
             _allText += _text;
-						_talkText+=_text;
+            _talkText += _text;
           }
+          `~`;
           _mdText = _allText + "_";
           _mdText = _mdText.replace(/\\n/g, "\n");
           _mdText = _mdText.replace(/\\/g, "");
           if (_allText.split("```").length % 2 == 0) _mdText += "\n```\n";
-					this.aiText = _mdText;
-					this.showTextIndex = 0;
-					if(_talkIndex==10){
-						_talkIndex = 0;
-						this.talkTextList.push(_talkText)
-						_talkText = "";
-						if(!this.talkLoading)this.talkText();
-					}
-					
+          this.aiText = _mdText;
+          this.showTextIndex = 0;
+          if (/[,。:]/.test(_talkText)) {
+            let _resultText = this.removeMarkdown(_talkText);
+            this.talkTextList.push(_resultText);
+            _talkText = "";
+            if (!this.talkLoading) this.talkText();
+          }
+          // if(_talkIndex==10){
+          // 	_talkIndex = 0;
+          // 	this.talkTextList.push(_talkText)
+          // 	_talkText = "";
+          // 	if(!this.talkLoading)this.talkText();
+          // }
         }
       };
     },
-		talkText(){
-			let _text = this.talkTextList.shift();
-			let _talkTextIiframe2 = this.$refs.iiframe2;
-			
-			if(_text){
-				this.talkLoading = true;
-				 if (this.timer) {
+    talkText() {
+      let _text = this.talkTextList.shift();
+      let _talkTextIiframe2 = this.$refs.iiframe2;
+
+      if (_text) {
+        this.talkLoading = true;
+        if (this.timer) {
           clearTimeout(this.timer);
           this.timer = null;
         }
-				console.log(`👉转语音:${_text}`)
-				// setTimeout(()=>{
-				// 	this.talkText();
-				// },2000)
-				_talkTextIiframe2.contentWindow.texttospeech(_text,this.talkText);
-			}else{
-				console.log("👉转语音结束👈")
-				_talkTextIiframe2.contentWindow.closesynthesizer()
-				this.talkLoading = false;
-				// this.timer = setTimeout(() => {
+        // console.log(`👉转语音:${_text}`);
+        // setTimeout(()=>{
+        // 	this.talkText();
+        // },2000)
+        _talkTextIiframe2.contentWindow.texttospeech(_text, this.talkText);
+      } else {
+        console.log("👉转语音结束👈");
+        _talkTextIiframe2.contentWindow.closesynthesizer();
+        this.talkLoading = false;
+        // this.timer = setTimeout(() => {
         //   this.showTextIndex = 3;
         //   this.aiStatus = 2;
         //   this.aiText = "";
         //   this.userText = "";
-				// 	this.time = null;
+        // 	this.time = null;
         // }, 5000);
-			}
-		},
+      }
+    }
   },
   mounted() {
-		// // this.recordStart()
-		// setTimeout(()=>{
-		// 	this.recordStart("可可同学。")
-		// 	setTimeout(()=>{
-		// 		this.recordStart("世界上最大的山是什么山。")
-		// 		setTimeout(()=>{
-		// 			this.recordStart("位于哪里。")
-		// 		},2000)
-		// 	},2000)
-		// },2000)
+    // // this.recordStart()
+    // setTimeout(()=>{
+    // 	this.recordStart("可可同学。")
+    // 	setTimeout(()=>{
+    // 		this.recordStart("世界上最大的火山是什么。")
+    // 		setTimeout(()=>{
+    // 			this.recordStart("位于哪里。他温度怎么样。")
+    // 		},2000)
+    // 	},2000)
+    // },2000)
   }
 };
 </script>

+ 0 - 1
src/components/classRoomHelper/component/searchArea.vue

@@ -843,7 +843,6 @@ export default {
       this.scrollBottom();
 			console.log(this.sendType)
       if (_text.indexOf("视频") != -1 || this.sendType == 2) {
-				this.$message.info('猪')
         _msg = `
 NOTICE
 Language: Please use the same language as the user requirement, if the user speaks Chinese, the specific text of your answer should also be in Chinese.