收藏
回答

websocket api wx.onsocketmessage接收不到消息?

调用搜狗AI开放平台的asr语音识别接口。二进制音频数据已经发送成功,但是接受不到服务器消息。

const recorder=wx.getRecorderManager()
const recordconfig={
  frameSize25,
  sampleRate16000,
  format'WAV',
  numberOfChannels1
}
const app=getApp()
  openSocketfunction(){
    wx.connectSocket({
      url'wss://api.zhiyin.sogou.com/wss/asr/v1/streaming_recognize?Appid=1WCCVjJBLB5GzcRIEepsbmxNdgd&Authorization=Bearer '+wx.getStorageSync('token'),
      timeout600000,
      successres=>{
        console.log("连接成功")
      }
    })
    wx.onSocketMessage(res => {
      console.log(res)
    })
    wx.onSocketOpen((result) => {
      console.log(result)
      let config={
        "encoding""LINEAR16",
        "sample_rate_hertz"16000,
        "language_code""zh-cmn-Hans-CN"
      }
      let streamconfig={
        "config": config,
        "interim_results"true
      }
      wx.sendSocketMessage({
        dataJSON.stringify(streamconfig),
        successres=>{
          console.log('发送初始帧')
        }
      })
      recorder.start(recordconfig)
      recorder.onFrameRecorded(res=>{
        wx.sendSocketMessage({
          data: wx.arrayBufferToBase64(res.frameBuffer),
          successres=>{
            console.log('发送数据帧')
          }
        })
      })
    }) 
  }
最后一次编辑于  10-14
回答关注问题邀请回答
收藏

2 个回答

登录 后发表内容
问题标签