zjs_project 10 ヶ月 前
コミット
b4ef40b002

+ 1 - 0
src/components/newQCCom/viewlayout/viewlayout.html

@@ -27,6 +27,7 @@
 			</div>
             <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 class="overlay" @contextmenu.prevent></div>
             	<!-- 语音调整 -->
             </div>
 			<div class="btn AiBtn rows justify-center up1" @click="goRoam">

+ 10 - 0
src/components/newQCCom/viewlayout/viewlayout.scss

@@ -89,6 +89,7 @@
 	box-shadow: 0 6px 20px #f2980233;
 }
 .voice{
+    position: relative;
     width: 100px;
     background: linear-gradient(130.79deg, rgba(245, 201, 82, 1) 0%, rgba(253, 148, 41, 1) 100%);
     border-radius: 50%;
@@ -101,8 +102,17 @@
         width: 31.5px;
         height: 44px;
         user-select: none;
+        -webkit-touch-callout:none;
         // margin-right: 10px;
     }
+    .overlay {  
+        position: absolute;  
+        top: 0;  
+        left: 0;  
+        width: 100%;  
+        height: 100%;  
+        background: transparent; /* 透明覆盖 */  
+    } 
 }
 .voice-view{
 	position: fixed;

+ 1 - 0
src/pages/webgl_rxdz_recognizer_houseList/webgl_rxdz_recognizer_houseList.html

@@ -41,6 +41,7 @@
 		<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 class="overlay" @contextmenu.prevent></div>
 		</div>
 		<!-- <div class="btn diy rows justify-center" @click="enterAction">DIY空间</div> -->
 	</div>

+ 9 - 0
src/pages/webgl_rxdz_recognizer_houseList/webgl_rxdz_recognizer_houseList.scss

@@ -135,6 +135,7 @@
         background-color: rgba(23, 23, 23, 0.1);
     }
     .voice{
+        position: relative;
         width: 100%;
         background: linear-gradient(130.79deg, rgba(245, 201, 82, 1) 0%, rgba(253, 148, 41, 1) 100%);
         user-select: none;
@@ -148,6 +149,14 @@
             height: 44px;
             margin-right: 10px;
         }
+        .overlay {
+            position: absolute;  
+            top: 0;  
+            left: 0;  
+            width: 100%;  
+            height: 100%;  
+            background: transparent; /* 透明覆盖 */  
+        } 
     }
 }
 .voice-view{

+ 43 - 0
src/pages/webgl_rxdz_recognizer_houseList/webgl_rxdz_recognizer_houseList.vue

@@ -51,6 +51,7 @@
                 speechText: '', //语音识别的结果-文字
                 recording: false, //语音识别是否开始
                 touching:false,
+                audioAuth:false,    //音频授权结果
                 messageList:[
                     {
                         author: 'AI',
@@ -76,10 +77,46 @@
             this.id = this.$route.query.id2 ? this.$route.query.id2 : (this.queryObj && this.queryObj.id2 ? this
                 .queryObj.id2 : '110');
             this.findHouseTypeSpaceList();
+            this.getUserMedia();
             // this.queryTestcaseSingle();
             document.title = this.navbar.title;
         },
         methods: {
+            getUserMedia(){
+                let self = this;
+                if (navigator.mediaDevices.getUserMedia) {
+                    //最新的标准API
+                    navigator.mediaDevices.getUserMedia({
+                        'audio':true,
+                        'video':false//调用前置摄像头,后置摄像头使用video: { facingMode: { exact: "environment" } }
+                    })
+                    .then(success)
+                    .catch(error)
+                } else if (navigator.webkitGetUserMedia) {
+                    //webkit核心浏览器
+                    navigator.webkitGetUserMedia(constraints, success, error)
+                } else if (navigator.mozGetUserMedia) {
+                    //firfox浏览器
+                    navigator.mozGetUserMedia(constraints, success, error);
+                } else if (navigator.getUserMedia) {
+                    //旧版API
+                    navigator.getUserMedia(constraints, success, error);
+                }
+                function success(stream) {
+                    //兼容webkit核心浏览器
+                    let CompatibleURL = window.URL || window.webkitURL;
+                    //将视频流设置为video元素的源
+                    console.log(stream);
+                    self.audioAuth = true;
+                }
+                function error(error) {
+                    console.log(`访问用户媒体设备失败${error.name}, ${error.message}`);
+                    self.audioAuth = false;
+                    Toast({
+                        message: '已拒绝麦克风授权,无法使用录音功能',
+                    });
+                }
+            },
             backFun() {
                 uni.navigateBack({
                     url: 'pages/groupIndex2/groupIndex2'
@@ -412,6 +449,12 @@
             },
             //语音识别
             speechRecognizer() {
+                if(this.audioAuth==false){
+                    Toast({
+                        message: '已拒绝麦克风授权,无法使用录音功能',
+                    });
+                    return false;
+                }
                 this.touching = true;//用户开始触摸语音按钮
                 console.warn('speechRecognizer',this.recording);
                 // if (!webAudioSpeechRecognizer) {