diff --git a/miniprogram/app.json b/miniprogram/app.json index 386368a..dc9d82f 100644 --- a/miniprogram/app.json +++ b/miniprogram/app.json @@ -16,6 +16,12 @@ "navigationBarTitleText": "Weixin", "navigationBarTextStyle": "black" }, + "plugins": { + "WechatSI": { + "version": "0.3.5", + "provider": "wx069ba97219f66d99" + } + }, "style": "v2", "sitemapLocation": "sitemap.json", "usingComponents": { diff --git a/miniprogram/asset/icon/keyboard.png b/miniprogram/asset/icon/keyboard.png new file mode 100644 index 0000000..5641fc6 Binary files /dev/null and b/miniprogram/asset/icon/keyboard.png differ diff --git a/miniprogram/asset/icon/voice.png b/miniprogram/asset/icon/voice.png new file mode 100644 index 0000000..2b80792 Binary files /dev/null and b/miniprogram/asset/icon/voice.png differ diff --git a/miniprogram/pages/chat/chat.js b/miniprogram/pages/chat/chat.js index fe71171..a056bda 100644 --- a/miniprogram/pages/chat/chat.js +++ b/miniprogram/pages/chat/chat.js @@ -1,8 +1,11 @@ const app = getApp() import request from '../../utils/request' import { scrollToID, keyWordsEnum } from '../../utils/util' -Page({ +var plugin = requirePlugin("WechatSI") +let manager = plugin.getRecordRecognitionManager() +const record = wx.getRecorderManager() +Page({ /** * 页面的初始数据 */ @@ -22,7 +25,8 @@ Page({ interval: null, promotContentCount: 0, completionContentCount: 0, - noticeText: '' + noticeText: '', + inputMode: true }, /** @@ -397,6 +401,57 @@ Page({ }) }, + voiceMode() { + manager.start({ duration: 100, lang: "zh_CN" }) + manager.onStop(res => { + console.log('已获取麦克风调用权限!'); + }) + const inputMode = this.data.inputMode + this.setData({ + inputMode: !inputMode + }) + }, + + speakStart() { + console.log('按下'); + wx.showLoading({ + title: '请说话' + }) + manager.start({ duration: 30000, lang: "zh_CN" }) + manager.onStart = function (res) { + console.log("成功开始录音识别", res) + } + }, + + speakEnd() { + console.log('抬起'); + wx.hideLoading() + // wx.showLoading({ + // title: '正在识别', + // mask: true + // }) + manager.stop() + }, + + initVoiceManager() { + manager.onRecognize = function (res) { + console.log("current result", res.result) + } + + manager.onStop = function (res) { + console.log(res.tempFilePath, 'res'); + console.log(res.result, 'result'); + wx.hideLoading() + } + + manager.onError = function (res) { + console.error("error msg", res.msg) + wx.showToast({ + title: '太短了,请描述长一点', + icon: 'none' + }) + } + }, /** * 生命周期函数--监听页面初次渲染完成 @@ -409,7 +464,7 @@ Page({ * 生命周期函数--监听页面显示 */ onShow() { - + this.initVoiceManager() }, /** diff --git a/miniprogram/pages/chat/chat.less b/miniprogram/pages/chat/chat.less index 4592367..c6904db 100644 --- a/miniprogram/pages/chat/chat.less +++ b/miniprogram/pages/chat/chat.less @@ -212,9 +212,23 @@ page { .boxOutside { margin-bottom: 20rpx; + .voiceBtn { + height: 70rpx; + margin-right: 20rpx; + } + + .pushBtn { + display: inline-block; + width: 530rpx; + height: 70rpx; + line-height: 60rpx; + padding: 5rpx 0; + margin-left: 35rpx; + } + .inputBox { display: inline-block; - width: 480rpx; + width: 410rpx; height: 70rpx; line-height: 70rpx; border-radius: 10rpx; diff --git a/miniprogram/pages/chat/chat.wxml b/miniprogram/pages/chat/chat.wxml index 25ebe07..e2e8195 100644 --- a/miniprogram/pages/chat/chat.wxml +++ b/miniprogram/pages/chat/chat.wxml @@ -40,8 +40,14 @@ - + + + + + + + \ No newline at end of file diff --git a/miniprogram/pages/index/index.wxml b/miniprogram/pages/index/index.wxml index 2b3cc9e..3dcc10c 100644 --- a/miniprogram/pages/index/index.wxml +++ b/miniprogram/pages/index/index.wxml @@ -53,7 +53,7 @@ 用户协议 延续历史 - +