zsbd
- 发布:2023-08-16 13:48
- 更新:2024-09-09 05:00
- 阅读:258
产品分类: uniapp/App
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: win10
HBuilderX类型: 正式
HBuilderX版本号: 3.8.11
手机系统: iOS
手机系统版本号: iOS 16
手机厂商: 苹果
手机机型: iphone14
页面类型: vue
vue版本: vue2
打包方式: 云端
项目创建方式: HBuilderX
操作步骤:
预期结果:
onOpen onClose 正常触发
onOpen onClose 正常触发
实际结果:
连接成功 监听函数未触发
连接成功 监听函数未触发
bug描述:
生成scoketTask后监听 url采用科大讯飞的语音识别接口 wsConfig是url的域名 host app信息 鉴权的设置
安卓正常触发
IOS连接成功 不能触发监听的周期
function connectSocket(url) {
console.log(url);
let socketTask = uni.connectSocket({
url: url,
complete: () => {},
fail: () => {},
success: () => {
console.log("webSocket连接成功")
}
})
return socketTask
}
const recorderManager = uni.getRecorderManager();
onLoad() {
const that = this;
this.getAllClass()
this.avatar = uni.getStorageSync('userinfo').touXiang
recorderManager.onStop(async function(res) {
console.log('recorder stop' + JSON.stringify(res));
that.voiceFlag = false
that.voicePath = res.tempFilePath;
let file = await pathToBase64(that.voicePath)
let date = (new Date().toUTCString())
let url = WsConfig.hostUrl + "?authorization=" + that.getAuthStr(date) + "&date=" + date +
"&host=" + WsConfig.host
// url = 'https://www.websocket.in/'
console.error('url', url)
that.socketTask = socket.connectSocket(url)
that.socketTask.onError((err) => {
console.error("连接错误报文=>", err)
})
uni.onSocketOpen(() => {
console.log("监听Open")
that.socketTask.send({
data: JSON.stringify(that.send(file.split(',')[1])),
success: () => {
console.log(status, "发送状态");
status = FRAME.STATUS_LAST_FRAME
that.socketTask.send({
data: JSON.stringify(that.send("")),
success: () => {
console.log(status, "发送状态");
uni.showLoading()
if (status === FRAME.STATUS_LAST_FRAME) {
setTimeout(() => {
if (status === FRAME
.STATUS_LAST_FRAME) {
status = FRAME
.STATUS_FIRST_FRAME
uni.hideLoading()
uni.showToast({
title: "语音识别socket连接失败",
icon: "none"
})
}
}, 2000)
}
that.socketTask.onMessage(data => {
uni.hideLoading()
let msg = JSON.parse(data.data)
console.log("res", msg)
if (msg.code === 0) {
let ws = msg.data.result.ws
let voice = '';
for (let item in ws) {
let data = ws[item]
for (let key in data
.cw) {
voice += data.cw[
key].w
}
}
if (voice !== '') {
let data = {
type: 'user',
text: voice
}
that.talkList.push(
data)
let text = voice.split(
'。')
that.getId()
that.toSearch(text[0])
} else {
uni.showToast({
icon: "none",
title: "语音未识别"
})
}
} else {
uni.showToast({
icon: "none",
title: "语音识别失败"
})
}
that.socketTask.close({
success() {
console.log(
"SocketTask 关闭成功"
)
uni.hideLoading()
status = FRAME
.STATUS_FIRST_FRAME
console.log(
status);
}
});
});
}
})
},
fail: () => {
uni.hideLoading()
status = FRAME.STATUS_FIRST_FRAME
uni.showToast({
title: "语音识别socket发送失败",
icon: "none"
})
}
})
})
})
},
7***@qq.com
请问如何解决的
2023-08-28 17:48
3***@qq.com
怎么解决的?
2024-09-09 05:00
7***@qq.com
回复 3***@qq.com: 请问如何解决的?
2024-11-27 16:56