From 1f98b820905eeebe4fe1aea5adf82e99228cdd7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E5=85=81=E6=9E=9E?= <3422692813@qq.com> Date: Tue, 11 Mar 2025 18:12:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dc-App/pages/Chat/chat.vue | 10 +- dc-App/pages/Chat/newChat.vue | 95 ++++++++++++++----- dc-App/pages/Chat/newChat/submit.vue | 2 +- dc-App/pages/busNavigation/busNavigation.nvue | 10 +- 4 files changed, 84 insertions(+), 33 deletions(-) diff --git a/dc-App/pages/Chat/chat.vue b/dc-App/pages/Chat/chat.vue index 3331e5f..b70a943 100644 --- a/dc-App/pages/Chat/chat.vue +++ b/dc-App/pages/Chat/chat.vue @@ -22,6 +22,11 @@ return { msg: "2", list:[ + {title:'Translator', + icon:'../../static/chatImg/fy.png', + token:'Bearer app-EcJaT2EkUjHNJsax9SwESQuK', + detail:'', + conversation:'Translator'}, {title:'Trip Advisor', icon:'../../static/chatImg/lxgw.png', token:'Bearer app-4Wqu03XTw297LtEsTXhotOuP', @@ -37,11 +42,6 @@ token:'Bearer app-4Wqu03XTw297LtEsTXhotOuP', detail:'', conversation:'Ai'}, - {title:'Translator', - icon:'../../static/chatImg/fy.png', - token:'Bearer app-EcJaT2EkUjHNJsax9SwESQuK', - detail:'', - conversation:'Translator'} ], userInfo:{} diff --git a/dc-App/pages/Chat/newChat.vue b/dc-App/pages/Chat/newChat.vue index 9a5e6dc..988772e 100644 --- a/dc-App/pages/Chat/newChat.vue +++ b/dc-App/pages/Chat/newChat.vue @@ -31,7 +31,7 @@ - + @@ -69,12 +69,12 @@ - Voice + Voice {{ item.answer }}
- {{ item.answerCh }} +
@@ -258,15 +258,18 @@ export default { submit, }, methods: { - async voiceTxt(text) { + async voiceTxt(item) { + console.log('执行了') let res = await request({ url: 'youDaoApi/tts', method: 'post', data: { - q: text, + q: item.answer, voiceName: this.lang, + language: item.lang } }) + console.log('语音合成', res) this.playBase64Mp3(res.data) this.show = false @@ -369,6 +372,42 @@ export default { this.msgInfo() //追加心跳机制 }, + translatorChinese() { + //调用api翻译成中文 + request({ + url: 'chatHttpApi/getChatInfo', + method: 'post', + data: { + q: this.messagesList[this.messagesList.length - 1].answer, + lang: this.lang + } + }).then(res => { + this.$nextTick(() => { + let msgItem = { + "inputs": { + "type": "text" + }, + "query": '', + "response_mode": 'streaming', + "conversation_id": uni.getStorageSync(this.info.conversation) || null, + "user": this.userId, + 'token': this.info.token, + 'answer': res.msg, + 'answerCh': '', + 'showImageTextIndex': '', + 'showImage': '', + 'imageText': '', + 'time': '', + 'type': '', + 'filePath': '', + "lang": "Chinese", + 'isTrans':false, + }; + this.messagesList.push(msgItem); + // this.messagesList[this.messagesList.length - 1].answerCh = this.messagesList[this.messagesList.length - 1].answerCh + res.msg + }) + }) + }, msgInfo() { if (this.msgSocket) { this.msgSocket.onMessage(res => { @@ -376,19 +415,10 @@ export default { if (this.messagesList[this.messagesList.length - 1].inputs.type != 'image') { this.messagesList[this.messagesList.length - 1].answer = this.messagesList[this .messagesList.length - 1].answer + res.data - //调用api翻译成中文 - request({ - url: 'chatHttpApi/getChatInfo', - method: 'post', - data: { - q: this.messagesList[this.messagesList.length - 1].answer, - lang: this.lang - } - }).then(res => { - this.$nextTick(() => { - this.messagesList[this.messagesList.length - 1].answerCh = this.messagesList[this.messagesList.length - 1].answerCh + res.msg - }) - }) + if (this.lang == 'Chinese' || this.sayLang == 'zh-CHS') { + }else { + this.translatorChinese() + } } else { //将res.data 转为json let json = JSON.parse(res.data) @@ -505,14 +535,32 @@ export default { } }); }, + //音频播放 playVoice(e) { - console.log(e); - innerAudioContext.src = e; - - innerAudioContext.play(() => { + let innerAudioContext1 = uni.createInnerAudioContext(); + innerAudioContext1.autoplay = true; + innerAudioContext1.src = 'data:audio/mp3;base64,'+e.replace(/[\r\n]/g, ""); + innerAudioContext1.onPlay(() => { console.log('开始播放'); }); + + // console.log('音频开始') + // innerAudioContext.src = `data:audio/mp3;base64,${e}`; + // // innerAudioContext.src = e; + // // console.log(innerAudioContext.src); + // + // // 3. 添加事件监听 + // innerAudioContext.onPlay(() => { + // console.log('开始播放'); + // }); + // + // innerAudioContext.onError((err) => { + // console.error('播放错误:', err); + // }); + // + // // 4. 开始播放 + // innerAudioContext.play(); }, //地图定位 covers(e) { @@ -523,6 +571,7 @@ export default { }] return (map); }, + //跳转地图信息 openLocation(e) { uni.openLocation({ @@ -563,6 +612,8 @@ export default { 'time': inputData.time, 'type': '', 'filePath': inputData.filePath, + "lang": this.lang, + 'isTrans':true, }; if (this.info.conversation == 'Translator') { msgItem.response_mode = 'blocking' diff --git a/dc-App/pages/Chat/newChat/submit.vue b/dc-App/pages/Chat/newChat/submit.vue index 8174d66..238adb8 100644 --- a/dc-App/pages/Chat/newChat/submit.vue +++ b/dc-App/pages/Chat/newChat/submit.vue @@ -347,7 +347,7 @@ export default { type: 2 } }).then(ress => { - that.send(ress.data, 2, res.tempFilePath, that.vlength, res.base64) + that.send(ress.data, 2, res.base64, that.vlength, res.base64) this.vlength = 0; }) }).catch(error => { diff --git a/dc-App/pages/busNavigation/busNavigation.nvue b/dc-App/pages/busNavigation/busNavigation.nvue index a97ef24..0f29fd8 100644 --- a/dc-App/pages/busNavigation/busNavigation.nvue +++ b/dc-App/pages/busNavigation/busNavigation.nvue @@ -687,7 +687,7 @@ /* 如果父容器需要限制宽度 */ display: block; - max-width: 100%; + //width: 100%; } .text_line { @@ -712,8 +712,8 @@ .c_c_title { - //width: 260rpx; - width: 90%; + width: 300rpx; + //width: 99%; height: 52rpx; border-radius: 8rpx 8rpx 8rpx 8rpx; background: #fcd702; @@ -806,10 +806,10 @@ } .bz_width { - width: 47%; + //width: 100%; } .segment-item{ - width: 290rpx; + width: 300rpx; margin: 5rpx 2rpx; padding-right: 25rpx; }