zjs_project 10 months ago
parent
commit
227b3c1f3d

+ 30 - 30
src/pages/webgl_rxdz_recognizer_houseList/webgl_rxdz_recognizer_houseList.html

@@ -1,12 +1,30 @@
 <div class="container" @touchend="streamRecordEnd">
 	<!-- <div class="back"><i class="iconfont icon-fanhui" @click="backFun"></i></div> -->
-	<div class="title rows justify-center">
+	<!-- <div class="title rows justify-center">
 		- 选择您喜欢的空间 -
-	</div>
+	</div> -->
 	<!-- 户型选择区域 -->
 	<div class="scroll-class">
-		<div class="main grid-view1">
-			<div @click="changeHouse(index)" class="item columns" :class="{'active': selectIndex == index}" 
+		<div class="main">
+            <div class="message-box columns" :style="{'align-items':item.type==1?'flex-end':'flex-start'}" v-for='(item,index) in messageList' :key="index" >
+                <template v-if="item.type==1">
+                    <div class="right rows">
+                        <div>{{item.text}}</div>
+                    </div>
+                </template>
+                <template v-else>
+                    <div class="author-name">Elab</div>
+                    <div class="columns left" v-if="item.id" @click="enterAction(index)">
+                        <img class="item-img" :src="item.coverImage" />
+                        <div class="item-text rows justify-center">{{item.houseType}}·{{item.houseArea}}㎡</div>
+                        <div class="item-note rows justify-center">{{item.note}}</div>
+                    </div>
+                    <div class="columns left" v-else>
+                        <div>{{item.text}}</div>
+                    </div>
+                </template>
+            </div>
+			<!-- <div @click="changeHouse(index)" class="item columns" :class="{'active': selectIndex == index}" 
 				v-for="(house,index) in houseList" :key="index" >
 				<img class="item-img" :src="house.coverImage" />
 				<div class="tab-info rows justify-center">
@@ -14,34 +32,16 @@
 				</div>
 				<div class="item-text rows justify-center">{{house.houseType}}·{{house.houseArea}}㎡</div>
 				<div class="item-note rows justify-center">{{house.note}}</div>
-			</div>
+			</div> -->
 		</div>
 	</div>
-	<!-- 题目数据 -->
-	<div class="topic-view">
-		<!-- 题目列表 -->
-		<!-- <div class="screenList">
-			<div class="items" v-for="(item, idx) in tabData" :key="idx">
-				<div class="item_title">
-					{{item.fatherContent}}:
-				</div>
-				<div class="item_list">
-					<div :class="['item', idx1 == item.checkedIndex ? 'item_sel': '']" 
-						v-for="(item1, idx1) in item.options" :key="idx1" 
-						@click.stop="changeOption(idx, idx1)">
-						{{item1.content}}
-					</div>
-				</div>
-			</div>
-		</div> -->
-		<!-- 按钮 -->
-		<div class="btn-list rows rows-between">
-			<div class="btn voice rows justify-center" @touchstart="speechRecognizer" >
-				<img class="icon" src="https://dm.static.elab-plus.com/miniProgram/iconfont/source.png" mode="widthFix"/>
-				语音选择/按住说话
-			</div>
-			<div class="btn diy rows justify-center" @click="enterAction">DIY空间</div>
+	<!-- 按钮 -->
+	<div class="btn-list rows rows-between">
+		<div class="btn voice rows justify-center" @touchstart="speechRecognizer" >
+			<img class="icon" src="https://dm.static.elab-plus.com/miniProgram/iconfont/source.png" mode="widthFix"/>
+			按住 说话
 		</div>
+		<!-- <div class="btn diy rows justify-center" @click="enterAction">DIY空间</div> -->
 	</div>
     <!-- 语音视图 -->
     <div class="voice-view" v-show="recording">
@@ -53,5 +53,5 @@
     	</div>
     </div>
     <!-- 语音识别的结果 -->
