收藏
回答

语音转文字失败

问题类型 API/组件名称 终端类型 微信版本 基础库版本
Bug wx.qy.translateVoice 微信iOS客户端 3.1.2 2.10.1

企业微信调用 wx.qy.translateVoice 接口总是出错,

iOS fail 提示为:

{

errCode: "-100"

errMsg: "qy__translateVoice:fail system error"

}

Android 错误提示为:

{

    errMsg: "qy.translateVoice:fail translate error:13"

}

下面是代码:

{
  /**
   * 页面的初始数据
   */
  data: {
    currentTab: 2,
    recordOperating: false,
    isRecording: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.inputModal = this.selectComponent('#inputModal');

    const _this = this;
    this.recorderManager = wx.getRecorderManager();
    this.recorderManager.onError(function (res){
      console.log('on record onError: ', res);
      if (_this.data.isRecording) {
        wx.showToast({
          title: '录音失败',
          icon: 'none'
        });
      }

      _this.setData({ isRecording: false, recordOperating: false });
    });
    this.recorderManager.onStart(function (){
      console.log('开始录音...');
      _this.setData({ isRecording: true, recordOperating: false });
    });
    this.recorderManager.onStop(function (res){
      console.log('speak stopped: ', res);
      _this.setData({ isRecording: false, recordOperating: false });
      _this.translateVoice(res.tempFilePath);
    });
  },

  onShow: function() {
    this.recorderManager && this.recorderManager.stop();
    
    if(!wx.getStorageSync('_qyWeChat')) {
      wx.showToast({
        title: '请在企业微信中使用此功能',
        icon : 'none'
      });
      return ;
    }
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.showLoading({
      title: '刷新中...',
    });
  },

  /*************************点击事件*********************** */
  handleNewNote: function() {
    this.inputModal.showModal();
  },

  handleToggleRecord: function() {
    if (this.data.recordOperating) {
      return;
    }

    if (this.data.isRecording) {
      this.recorderManager.stop();
    } else {
      this.recorderManager.start({
        format: 'pcm',
        sampleRate: 16000,
        numberOfChannels: 1,
        encodeBitRate: 96000
      });
    }

    this.setData({ recordOperating: true });
  },

  /*************************页面方法*************************/
  translateVoice(savedFile) {
    wx.qy.translateVoice({
      filePath: savedFile,
      isShowProgressTips: 1,
      success: (res) => {
        console.log('语音转换文字结果: ', res)
        var result  = res.translateResult
      },
      fail: (res) => {
        console.log('语音转文字失败: ', res);
        wx.showToast({
          title: '语音转换文字失败!',
          icon: 'none'
        });
      }
    })
  }
}


回答关注问题邀请回答
收藏
登录 后发表内容
问题标签