更新
This commit is contained in:
parent
a975ee882f
commit
1f98b82090
@ -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:{}
|
||||
|
@ -31,7 +31,7 @@
|
||||
<scroll-view class="chat" scroll-y="true" scroll-with-animation="true" :scroll-into-view="scrollToView">
|
||||
<view class="chat-main" :style="{paddingBottom:inputh+'px'}">
|
||||
<view class="chat-ls" v-for="(item,index) in messagesList" :key="index" :id="'msg'+ index">
|
||||
<view class="msg-m msg-right">
|
||||
<view class="msg-m msg-right" v-if="item.isTrans">
|
||||
<image class="user-img" :src="imagesUrl+userAvatar"></image>
|
||||
<view class="message" v-if="item.inputs.type == 'text'">
|
||||
<!-- 文字 -->
|
||||
@ -69,12 +69,12 @@
|
||||
|
||||
<view class="msg-text" @click="clickSprink(index)" id="po_" v-else>
|
||||
<view class="po_z" v-if="show=='1'&&clickIdx==index">
|
||||
<view class="size_" @click="voiceTxt(item.answer)">Voice</view>
|
||||
<view class="size_" @click="voiceTxt(item)">Voice</view>
|
||||
|
||||
</view>
|
||||
{{ item.answer }}
|
||||
<br/>
|
||||
<text v-if="item.answerCh">{{ item.answerCh }}</text>
|
||||
<!-- <text v-if="item.answerCh">{{ item.answerCh }}</text>-->
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@ -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'
|
||||
|
@ -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 => {
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user