企业微信调用 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'
});
}
})
}
}