zjs_project il y a 10 mois
Parent
commit
8ea1124b73

+ 4 - 1
src/components/newQCCom/viewlayout/viewlayout.scss

@@ -47,6 +47,7 @@
 	width: 100%;
 	box-sizing: border-box;
 	margin-top:26px;
+    user-select: none;
 }
 .btn{
 	height: 100px;
@@ -92,7 +93,6 @@
     background: linear-gradient(130.79deg, rgba(245, 201, 82, 1) 0%, rgba(253, 148, 41, 1) 100%);
     border-radius: 50%;
     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;
@@ -100,6 +100,7 @@
     .icon{
         width: 31.5px;
         height: 44px;
+        user-select: none;
         // margin-right: 10px;
     }
 }
@@ -116,6 +117,7 @@
     // backdrop-filter:blur(40px);
     background-color: #fff;
     border-radius: 40px 40px 0 0;
+    user-select: none;
     .voice-title{
     	font-size: 36px;
     	color: #242424;
@@ -129,5 +131,6 @@
     .voice-gif{
     	width: 100%;
     	margin-top:-20px;
+        user-select: none;
     }
 }

+ 51 - 43
src/components/newQCCom/viewlayout/viewlayout.vue

@@ -4,8 +4,9 @@
 <script>
     const util = require('@/utils/util.js').default;
     const config = require('@/services/urlConfig.js');
+    let webAudioSpeechRecognizer;
     import {
-        Toast
+        Toast,Indicator
     } from 'mint-ui';
     // import Bus from '@/common/bus';
     // import commonMethod from '@/common/commonMethod.js';
@@ -44,10 +45,10 @@
                 spaceList: [],
                 showX: false,
 
-                webAudioSpeechRecognizer: null, //语音识别的对象
+                // webAudioSpeechRecognizer: null, //语音识别的对象
                 speechText: '', //语音识别的结果-文字
                 recording: false, //语音识别是否开始
-                isCanStop:false,    //socket是否已经链接好了
+                touching:false,
             }
         },
         props: {
@@ -254,12 +255,21 @@
                 return "";
             },
             async textChange(text) {
-                // if (this.overChange) {
-                //     Toast({
-                //         message: '请慢一点',
-                //     });
-                //     return false;
-                // }
+                if (!text) {
+                    Toast({
+                        message: '未识别到语音',
+                    });
+                    return false;
+                }
+                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
                 });
@@ -344,9 +354,9 @@
             },
             //语音识别
             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, // 鉴权函数,若直接使用默认鉴权函数。可不传此参数
                         // 用户参数
@@ -367,66 +377,64 @@
                         // 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);
                     };
                     // 一句话开始 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);
+                        // const currentText = `${resultText}${res.result.voice_text_str}`;
                     };
                     // 一句话结束
                     webAudioSpeechRecognizer.OnSentenceEnd = (res) => {
                         console.log('一句话结束',this.recording, res);
-                        resultText = res.result.voice_text_str;
-                        let param = {
-                            type: 'CLK', //埋点类型
-                            clkId: 'clk_2cmina_23080407', //点击ID
-                            clkName: 'voice_clk', //点击前往的页面名称
-                            clkParams: {
-                                locusName: "语音调整",
-                                text: resultText
-                            }
-                        };
-                        util.trackRequest(param);
-                        let text = resultText.replaceAll(/,|。/ig, "");
+                        // resultText = res.result.voice_text_str;
+                        let text = res.result.voice_text_str.replaceAll(/,|。/ig, "");
                         this.textChange(text);
-                        this.speechText += resultText;
+                        // this.speechText += 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 = webAudioSpeechRecognizer;
+                // }
+                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();
             },
         }
     }

+ 1 - 1
src/router/index.js

@@ -211,7 +211,7 @@ const router = new Router({
         	name: 'webgl_rxdz_recognizer_houseList',
         	component: webgl_rxdz_recognizer_houseList,
         	meta:{
-        		keepAlive:false
+        		keepAlive:true
         	}
         },
     ],