diff --git a/frontend/.hbuilderx/launch.json b/frontend/.hbuilderx/launch.json new file mode 100644 index 0000000000000000000000000000000000000000..81f13f4f4025c3f1d4a881de5addd979dff6ae15 --- /dev/null +++ b/frontend/.hbuilderx/launch.json @@ -0,0 +1,16 @@ +{ // launch.json 配置了启动调试时相关设置,configurations下节点名称可为 app-plus/h5/mp-weixin/mp-baidu/mp-alipay/mp-qq/mp-toutiao/mp-360/ + // launchtype项可配置值为local或remote, local代表前端连本地云函数,remote代表前端连云端云函数 + "version": "0.0", + "configurations": [{ + "default" : + { + "launchtype" : "local" + }, + "mp-weixin" : + { + "launchtype" : "local" + }, + "type" : "uniCloud" + } + ] +} diff --git a/frontend/manifest.json b/frontend/manifest.json index 974619e30b9ce167f9204adee1f84a4dfe921be8..31724390035ad7ec6845afada7f4b065d9e53a72 100644 --- a/frontend/manifest.json +++ b/frontend/manifest.json @@ -55,10 +55,16 @@ "quickapp" : {}, /* 小程序特有相关 */ "mp-weixin" : { - "appid" : "wx11660ded6d0bc968", + "appid" : "wxc3acc8a3498e3fb7", "setting" : { "urlCheck" : false }, + "plugins":{ + "WechatSI":{ + "version":"0.3.5", + "provider":"wx069ba97219f66d99" + } + }, "usingComponents" : true }, "mp-alipay" : { diff --git a/frontend/pages/search/search.css b/frontend/pages/search/search.css index c10a331f2b5542adc200ccc5439b5c261f7ede83..33c74618d259b3890df4eb7eed2e1250b896265a 100644 --- a/frontend/pages/search/search.css +++ b/frontend/pages/search/search.css @@ -275,12 +275,77 @@ view { /* 录音 start */ +.view-popup{ + padding: 0 30rpx; +} .recording-box { display: flex; flex-direction: row; justify-content: center; + align-items: center; + height:300rpx; +} +.recording-title{ + border-bottom: 1px solid #EBEBEB; +} +.recording-icon{ + width: 170rpx; + height: 170rpx; + border-radius: 50%; + border: 1rpx dashed #1296DB; + display: flex; + justify-content: center; + align-items: center; +} +.recording-icon image{ + width: 80rpx; + height:80rpx; + color: #1296DB; } +/*确认语音输入*/ +.confirm_search{ + width: 540rpx; + background: #FFFFFF; + border-radius: 28rpx; + padding: 0 40rpx; +} +.confirm_title{ + text-align: center; + padding: 58rpx 0; + font-size: 32rpx; + font-family: PingFangSC-Regular, PingFang SC; + font-weight: 400; + color: #333333; + line-height: 42rpx; + border-bottom: 1rpx solid #EBEBEB; +} +.confirm_title text{ + color: #007AFF; + font-weight: 500; + font-size: 36rpx; +} +.comfirm_btns{ + height: 106rpx; + display: flex; + align-items: center; +} +.comfirm_btns view{ + text-align: center; + width: 50%; + font-size: 32rpx; + font-family: PingFangSC-Regular, PingFang SC; + font-weight: 400; + color: #333333; + background-color: color; + border: none; +} +.comfirm_btns view:nth-child(2){ + color: #2173F9; +} +.uni-close-bottom, .uni-close-right { + display: none; +} #canvas { /* border: 2upx solid red; */ position: relative; diff --git a/frontend/pages/search/search.vue b/frontend/pages/search/search.vue index ee1bdb7d6dbda7866250a0fa6fd3817828e164ce..183e65e2b58d9d1a7d5e91f44d938b4e9eef32e6 100644 --- a/frontend/pages/search/search.vue +++ b/frontend/pages/search/search.vue @@ -67,10 +67,6 @@ 当前搜热门搜索已隐藏 - - @@ -78,20 +74,25 @@ 按住 说话 - - - - - + + + - - + + + + 您确定搜索" {{keyword}} "吗? + + 取消 + 确认 + + + + @@ -135,6 +136,9 @@ const innerAudioContext = uni.createInnerAudioContext(); innerAudioContext.autoplay = true; + + const plugin = requirePlugin('WechatSI') + let manager = plugin.getRecordRecognitionManager(); export default { components: { @@ -208,7 +212,7 @@ // image 相关的值 end detailPopupShow: false, detailShowObject: null, - + confirmSearchPopup:false, } }, // onShareAppMessage() { @@ -220,6 +224,7 @@ // }, onLoad(option) { + console.log("options=========",option) let me = this; if (option.type == 1) { me.takePhoto(); @@ -257,74 +262,81 @@ if (me.keywordList == 0 && !me.detailPopupShow) { me.noTitlemodalTap(); } - } } me.init(); - // 录音过程圆圈动画 - - console.log(1); - // 录音结束的事件监听 - recorderManager.onStop(function(res) { - uni.showLoading({ - title: '正在努力识别中...' - }); - console.log('recorder stop' + JSON.stringify(res)); - me.voicePath = res.tempFilePath; - console.log(me.voicePath) - me.popupShow = false; - - // if (me.voicePath) { - // innerAudioContext.src = me.voicePath; - // innerAudioContext.play(); - // console.log("播放了声音") - // } - - // canvas 画图 - // let angle = -0.5; - // let context = uni.createCanvasContext('canvas'); - // me.draw = setTimeout(function() { - // context.beginPath(); - // context.setStrokeStyle("#1296db"); - // context.setLineWidth(3); - // context.arc(0, 0, 0, -0.5 * Math.PI, (angle += 2 / (me.maxTime / me.frame)) * Math.PI, false); - // context.stroke(); - // context.draw(); - // }, 1); - uni.uploadFile({ - url: me.serverUrl + '/upload/record', //仅为示例,非真实的接口地址 - filePath: me.voicePath, - name: 'file', - success: (uploadFileRes) => { - console.log(uploadFileRes.data) - let res = JSON.parse(uploadFileRes.data); - let data = res.data; - let uniOne = data.uni; - me.keyword = data.keyword; - me.isShowKeywordList = true; - me.keywordList = me.drawCorrelativeKeyword(data.results, me.keyword); - if (uniOne) { - me.detailPopupShow = true; - me.detailShowObject = { - keyword: uniOne.garbageName, - garbageType: uniOne.garbageType, - remark: uniOne.remark, - } - } - if (me.keywordList == 0 && !me.detailPopupShow) { - me.noTitlemodalTap(); - } - }, - complete() { - uni.hideLoading(); - } - }); - }) - + me.recordInit(); }, methods: { + recordInit(){ + let that = this ; + manager.onStart = function(res) { + console.log("录音开始=======") + if(res.msg == 'Ok') { + uni.showLoading({ + title: '正在识别语音...', + }) + } + }; + //有新的识别内容返回,则会调用此事件 + manager.onRecognize = (res) => { + console.log("录音正在-----------") + } + // 识别结束事件 + manager.onStop = (res) => { + plugin.translate({ + lfrom: 'en_US', + lto: 'zh_CN', + content: res.result, + success: function(res) { + console.log("录音内容结果=======",res) + uni.hideLoading(); + if(res.retcode == 0) { + //语音识别有时会在末尾添加符号 + if(res.result.charAt(res.result.length - 1) == '。' || res.result.charAt(res.result.length - 1) == '.' || res.result.charAt(res.result.length - 1) == '、') { + res.result = res.result.substr(0, res.result.length - 1); + } + that.keyword = res.result + //打开确认框 + that.popupShow = false; + //打开确认弹窗 + that.confirmSearchPopup = true; + } else { + uni.showToast({ + title:"录音翻译失败", + duration:1500, + icon:"error" + }) + } + }, + fail: function(res) { + uni.hideLoading(); + console.log('网络失败', res); + that.vioceWaitContent='按住说话' + // 当用户说话声音小或者用户没有说话就会报这两个错误 + if(res.retcode == -10001 || res.retcode == -10002) { + uni.showToast({ + title: '没有听清您说什么', + duration: 1500, + icon: 'error' + }) + + } + } + }) + } + // 识别错误事件 + manager.onError = (res) => { + uni.showToast({ + title: '语音识别错误', + duration: 1500, + icon: 'error' + }) + } + + }, tapKeyword(keyword) { this.keyword = keyword; this.doSearch(); @@ -356,93 +368,75 @@ hideUnipPpup() { this.imagesResultShow = false; }, + //展示录音弹窗 readyRecord() { this.popupShow = true; }, start() { - // console.log("startTiming"); - this.recording(); - // this.startTiming = setTimeout(this.recording, 150); + var that = this + this.vioceWaitContent = '录音准备中...'; + // 向用户发起授权请求 + uni.authorize({ + scope: 'scope.record', // 获取录音功能,也就是麦克风权限 + success: (res) => { + // 用户授权使用麦克风权限调用语音搜索事件函数 + console.log("授权=================") + that.pluginInit() + }, + // 用户没有授权使用麦克风权限执行以下代码 + fail(res) { + console.log("未授权=================") + // 显示模态弹窗提示用户没有开启麦克风权限 + uni.showModal({ + content: '检测到您未开启麦克风权限,请保持麦克风权限为开启状态', + confirmText: '去开启', + showCancel: false, + success: (res) => { + console.log(res) + if(res.confirm) { + // 调起客户端小程序设置界面,返回用户设置的操作结果 + uni.openSetting({ + success: (res) => { + console.log(res) + if(res.authSetting['scope.record'] == false) { + that.pluginInit() + } + } + }) + } else { + uni.navigateBack({ + delta: 1 + }) + } + } + }) + } + }) }, - end() { - // console.log("录音 end") - recorderManager.stop(); - clearInterval(this.draw); - clearTimeout(this.startTiming); - clearTimeout(this.timeoutTiming); - clearInterval(this.animaTiming1); - clearInterval(this.animaTiming2); - this.draw = false; - this.startTiming = false; - this.timeoutTiming = false; - this.animaTiming1 = false; - this.animaTiming2 = false; - var animation = uni.createAnimation({ - duration: 500, - timingFunction: 'ease', + //语音插件初始化 + pluginInit(){ + console.log("录音键触摸开始==========") + // 设置录音的参数 + manager.start({ + // duration: 5000, // 时间 + lang: "zh_CN" // 语言 }) - this.animation = animation - animation.scale(1, 1).step() - this.animationData = animation.export() }, - recording() { - let me = this; - // console.log('录音开始'); - recorderManager.start(); - // 画图 - // let angle = -0.5; - // let context = uni.createCanvasContext('canvas'); - // me.draw = setInterval(function() { - // context.beginPath(); - // context.setStrokeStyle("#1296db"); - // context.setLineWidth(3); - // context.arc(75, 75, 50, -0.5 * Math.PI, (angle += 2 / (me.maxTime / me.frame)) * Math.PI, false); - // context.stroke(); - // context.draw(); - // }, me.frame); - me.animaTiming1 = setInterval(function() { - var animation = uni.createAnimation({ - duration: 500, - timingFunction: 'ease', - }) - - me.animation = animation - - animation.scale(1.3, 1.3).step() - - me.animationData = animation.export() - - }, 500) - me.animaTiming2 = setInterval(function() { - var animation = uni.createAnimation({ - duration: 500, - timingFunction: 'ease', - }) - - me.animation = animation - - animation.scale(1, 1).step() - - me.animationData = animation.export() - - }, 1000) - me.timeoutTiming = setTimeout(() => { - clearInterval(me.draw); - me.draw = false; - me.animaTiming1 = false; - me.animaTiming2 = false; - // console.log("时间到,录音结束"); - recorderManager.stop(); - }, me.maxTime); + end() { + console.log("触摸结束==========") + manager.stop(); + }, + //取消弹窗 + cancelHandle(){ + this.popupShow = true ; + this.confirmSearchPopup = false; + this.keyword = ''; }, playVoice() { let me = this; - // console.log(" 点击 播放") - // console.log(me.voicePath) if (me.voicePath) { innerAudioContext.src = me.voicePath; innerAudioContext.play(); - // console.log("播放了声音") } }, hidePopup() { @@ -488,12 +482,6 @@ me.imageResults = response.result; me.imagesResultShow = true; } - - - // if (me.keywordList == 0 && !me.detailPopupShow) { - // me.noTitlemodalTap(); - // } - }, complete() { uni.hideLoading(); @@ -616,6 +604,7 @@ }, //执行搜索 doSearch(key) { + this.confirmSearchPopup = false ; uni.showLoading({ title: '正在努力查询中...' });