微信同声传译

1.manifest.json在mp-weixin目录下进行配置

 "plugins" : {
            "WechatSI" : {
                "version" : "0.3.4", // 这是同声传译的版本(也可以在微信公众平台添加的同声传译查看最新版本)
                "provider" : "wx069ba97219f66d99" // 这是同声传译的ID
            }
        },

2.vue页面如下

<template>
    <view class="content">
        <view class="cu-form-group">
            <view class="title xrequired">事件描述</view>
            <textarea v-model="myFormData.description" placeholder="请填写事件描述" rows="5"></textarea>
        </view>
        <view class="cu-form-group" style="border-top: none;">
            <button @touchstart="touchStart" @touchend="touchEnd">语音录入</button>
        </view>
    </view>
</template>
<script>
    var plugin = requirePlugin("WechatSI")
    let manager = plugin.getRecordRecognitionManager()
    export default {
        data() {
            return {
                myFormData: {    
                    description: ''
                },
            }
        },
        onLoad() {
            this.initRecord();

        },
        methods: {
            /**
             * 初始化语音识别回调
             * 绑定语音播放开始事件
             */
            initRecord: function() {
                manager.onStart = function(res) {
                    console.info("onStart",res)
                };
                //有新的识别内容返回,则会调用此事件
                manager.onRecognize = (res) => {
                    console.info("onRecognize",res)
                    
                };
                // 识别结束事件
                manager.onStop =(res) => {
                    console.info("onStop",res)
                    this.myFormData.description += res.result;
                };
                // 识别错误事件
                manager.onError = (res) => {
                    console.info("onError",res)
                    uni.showModal({
                        title: "提示",
                        content: "听不清楚,请重新说一遍!",
                        showCancel: false
                    })
                }
            },
            touchStart: function() {
                manager.start({
                    duration: 60000,
                    lang: "zh_CN"
                });
                uni.showToast({
                    title: '开始语音',
                    icon: 'success',
                    image: '../image/icon.png',
                    image: '../../static/microphone.png',
                    duration: 60000,
                    position: "top"
                });
            },
            touchEnd: function() {
                uni.hideToast()
                manager.stop();
            },

        }
    }
</script>
<style>

</style>
 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值