websocket api wx.onsocketmessage接收不到消息?
调用搜狗AI开放平台的asr语音识别接口。二进制音频数据已经发送成功,但是接受不到服务器消息。 [图片] const recorder=wx.getRecorderManager()
const recordconfig={
frameSize: 25,
sampleRate: 16000,
format: 'WAV',
numberOfChannels: 1
}
const app=getApp()
openSocket: function(){
wx.connectSocket({
url: 'wss://api.zhiyin.sogou.com/wss/asr/v1/streaming_recognize?Appid=1WCCVjJBLB5GzcRIEepsbmxNdgd&Authorization=Bearer '+wx.getStorageSync('token'),
timeout: 600000,
success: res=>{
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({
data: JSON.stringify(streamconfig),
success: res=>{
console.log('发送初始帧')
}
})
recorder.start(recordconfig)
recorder.onFrameRecorded(res=>{
wx.sendSocketMessage({
data: wx.arrayBufferToBase64(res.frameBuffer),
success: res=>{
console.log('发送数据帧')
}
})
})
})
}