收藏
回答

同声传译插件开始识别延迟怎么处理

我的小程序里使用了同声传译插件,因为业务不是很复杂,没有像官方的面对面翻译小程序一样使用自定义组件,页面中没有使用任何自定义组件,在页面的js里调用

manager.start({

duration: 60000,

lang: "zh_CN"

})方法后,大概300到400毫秒以后才能开启录音功能,比如我点击开始识别的按钮,也就是这个按钮绑定的事件执行了manager.start这个方法,如果我马上就说一瓶可乐,识别的内容返回值只有可乐,一瓶这两个字就没识别到,如果我点击按钮稍微等一秒钟再说活,识别的内容就全了,官方的例子就感觉识别的很快,我自己的程序就不行,我的问题是这300毫秒到400毫秒的延迟我怎么解决,虽然这个时间不长,但是影响了用户体验,这块是一定要像官方去用自定义组件去处理才是最优方案吗,或者说这块应该怎么去处理,或者说文档中没有提到的细节需要我们自行处理吗


const app = getApp()

const plugin = requirePlugin("WechatSI")

const manager = plugin.getRecordRecognitionManager()

const url = require('../../utils/api.js')

const api = require('../../utils/request.js')

Page({


/**

  * 页面的初始数据

  */

    data: {

        order: '',

        start: 0,

        btnText: '按住说话',

        file: ''

    },

    fnStart: function() {

    //清除杂音

        wx.stopBackgroundAudio();

        manager.start({

        duration: 60000,

        lang: "zh_CN"

    })

        var that = this;

        setTimeout(function(){

                that.setData({

                start: 1,

                btnText: '松开结束',

                order: ''

           })

        },400)

        //屏幕常亮,防止灭屏

        wx.setKeepScreenOn({

                keepScreenOn: true

        })

    },

    fnEnd: function() {

            var that = this;

            that.setData({

                    start: 0,

                    btnText: '按住说话',

            })

            manager.stop();

        },

        init: function() {

                var that = this;

                manager.onRecognize = function(res) {

                            console.log("current result", res.result)

                }

                manager.onStop = function(res) {

                            console.log("record file path", res.tempFilePath);

                                console.log("result", res.result);

                                var result = res.result;

                            if (result) {

                                    that.setData({

                                    order: res.result,

                                    file: res.tempFilePath

                              })

                                var params = {

                                            userId: '123456',

                                            query: result

                                };

                            var file = res.tempFilePath;

                            //语音下单

                            api.requestLoading(url.orderUrl, params, '下单中...', function(res) {

                                            console.log(res.result);

                                            var res = JSON.stringify(res.result)

                                            if (res == '' || res == null || res == '[]') {

                                                                wx.showToast({

                                                                            title: '我没听懂,我还在努力成长中',

                                                                            icon: 'none',

                                                                            duration: 2000

                                                                })

                                            } else {

                                                                that.setData({

                                                                order: res

                                            })

                                            console.log(res);

                                            }

                                })


                                    } else {

                                            wx.showToast({

                                                title: '请说话',

                                                image: '../../images/no_voice.png',

                                                mask: true

                                            })

                                    }

                            }

},

/**

  * 生命周期函数--监听页面加载

  */

onLoad: function(options) {

                this.init();

                app.getRecordAuth()

},

})




最后一次编辑于  2018-06-25
回答关注问题邀请回答
收藏

1 个回答

  • Lethe
    Lethe
    2018-06-26

    下一个版本将会优化~~

    2018-06-26
    赞同
    回复