-    <div class="result-view rows justify-center">{{speechText}}</div>
+    <!-- <div class="result-view rows justify-center">{{speechText}}</div> -->
 </div>

+ 93 - 79
src/pages/webgl_rxdz_recognizer_houseList/webgl_rxdz_recognizer_houseList.scss

@@ -16,14 +16,69 @@
 }
 .scroll-class{
 	position: relative;
-	height: calc(100% - 210px);
-	padding-top: 170px;
+	height: 100vh;
+	padding-top: 30px;
+    padding-bottom:60px;
     box-sizing: border-box;
+    background-color: #EFF0F4;
+    border-radius: 50px;
 	.main{
 		// max-height: 400px;
 		max-height: 100%;
 		overflow-y: auto;
-		padding: 0px 20px;
+		padding: 0px 30px;
+        border-radius: 50px;
+        .message-box{
+            position: relative;
+            box-sizing: border-box;
+            width: 100%;
+            font-family: "Verdana";
+            font-weight: 400;
+            font-size: 28px;
+            margin-bottom: 30px;
+        }
+        .message-box:last-child{
+            margin-bottom: 100px;
+        }
+        .right{
+            width: fit-content;
+            border-radius: 30px 30px 0 30px;
+            background-color: #346BFC;
+            color: #fff;
+            padding: 20px;
+        }
+        // 系统回答
+        .left{
+            border-radius: 0px 30px 30px 30px;
+            background-color: #FFFFFF;
+            color: #000;
+            align-items: flex-start;
+            padding: 20px;
+            .item-img{
+            	width: 340px;
+            	height: 260px;
+            	object-fit: cover;
+            	margin-bottom: 8px;
+            }
+            .item-text{
+            	font-family: "DIN Alternate Bold";
+            	font-weight: 700;
+            	font-size: 28px;
+            	color: #0f0f0f;
+            	margin-bottom: 4px;
+            }
+            .item-note{
+            	font-family: "Verdana";
+            	font-weight: 400;
+            	font-size: 28px;
+            	color: #e0862e;
+            }
+        }
+        .author-name{
+            margin-bottom: 10px;
+            color: #5E5F63;
+        }
+        
 		.item{
 			position: relative;
 			font-size: 0px;
@@ -53,88 +108,47 @@
 			&.active .tab-info{
 				opacity: 1;
 			}
-			.item-img{
-				width: 340px;
-				height: 260px;
-				object-fit: contain;
-				margin-bottom: 8px;
-			}
-			.item-text{
-				font-family: "DIN Alternate Bold";
-				font-weight: 700;
-				font-size: 28px;
-				color: #0f0f0f;
-				margin-bottom: 4px;
-			}
-			.item-note{
-				font-family: "Verdana";
-				font-weight: 400;
-				font-size: 28px;
-				color: #e0862e;
-			}
+			
 		}
 			
 	}
 }
