diff --git a/components/GPT/index.vue b/components/GPT/index.vue index 978c55f..2116129 100644 --- a/components/GPT/index.vue +++ b/components/GPT/index.vue @@ -56,29 +56,36 @@ - - - - 按住 说话 + + + + + 按住 说话 + + + + - - - - @@ -141,7 +148,9 @@ export default { requestMsg: {}, disabledStatus: false, audioOBJ: null, - reAudioType: false + reAudioType: false, + + stopStatus: false } }, onLoad() { @@ -161,8 +170,9 @@ export default { this.audioActive = '' this.audioStatus = false this.asrStatus = false - this.player && this.player.destroy() + this.stopStatus = false + this.currentRecordId = '' }, onHide() { console.log('【hide message connect type------>】',); @@ -171,7 +181,40 @@ export default { this.scrollToBottom() }, methods: { + stopMessage(){ + // 暂停播放 + console.log('暂停语音',); + this.stopStatus = true + // 取消对话框回复 + this.stopMSN() + // 暂停语音播放 + if (this.player) { + this.player.destroy() + } + + // 清楚当前如果是pending的信息 + if (this.msgList && this.msgList.length) { + const last = this.msgList[this.msgList.length - 1] + console.log('last', last); + if (last.pending) { + this.msgList.pop() + } + } + + this.audioActive = '' + this.disabledStatus = false + }, + stopMSN () { + if (this.socketObj && this.socketObj.socket) { + const options = { data: "42" + JSON.stringify(["stop_generation", { + payload: { + record_id: this.currentRecordId + } + }]) } + this.socketObj.send(options) + } + }, /* 4. 滚动日志 */ appendLog(str) { console.log(1111, str) @@ -181,6 +224,11 @@ export default { sampleRate: 16000, onPlay: (obj) => { console.log('播放文字', obj) + // 暂停 + if (this.stopStatus) { + return + } + this.disabledStatus = true if (obj.is_final) { // 最后一条语音 @@ -250,6 +298,11 @@ export default { // const player = new AudioStreamPlayer() this.audioOBJ = new Audio({ onMessage: (e) => { + // 暂停 + if (this.stopStatus) { + return + } + if (e instanceof ArrayBuffer) { this.player.feed(e) return @@ -328,7 +381,15 @@ export default { this.socketObj = new Socket({ agentId: this.agentId, onMessage: (e) => { - console.log(e.request_id + '回复内容', e.content) + console.log(111111, e.record_id, e.request_id + '回复内容', e.content) + // 记录当前记录id + self.currentRecordId = e.record_id + // 暂停 + if (this.stopStatus) { + this.stopMSN() + return + } + e.pending = false self.requestMsg[e.request_id] = (self.requestMsg[e.request_id] ? self.requestMsg[e.request_id] : '') + e.content @@ -389,6 +450,7 @@ export default { async audio(n, status) { console.log('【audio------>】', n, status); + this.stopStatus = false this.reAudioType = !status this.audioArray = [] // this.audioArray = this.audioArray.slice(-10) @@ -708,6 +770,7 @@ export default { }) }, onSendQuestion(e) { + this.stopStatus = false let self = this if (e === '') { return wx.showToast({ title: '不能发送空白消息', icon: 'none' }) @@ -843,6 +906,12 @@ export default { margin: 0 20rpx; background: #fff; + .input-content { + flex: 1; + display: flex; + position: relative; + } + .chatinput-input-wrap { flex: 1; height: 80rpx; diff --git a/components/GPT/utils/pcm-player.js b/components/GPT/utils/pcm-player.js index d591f49..5d68e21 100644 --- a/components/GPT/utils/pcm-player.js +++ b/components/GPT/utils/pcm-player.js @@ -83,7 +83,8 @@ export default class PcmPlayer { } // 3. 播放并等待结束 - await new Promise((resolve) => { + await new Promise((resolve, reject) => { + if (!this.isPlaying) {return reject()} const src = this.audioCtx.createBufferSource(); src.buffer = buf; src.connect(this.audioCtx.destination); diff --git a/components/WaterfallLayout.vue b/components/WaterfallLayout.vue index 3ddb72f..fc94005 100644 --- a/components/WaterfallLayout.vue +++ b/components/WaterfallLayout.vue @@ -15,12 +15,23 @@ class="waterfall-item" @click="handleItemClick(index, leftItems)" > - + + + + + {{ + item.status === 0 ? "待审核" : "审核不通过" + }} + + {{ item.title }} @@ -32,7 +43,11 @@ /> {{ item.nickname }} -