|
@@ -51,6 +51,7 @@
|
|
speechText: '', //语音识别的结果-文字
|
|
speechText: '', //语音识别的结果-文字
|
|
recording: false, //语音识别是否开始
|
|
recording: false, //语音识别是否开始
|
|
touching:false,
|
|
touching:false,
|
|
|
|
+ audioAuth:false, //音频授权结果
|
|
messageList:[
|
|
messageList:[
|
|
{
|
|
{
|
|
author: 'AI',
|
|
author: 'AI',
|
|
@@ -76,10 +77,46 @@
|
|
this.id = this.$route.query.id2 ? this.$route.query.id2 : (this.queryObj && this.queryObj.id2 ? this
|
|
this.id = this.$route.query.id2 ? this.$route.query.id2 : (this.queryObj && this.queryObj.id2 ? this
|
|
.queryObj.id2 : '110');
|
|
.queryObj.id2 : '110');
|
|
this.findHouseTypeSpaceList();
|
|
this.findHouseTypeSpaceList();
|
|
|
|
+ this.getUserMedia();
|
|
// this.queryTestcaseSingle();
|
|
// this.queryTestcaseSingle();
|
|
document.title = this.navbar.title;
|
|
document.title = this.navbar.title;
|
|
},
|
|
},
|
|
methods: {
|
|
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() {
|
|
backFun() {
|
|
uni.navigateBack({
|
|
uni.navigateBack({
|
|
url: 'pages/groupIndex2/groupIndex2'
|
|
url: 'pages/groupIndex2/groupIndex2'
|
|
@@ -412,6 +449,12 @@
|
|
},
|
|
},
|
|
//语音识别
|
|
//语音识别
|
|
speechRecognizer() {
|
|
speechRecognizer() {
|
|
|
|
+ if(this.audioAuth==false){
|
|
|
|
+ Toast({
|
|
|
|
+ message: '已拒绝麦克风授权,无法使用录音功能',
|
|
|
|
+ });
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
this.touching = true;//用户开始触摸语音按钮
|
|
this.touching = true;//用户开始触摸语音按钮
|
|
console.warn('speechRecognizer',this.recording);
|
|
console.warn('speechRecognizer',this.recording);
|
|
// if (!webAudioSpeechRecognizer) {
|
|
// if (!webAudioSpeechRecognizer) {
|