|
|
@ -77,6 +77,7 @@ import Socket from './utils/socket' |
|
|
|
import { splitTextForTTS } from './utils/util' |
|
|
|
import { |
|
|
|
getHistroyMsg, |
|
|
|
setMsgData |
|
|
|
} from './utils/message' |
|
|
|
import ClientData from './utils/ClientData'; |
|
|
|
import Pending from './components/pending'; |
|
|
@ -120,6 +121,7 @@ export default { |
|
|
|
tmpMsg: {}, |
|
|
|
lastTxt: {}, |
|
|
|
txtAudioStaus: {}, |
|
|
|
requestMsg: {}, |
|
|
|
disabledStatus: false |
|
|
|
} |
|
|
|
}, |
|
|
@ -151,11 +153,11 @@ export default { |
|
|
|
this.socketObj = new Socket({ |
|
|
|
agentId: this.agentId, |
|
|
|
onMessage: (e) => { |
|
|
|
const index = this.msgList.findIndex(it => it.request_id == e.request_id && it.type == 'reply') |
|
|
|
console.log(e.request_id + '回复内容', e.content) |
|
|
|
// const index = this.msgList.findIndex(it => it.request_id == e.request_id && it.type == 'reply') |
|
|
|
// this.tmpMsg[e.request_id] = this.tmpMsg[e.request_id] ?? [] |
|
|
|
// if (this.tmpMsg[e.request_id].length) { |
|
|
|
// const txt = this.removeSpecificText(e.content??'', this.lastTxt[e.request_id] ?? '') |
|
|
|
// const txt = e.content |
|
|
|
// if (txt) { |
|
|
|
// this.tmpMsg[e.request_id].push(txt) |
|
|
|
// } |
|
|
@ -163,7 +165,7 @@ export default { |
|
|
|
// this.tmpMsg[e.request_id].push(e.content) |
|
|
|
// } |
|
|
|
// this.lastTxt[e.request_id] = e.content |
|
|
|
// // console.log(this.tmpMsg[e.request_id]) |
|
|
|
|
|
|
|
// if (!this.txtAudioStaus[e.request_id]) { |
|
|
|
// this.txtAudioStaus[e.request_id] = true |
|
|
|
// this.renderTxt(e) |
|
|
@ -171,8 +173,12 @@ export default { |
|
|
|
|
|
|
|
// console.log(e.content) |
|
|
|
e.pending = false |
|
|
|
// 只输入文字 |
|
|
|
// if (index > -1) { |
|
|
|
// this.msgList[index] = e |
|
|
|
// this.msgList[index] = { |
|
|
|
// ...e, |
|
|
|
// content: this.msgList[index].content + e.content |
|
|
|
// } |
|
|
|
// } else { |
|
|
|
// if (this.msgList.length) { |
|
|
|
// const obj = this.msgList[this.msgList.length - 1] |
|
|
@ -184,34 +190,43 @@ export default { |
|
|
|
// } else { |
|
|
|
// this.msgList.push(e) |
|
|
|
// } |
|
|
|
|
|
|
|
// } else { |
|
|
|
// this.msgList.push(e) |
|
|
|
// } |
|
|
|
// } |
|
|
|
// // 写入缓存 |
|
|
|
// if (!e.is_from_self && e.is_final) { |
|
|
|
// setMsgData(this.msgList[index]) |
|
|
|
// } |
|
|
|
|
|
|
|
this.requestMsg[e.request_id] = (this.requestMsg[e.request_id] ? this.requestMsg[e.request_id] : '') + e.content |
|
|
|
|
|
|
|
if (!e.is_from_self && e.is_final) { |
|
|
|
e.content = this.requestMsg[e.request_id] |
|
|
|
const audioParams = e |
|
|
|
console.log( audioParams); |
|
|
|
// 回复结束 写入缓存 |
|
|
|
// 回复结束 写入缓存 |
|
|
|
setMsgData(audioParams) |
|
|
|
console.log('开始',audioParams); |
|
|
|
this.audio(audioParams, (txt)=> { |
|
|
|
|
|
|
|
const index = this.msgList.findIndex(it => it.request_id == e.request_id && it.type == 'reply') |
|
|
|
console.log(1111111, txt, index) |
|
|
|
if (index > -1) { |
|
|
|
this.msgList[index].content += txt |
|
|
|
this.$nextTick(() => { |
|
|
|
this.msgList[index].content += txt |
|
|
|
this.scrollToBottom() |
|
|
|
}) |
|
|
|
} else { |
|
|
|
if (this.msgList.length) { |
|
|
|
const obj = this.msgList[this.msgList.length - 1] |
|
|
|
if (obj.pending) { |
|
|
|
const tmp = { |
|
|
|
...e, |
|
|
|
pending: false, |
|
|
|
content: txt |
|
|
|
} |
|
|
|
this.msgList[this.msgList.length - 1] = tmp |
|
|
|
this.$nextTick(() => { |
|
|
|
const tmp = { |
|
|
|
...e, |
|
|
|
pending: false, |
|
|
|
content: txt |
|
|
|
} |
|
|
|
this.msgList[this.msgList.length - 1] = tmp |
|
|
|
this.scrollToBottom() |
|
|
|
}) |
|
|
|
} else { |
|
|
@ -222,8 +237,8 @@ export default { |
|
|
|
...e, |
|
|
|
pending: false |
|
|
|
} |
|
|
|
this.msgList.push(tmp) |
|
|
|
this.$nextTick(() => { |
|
|
|
this.msgList.push(tmp) |
|
|
|
this.scrollToBottom() |
|
|
|
}) |
|
|
|
} |
|
|
@ -231,8 +246,8 @@ export default { |
|
|
|
this.scrollToBottom() |
|
|
|
}) |
|
|
|
|
|
|
|
// |
|
|
|
this.disabledStatus = false |
|
|
|
// // |
|
|
|
// this.disabledStatus = false |
|
|
|
} |
|
|
|
this.scrollToBottom() |
|
|
|
} |
|
|
@ -307,8 +322,8 @@ export default { |
|
|
|
|
|
|
|
audioText(text, cb) { |
|
|
|
return new Promise(async (resolve, reject) => { |
|
|
|
if (!this.audioStatus) { reject() } |
|
|
|
const url = await this.loadAudioUrl(text) |
|
|
|
if (!this.audioStatus) { reject() } |
|
|
|
console.log('开始播放文字', text) |
|
|
|
cb && cb(text) |
|
|
|
this.audioCtx = wx.createInnerAudioContext(); |
|
|
|