-.topic-view{
-	position: relative;
-	width: 100vw;
-	height: 210px;
-	border-radius: 40px 40px 0 0;
-	background: #fff;
-	padding: 50px 30px;
-	box-sizing: border-box;
-	
-    .btn-list{
-    	position: relative;
-    	width: 100%;
-    	box-sizing: border-box;
-        .btn{
-        	height: 100px;
-        	border-radius: 50px;
-        	// backdrop-filter:blur(40px);
-        	font-family: "Verdana Bold";
-        	font-weight: 700;
-        	font-size: 32px;
-        	color: #272727;
-        	box-sizing: border-box;
-        }
-        // .btn{
-        // 	position: absolute;
-        // 	bottom: 68px;
-        // 	left: 140px;
-        // 	width: 470px;
-        // 	height: 92px;
-        // 	border-radius: 46px;
-        // 	/* Note: currently only Safari supports backdrop-filter */
-        // 	backdrop-filter:blur(40px);
-        // 	background: linear-gradient(130.79deg, rgba(245, 201, 82, 1) 0%, rgba(253, 148, 41, 1) 100%);
-        // 	font-family: "Verdana Bold";
-        // 	font-weight: 700;
-        // 	font-size: 30px;
-        // 	color: #fff;
-        // }
-        .diy{
-            width: 190px;
-            background-color: rgba(23, 23, 23, 0.1);
-        }
-        .voice{
-            width: 460px;
-            background: linear-gradient(130.79deg, rgba(245, 201, 82, 1) 0%, rgba(253, 148, 41, 1) 100%);
-            user-select: none;
-            context-menu: none;
-            // background-image: url('https://dm.static.elab-plus.com/miniProgram/iconfont/play.gif');
-            // background-repeat: no-repeat;
-            // background-size: cover;
-            color: #fff;
-            .icon{
-            	width: 31.5px;
-            	height: 44px;
-                margin-right: 10px;
-            }
+.btn-list{
+    position: fixed;
+    width: 100%;
+    box-sizing: border-box;
+    border-radius: 50px;
+    padding: 0px 30px;
+    bottom: 30px;
+    .btn{
+        height: 100px;
+        border-radius: 40px;
+        // backdrop-filter:blur(40px);
+        font-family: "Verdana Bold";
+        font-weight: 700;
+        font-size: 32px;
+        color: #272727;
+        box-sizing: border-box;
+    }
+    .diy{
+        width: 190px;
+        background-color: rgba(23, 23, 23, 0.1);
+    }
+    .voice{
+        width: 100%;
+        background: linear-gradient(130.79deg, rgba(245, 201, 82, 1) 0%, rgba(253, 148, 41, 1) 100%);
+        user-select: none;
+        context-menu: none;
+        // background-image: url('https://dm.static.elab-plus.com/miniProgram/iconfont/play.gif');
+        // background-repeat: no-repeat;
+        // background-size: cover;
+        color: #fff;
+        .icon{
+            width: 31.5px;
+            height: 44px;
+            margin-right: 10px;
         }
     }
-    
 }
 .voice-view{
 	position: absolute;

+ 95 - 66
src/pages/webgl_rxdz_recognizer_houseList/webgl_rxdz_recognizer_houseList.vue

@@ -4,16 +4,15 @@
 <script>
     const util = require('@/utils/util.js').default;
     const config = require('@/services/urlConfig.js');
+    let webAudioSpeechRecognizer;
     import router from "@/router";
     import {
         setStorage,
         getStorage,
     } from '@/utils/localStorage';
     import {
-        Toast
+        Toast,Indicator
     } from 'mint-ui';
-    // import houseList from "../../components/houseList/houseList.vue";
-    // import houseList2 from "../../components/houseList/houseList2.vue";
     import commonPageMethod from '@/mixins/commonPageMethod.js';
     export default {
         mixins: [commonPageMethod],
@@ -49,10 +48,10 @@
                 selectIndex: -1, //用户选择的户型序号
                 queryObj: null, //页面参数
 
-                webAudioSpeechRecognizer: null, //语音识别的对象
                 speechText: '', //语音识别的结果-文字
                 recording: false, //语音识别是否开始
-                isCanStop:false,    //socket是否已经链接好了
+                touching:false,
+                messageList:[], //消息列表
             }
         },
         // components: {
@@ -136,25 +135,32 @@
                 };
                 util.trackRequest(param);
             },
+            //选中这个户型
             changeHouse(index) {
-                this.curHouseObj = this.houseList[index];
-                this.selectIndex = index;
-                console.log("changeHouse: ", this.curHouseObj, this.selectIndex);
+                let curHouseObj = this.houseList[index];
+                // this.selectIndex = index;
+                console.log("changeHouse: ", curHouseObj);
                 let param = {
                     type: 'CLK', //埋点类型
                     clkId: 'clk_2cmina_24012401', //点击ID
                     clkName: 'option_clk', //点击前往的页面名称
                     clkParams: {
-                        houseType: this.curHouseObj.houseType,
-                        name: this.curHouseObj.name,
-                        note: this.curHouseObj.note,
-                        area: this.curHouseObj.houseArea,
-                        id: this.curHouseObj.id,
-                        locusValue: this.curHouseObj.houseType,
+                        houseType: curHouseObj.houseType,
+                        name: curHouseObj.name,
+                        note: curHouseObj.note,
+                        area: curHouseObj.houseArea,
+                        id: curHouseObj.id,
+                        locusValue: curHouseObj.houseType,
                         locusName: "空间选择",
                     }
                 };
                 util.trackRequest(param);
+                let message = {
+                    author: 'AI',
+                    type:   2,
+                    ...curHouseObj,
+                }
+                this.messageList.push(message);
             },
             //查询题目数据
             // async queryTestcaseSingle() {
@@ -212,7 +218,9 @@
                 }
             },
             //进入下一步
