收藏
回答

语音识别API在云函数中调用失败?

// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境
const db = cloud.database()
const _ = db.command
const request = require('request');


const rp = options => new Promise((resolve, reject) => {
  request(options, (error, response, body) => {
    if (error) {
      reject(error);
    } else {
      resolve({ response });
    }
  });
});



// 云函数入口函数
exports.main = async (event, context) => {
  const result1 = await rp({
    url: event.url1,
    method: 'POST',
    data: event.fileBuff,
  })
  const result2 = await rp({
    url: event.url2,
    method: 'POST',
  })
  return {
    res1:result1.response.body,
    res2:result2.response.body,
  }


}


以上是我在云函数中调用2次request请求调用语音识别接口的代码。文档在:https://developers.weixin.qq.com/doc/offiaccount/Intelligent_Interface/AI_Open_API.html,以上过程在微信小程序中可以成功调用,但是搬到云函数中,第一个request请求始终报错:res1"{"errcode":40010,"errmsg":"invalid voice size hint: [JMWmeA05037-15] rid: 68024dff-58e53a57-301b0dbb"}"。

我确认过语音文件大小没有超标(只有45KB),时长也没超过60s。

回答关注问题邀请回答
收藏

1 个回答

  • Mr.Zhao
    Mr.Zhao
    04-18

    不用云函数呢,本地写个nodejs,报啥错

    04-18
    有用
    回复 7
    • Jormungand
      Jormungand
      04-18
      调用的URL:https://api.weixin.qq.com 不是合法request域名,也不允许加入合法域名。wx.request无法在上线版本中调用该API
      04-18
      回复
    • Mr.Zhao
      Mr.Zhao
      04-18回复Jormungand
      你想说什么啊
      04-18
      回复
    • Jormungand
      Jormungand
      04-19回复Mr.Zhao
      就是我不得不用云函数
      04-19
      回复
    • Mr.Zhao
      Mr.Zhao
      04-19回复Jormungand
      我让你排查问题呢,扯的远了
      04-19
      回复
    • Jormungand
      Jormungand
      04-19回复Mr.Zhao
      用node.js也是一样的错误,request请求是成功发出去了的,只是返回 40010,errcode 40010,表示不合法的语音大小
      04-19
      回复
    查看更多(2)
登录 后发表内容