-            enterAction() {
+            enterAction(index) {
+                let message = this.messageList[index];
+                this.curHouseObj = this.houseList.find(it=>it.id==message.id);
                 if (!this.curHouseObj) {
                     Toast({
                         message: '请选择喜欢的空间',
@@ -277,10 +285,25 @@
                 text = text.replaceAll(/ |,|。/ig, "");
                 if (!text) {
                     Toast({
-                        message: '请再说一次',
+                        message: '未识别到语音',
                     });
                     return false;
                 }
+                let message = {
+                    author: this.userId,
+                    type:   1,
+                    text:   text,
+                }
+                this.messageList.push(message);
+                let param = {
+                    type: 'CLK', //埋点类型
+                    clkId: 'clk_2cmina_24082901', //点击ID
+                    clkName: 'user_talk_clk', //点击前往的页面名称
+                    clkParams: {
+                        locusValue: text,
+                    }
+                };
+                util.trackRequest(param);
                 // let res = await requestConfig("chineseToPinyin", {
                 //     chinese: text
                 // });
@@ -292,9 +315,15 @@
                 if(houseIndex){
                     houseIndex = this.houseList.length - houseIndex;
                     if(houseIndex < 0){//越界了
-                        Toast({
-                            message: '数据不合法,请再说一次',
-                        });
+                        // Toast({
+                        //     message: '数据不合法,请再说一次',
+                        // });
+                        let message = {
+                            author: 'AI',
+                            type:   2,
+                            text:   "没有匹配到,请再说一次~",
+                        }
+                        this.messageList.push(message);
                     }else{
                         this.changeHouse(houseIndex);
                     }
@@ -321,7 +350,7 @@
                         }
                     })
                     console.warn("***mate-result-list***",list);
-                    //寻找5个字符串以上的
+                    //寻找2个字符串以上的
                     let tmpList = list.filter(it => {
                         return it.comStr.length > 2;
                     })
@@ -333,33 +362,34 @@
                 }
                 //没有找到语音操作对象
                 if (houseIndex==null || houseIndex < 0) {
-                    Toast({
-                        message: '请再说一次',
-                    });
+                    let message = {
+                        author: 'AI',
+                        type:   2,
+                        text:   "没有匹配到,请再说一次",
+                    }
+                    this.messageList.push(message);
                     return false;
                 }
                 if(houseIndex > this.houseList.length){
-                    Toast({
-                        message: '数据不合法,请再说一次',
-                    });
+                    // Toast({
+                    //     message: '数据不合法,请再说一次',
+                    // });
+                    let message = {
+                        author: 'AI',
+                        type:   2,
+                        text:   "没有匹配到,请再说一次!",
+                    }
+                    this.messageList.push(message);
                    return false; 
                 }
                 this.changeHouse(houseIndex);
                 console.log("textChange:", houseIndex);
-                // this.$emit("curSpaceChange", data); //通知父组件-当前已经选中了户型大类
-            },
-            //用户语音为空
-            showRecordEmptyTip() {
-                this.recording = false; //录音结束
-                Toast({
-                    message: '告诉我您的想法',
-                });
             },
             //语音识别
             speechRecognizer() {
-                this.recording = true;
-                console.warn('speechRecognizer', this.webAudioSpeechRecognizer,this.recording);
-                if (!this.webAudioSpeechRecognizer) {
+                this.touching = true;//用户开始触摸语音按钮
+                console.warn('speechRecognizer',this.recording);
+                // if (!webAudioSpeechRecognizer) {
                     const params = {
                         // signCallback: signCallback, // 鉴权函数,若直接使用默认鉴权函数。可不传此参数
                         // 用户参数
@@ -380,62 +410,61 @@
                         // convert_num_mode : 1,
                         // word_info: 2
                     }
-                    const webAudioSpeechRecognizer = new WebAudioSpeechRecognizer(params);
-                    let resultText = '';
+                    webAudioSpeechRecognizer = new WebAudioSpeechRecognizer(params);
+                    Indicator.open({
+                        text: '正在链接...',
+                        spinnerType: 'fading-circle'
+                    });
                     // 开始识别
                     webAudioSpeechRecognizer.OnRecognitionStart = (res) => {
-                        console.log('开始识别',this.recording, res);
+                        console.log('开始识别',res);
                     };
                     // 一句话开始 socket链接成功了
                     webAudioSpeechRecognizer.OnSentenceBegin = (res) => {
-                        console.log('一句话开始',this.recording, res);
-                        this.speechText = "";
-                        this.isCanStop = true;
+                        console.log('一句话开始',this.touching,res);
+                        if(this.touching==false){//用户没有触摸
+                            return false;
+                        }else{//正常开始识别语句了
+                            this.speechText = "";
+                            Indicator.close();
+                            this.recording = true;//显示正在录音视图
+                        }
+                        
                     };
                     // 识别变化时
                     webAudioSpeechRecognizer.OnRecognitionResultChange = (res) => {
-                        console.log('识别变化时',this.recording, res);
-                        const currentText = `${resultText}${res.result.voice_text_str}`;
-                        this.speechText = currentText;
+                        console.log('识别变化时', res);
                     };
                     // 一句话结束
                     webAudioSpeechRecognizer.OnSentenceEnd = (res) => {
                         console.log('一句话结束',this.recording, res);
-                        resultText += res.result.voice_text_str;
+                        let resultText = res.result.voice_text_str;
                         this.speechText = resultText;
-                        let param = {
-                            type: 'CLK', //埋点类型
-                            clkId: 'clk_2cmina_23080407', //点击ID
-                            clkName: 'voice_clk', //点击前往的页面名称
-                            clkParams: {
-                                locusName: "语音调整",
-                                text: resultText
-                            }
-                        };
-                        util.trackRequest(param);
                         this.textChange(resultText);
                     };
                     // 识别结束
                     webAudioSpeechRecognizer.OnRecognitionComplete = (res) => {
                         console.log('识别结束', res);
+                        this.recording = false; //录音结束
                     };
                     // 识别错误
                     webAudioSpeechRecognizer.OnError = (res) => {
                         console.log('识别失败', res)
+                        this.recording = false; //录音结束
+                        Indicator.close();
                     };
-                    this.webAudioSpeechRecognizer = webAudioSpeechRecognizer;
-                }
-                this.webAudioSpeechRecognizer.start();
+                // }
+                webAudioSpeechRecognizer.start();
             },
             //结束识别
             streamRecordEnd() {
-                this.recording = false; //录音结束
-                console.log('主动结束识别', this.recording,this.isCanStop)
-                if (this.isCanStop) {//链接成功才能关闭
-                    this.webAudioSpeechRecognizer.stop();//关闭
-                    this.isCanStop = false; //已经关闭了,不能在此打开
-                    this.webAudioSpeechRecognizer = null;
+                this.touching = false;//用户没有触摸了
+                console.log('主动结束识别', this.recording)
+                if(webAudioSpeechRecognizer){
+                    webAudioSpeechRecognizer.stop();//关闭
                 }
+                // webAudioSpeechRecognizer = null;
+                Indicator.close();
             },
         },
     }