修改语音识别

This commit is contained in:
jia 2023-10-23 09:36:53 +08:00
parent a95ef0427a
commit 7c349b94e9
3 changed files with 502 additions and 393 deletions

View File

@ -218,168 +218,21 @@
// init() { // opt
// let self = this
// let ctx = uni.createCanvasContext('ctx')
// setTimeout(()=>{
// self.drawBg(ctx, 330, this.cliceHeight, 8, '#fff')
// self.drawTxtOne(ctx, '', 220, 35, 100,
// '#222', 12, false)
// //
// self.drawImg(ctx,
// 'https://lihai001.oss-cn-chengdu.aliyuncs.com/storage/202310/20231013091310.png',
// 170, 10, 40, 40, 20)
// self.drawImg(ctx,
// 'https://lihai001.oss-cn-chengdu.aliyuncs.com/storage/202310/20231013091059.png',
// 10, 50, 40, 40, 20)
// self.drawImg(ctx,
// 'https://lihai001.oss-cn-chengdu.aliyuncs.com/storage/202310/20231013091310.png',
// 10, 118, 40, 40, 20)
// //
// self.drawImg(ctx,
// 'https://lihai001.oss-cn-chengdu.aliyuncs.com/storage/202310/ai_qr_20231013091327.jpg',
// 174, this.cliceHeight-125, 100, 100, 0)
// //
// self.drawTxtOne(ctx, self.pext1, 60, 70, 100,
// '#222', 12, false)
// //
// self.drawTxtFour(ctx,
// self.pext2,
// 60, 120,
// 190, 20, '#222', 12)
// //
// self.drawTxtOne(ctx, '', 15, this.cliceHeight-85, 100,
// '#666', 11, false)
// //
// ctx.draw()
// self.show = true
// },1000)
// //
// //
// // uni.downloadFile({
// // url: 'http://banbai.oss-cn-beijing.aliyuncs.com/20230524/96e80fb572e35d4acebdce67dbd41f30.jpg',
// // success: function(e) {
// // let img = e.tempFilePath //
// // uni.downloadFile({
// // url: 'http://banbai.oss-cn-beijing.aliyuncs.com/20230524/96e80fb572e35d4acebdce67dbd41f30.jpg',
// // success: function(e) {
// // let photo = e.tempFilePath //
// // uni.downloadFile({
// // url: 'http://banbai.oss-cn-beijing.aliyuncs.com/20230606/f0738e1ff432c08b369ca5e4b906a34a.png',
// // success: function(e) {
// // uni.hideLoading()
// // let qrcode = e.tempFilePath //
// // self.drawTxtOne(ctx, '', 220, 35, 100,
// // '#222', 12, false)
// // //
// // self.drawImg(ctx,
// // 'https://lihai001.oss-cn-chengdu.aliyuncs.com/storage/202310/20231013091310.png',
// // 170, 10, 40, 40, 20)
// // self.drawImg(ctx,
// // 'https://lihai001.oss-cn-chengdu.aliyuncs.com/storage/202310/20231013091059.png',
// // 10, 50, 40, 40, 20)
// // self.drawImg(ctx,
// // 'https://lihai001.oss-cn-chengdu.aliyuncs.com/storage/202310/20231013091310.png',
// // 10, 118, 40, 40, 20)
// // //
// // // self.drawImg(ctx, img, 10, 120, 210, 260, 8)
// // //
// // self.drawImg(ctx,
// // 'https://lihai001.oss-cn-chengdu.aliyuncs.com/storage/202310/ai_qr_20231013091327.jpg',
// // 174, 195, 100, 100, 0)
// // //
// // self.drawTxtOne(ctx, self.pext1, 60, 70, 100,
// // '#222', 12, false)
// // // self.drawTxtTwo(ctx, self.pext1, 60, 64, 80,
// // // '#222', 13)
// // // self.drawTxtTwo(ctx, self.pext1, 60,64,
// // // 190, 20, '#222', 12)
// // //
// // // self.drawTxtOne(ctx, '', 60, 80, 100,
// // // '#666', 9, false)
// // //
// // self.drawTxtFour(ctx,
// // self.pext2,
// // 60, 120,
// // 190, 20, '#222', 12)
// // //
// // self.drawTxtOne(ctx, '', 15, 250, 100,
// // '#666', 11, false)
// // //
// // // self.drawTxtOne(ctx, '', 15, 350, 100,
// // // '#ED3327', 11, false)
// // //
// // // self.drawTxtOne(ctx, '86.00', 82, 350, 100,
// // // '#ED3327', 11, true)
// // //
// // // self.drawTxtDel(ctx, ':20', 15, 370, 4,
// // // '#818181', 10, false)
// // //
// // ctx.draw()
// // self.show = true
// // }
// // })
// // }
// // })
// // }
// // })
// },
down() {
uni.showLoading({
title: '保存中'
})
uni.canvasToTempFilePath({
canvasId: 'ctx',
quality: 1,
success: (res) => {
uni.hideLoading()
console.log(res)
this.$emit('down', res)
this.show = false
//
uni.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
filePath: this.tempImage,
success: (res) => {
console.log('保存')
uni.hideLoading()
this.close()
uni.showModal({
title: '保存成功'
})
}
})
}
})
},
//
drawBg(ctx, w, h, r, color) {

View File

@ -3,7 +3,7 @@
{
"path": "pages/index/index",
"style": {
"navigationBarTitleText": "农业咨询",
"navigationBarTitleText": "教育咨询",
"navigationStyle": "custom",
"bounce": "none"
// "softinputMode": "adjustResize"

View File

@ -6,7 +6,7 @@
<view class="" style="position: absolute;left: 30rpx;"><i class="iconfont icon-xiangzuo"
style="font-size: 40rpx;text-align: left;"></i></view>
<view class="" style="font-size: 30rpx;">
农业咨询
情感咨询
</view>
</view>
<view style="padding-top:var(--status-bar-height);padding-bottom: 30rpx; margin-bottom: 30rpx;"></view>
@ -36,9 +36,9 @@
</view>
<view v-for="(item,index) in talkList" :key="index" :id="`msg-${item.id}`">
<view class="item flex_col" :class="item.type == 1 ? 'push':'pull' ">
<image :src="item.type==1?avatar:item.pic" mode="aspectFill" class="pic" v-if="item.pic">
</image>
<view class="content" v-if="item.id=='@'">
<!-- 加载中 -->
<view class="blinking-box">
@ -49,28 +49,36 @@
<view class="" v-else>
<view v-if="talkList.length-1==index" class="multiline-text">
<view class="content">
<view class="" v-if="item.type==3"
style="border: 1px solid #2573fb;margin-left: 20rpx;">
<image :src="item.Image" mode="" style="width: 200rpx;height: 200rpx;"
@click="previewImage(item.Image)"></image>
<view class="">{{c_content}}</view>
</view>
<view class="" v-else>
<bing-math v-if="c_content!=''" :key="`math-${item.id}`" class="bing-math1"
:latex="c_content"></bing-math>
<view v-else class="blinking-box">
<image src="@/static/icon/ioc.gif" mode="aspectFit"></image>
<view class="">正在快速生成答案</view>
</view>
</view>
</view>
<view class="contenta" v-if="c_content!=''&&index==nums">
<view class="contenta-img" v-if='palystatus' @click="palyaudio(item,index)">
<view class="contenta-img" v-if='item.playStatus' @click="palyaudio(item,index)">
<image src="@/static/icon/ai7.png" mode="aspectFit"></image>
</view>
<view class="contenta-img" v-else @click="palyaudio(item,index)">
<image src="@/static/icon/ai8.png" mode="aspectFit"></image>
</view>
<view class="contenta-ai" v-show="palystatus==false">
<view class="contenta-ai" v-show="item.playStatus==false">
<image src="@/static/icon/ai.gif" mode="aspectFit"></image>
</view>
<view class="contenta-imga" @tap="copyContent(c_content)"
:style="{'margin-left':palystatus==false?'377rpx' :'427rpx','margin-right': '20rpx'}">
:style="{'margin-left':item.playStatus==false?'377rpx' :'427rpx','margin-right': '20rpx'}">
<image src="@/static/icon/ai10.png" mode="aspectFit"></image>
</view>
<view class="contenta-imga" @click="Share">
@ -78,13 +86,42 @@
</view>
</view>
</view>
<view v-else class="content multiline-text">
<view v-else>
<!-- <rich-text :nodes="item.content"></rich-text> -->
<bing-math :key="`math-${item.id}`" class="bing-math" :latex="item.content"></bing-math>
<view class="" v-if="item.type==3"
style="border: 1px solid #2573fb;margin-left: 20rpx;">
<image :src="item.Image" mode="" style="width: 200rpx;height: 200rpx;"
@click="previewImage(item.Image)"></image>
</view>
<view class="" v-else>
<view class="content multiline-text">
<bing-math :key="`math-${item.id}`" class="bing-math"
:latex="item.content"></bing-math>
</view>
</view>
<view class="contenta" v-if="!item.pic">
<view class="contenta-img" v-if='item.playStatus' @click="palyaudio(item,index)">
<image src="@/static/icon/ai7.png" mode="aspectFit"></image>
</view>
<view class="contenta-img" v-else @click="palyaudio(item,index)">
<image src="@/static/icon/ai8.png" mode="aspectFit"></image>
</view>
<view class="contenta-ai" v-show="item.playStatus==false">
<image src="@/static/icon/ai.gif" mode="aspectFit"></image>
</view>
<view class="contenta-imga" @tap="copyContent(c_content)"
:style="{'margin-left':item.playStatuss==false?'377rpx' :'427rpx','margin-right': '20rpx'}">
<image src="@/static/icon/ai10.png" mode="aspectFit"></image>
</view>
<view class="contenta-imga" @click="Share">
<image src="@/static/icon/ai9.png" mode="aspectFit"></image>
</view>
</view>
</view>
</view>
</view>
</view>
@ -112,7 +149,7 @@
</view>
<view class="flex_c_txt" v-else>
<view class="con" @touchend="end" @touchmove="move" @touchstart="start">
<view class="con" @touchend="end" @touchmove="move" @longpress="start">
{{btnStatus==0? "按住说话":btnStatus==1? "说话中...": btnStatus==2? "松开手指发送录音": "上划取消"}}
</view>
<!-- <view :class=" btnStatus==0? 'footerBtn': btnStatus==1?'footerBtn_star':'footerBtn_move'">
@ -144,7 +181,7 @@
</uni-transition>
<uni-popup ref="popup" :mask-click="false">
<view class="popup_box" @touchend="end" @touchmove="move" @touchstart="start">
<view class="popup_box" @touchend="end" @touchmove="move" @longpress="start">
<view class="move">
<view v-if="btnStatus!==0" :class="btnStatus==3? 'move_center_clear': 'move_center'">
@ -195,6 +232,7 @@
fileToBase64,
dataURLtoBlob,
ttWss,
ttocr
} from "@/api/api.js"
import {
HTTP_REQUEST_URL
@ -213,11 +251,8 @@
import qiqbshare from "@/components/qiqb-share/qiqb-share.vue"
// module
const sr = uni.requireNativePlugin("YL-SpeechRecognition")
const recorderManager = uni.getRecorderManager()
const innerAudioContext = uni.createInnerAudioContext()
export default {
components: {
'bing-math': BingMath,
@ -256,7 +291,6 @@
isshow: true,
shouldScrollToBottom: true,
nums: 0,
palystatus: true, //
recordFlg: true, //
btnStatus: 0, //
audioDuration: "",
@ -282,7 +316,12 @@
},
audio_file: [],
currentIndex: 0,
wv: null
kk: 1,
wv: null,
Imageurl: '',
content1: '',
audioContext: null, // innerAudioContext
}
},
mounted() {
@ -302,21 +341,11 @@
})
})
//
sr.init("2eda6c2e");
//
sr.createTts(code => {});
//
sr.createIat(code => {
console.log(code, '1111111111')
});
sr.setVadBos(10 * 1000); //ms10s,
sr.setVadEos(10 * 1000); //ms10s,
},
beforeDestroy() {
sr.destroy();
},
onLoad() {
let avatar = uni.getStorageSync('avatar');
avatar ? this.avatar = avatar : null;
@ -338,6 +367,23 @@
this.getHistoryMsg();
}
},
created() {
//
// uni.setInnerAudioOption({
// obeyMuteSwitch: false
// })
let that = this;
recorderManager.onStop(function(res) {
// ,
that.$nextTick(() => {
// console.log('recorder stop' + JSON.stringify(res));
that.audioDuration = res.duration;
that.voicePath = res.tempFilePath;
})
});
},
watch: {
n_content(n, o) {
@ -426,27 +472,57 @@
},
//
album() {
let that = this
uni.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['album'], //cameraalbum
success: (res) => {
// const tempFilePaths = res.tempFilePaths;
this.imgfile(res.tempFilePaths)
console.log(res.tempFilePaths, '2222222222')
uni.uploadFile({
url: HTTP_REQUEST_URL + '/api/upload/image', //
filePath: res.tempFilePaths[0], //
name: 'file', // key
header: {
'content-type': 'multipart/form-data'
},
success: function(res) {
let data = {
let data = JSON.parse(res.data)
console.log(data, '222222222222')
if (data.code == 1) {
// this.File()
let data1 = {
"id": '@',
"content": '',
"type": 2,
"pic": this.avatarType
"pic": this.avatar
}
this.talkList.push(data);
that.talkList.push(data1);
that.Imageurl = data.data.uri
that.imgfile(data.data.uri)
}
},
fail: function(error) {
//
that.talkList = that.talkList.filter(item => item.id !== '@');
console.log(error, 11);
}
})
}
});
},
//
camera() {
let that = this
uni.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
@ -454,14 +530,44 @@
success: (res) => {
console.log(res);
// const tempFilePaths = res.tempFilePaths;
this.imgfile(res.tempFilePaths)
let data = {
console.log(res.tempFilePaths)
uni.uploadFile({
url: HTTP_REQUEST_URL + '/api/upload/image', //
filePath: res.tempFilePaths[0], //
name: 'file', // key
header: {
'content-type': 'multipart/form-data'
},
success: function(res) {
let data = JSON.parse(res.data)
console.log(data, data.code)
if (data.code == 1) {
// this.File()
let data1 = {
"id": '@',
"content": '',
"type": 2,
"pic": this.avatarType
"pic": this.avatar
}
this.talkList.push(data);
that.talkList.push(data1);
that.Imageurl = data.data.uri
that.imgfile(data.data.uri)
}
},
fail: function(error) {
//
that.talkList = that.talkList.filter(item => item.id !== '@');
console.log(error, 11);
}
})
// this.imgfile(res.tempFilePaths)
}
});
@ -482,46 +588,93 @@
}
});
},
//
previewImage(url) {
uni.previewImage({
urls: [url], //
current: url, //
success: function() {
console.log('预览图片成功');
},
fail: function(error) {
console.error('预览图片失败', error);
}
});
},
//
imgfile(tempFilePath) {
let that = this
console.log(tempFilePath, '2')
uni.uploadFile({
url: HTTP_REQUEST_URL + '/api/xun_fei/ocr', //
filePath: tempFilePath[0], //
name: 'image', // key
header: {
'content-type': 'multipart/form-data'
},
success: function(res) {
that.content1 = ''
// console.log(tempFilePath, '2')
ttocr({
image: tempFilePath
}).then(res => {
let data = JSON.parse(res.data)
console.log(data)
if (data.code == 1) {
if (res.code == 1) {
uni.showToast({
title: '图片识别成功'
});
console.log(res.data.words)
that.gnishow = false
that.talkList = that.talkList.filter(item => item.id !== '@');
if (data.data.words.length > 0) {
that.content = ''
for (let i in data.data.words) {
that.content = that.content + data.data.words[i]
}
if (res.data.words.length > 0) {
for (let i in res.data.words) {
that.content1 += res.data.words[i]
if (res.data.words.length - 1 == i) {
that.send1()
}
}
}
},
fail: function(error) {
//
}
}).catch((err) => {
that.talkList = that.talkList.filter(item => item.id !== '@');
console.log(error, 11);
}
console.log(err)
})
// uni.uploadFile({
// url: HTTP_REQUEST_URL + '/api/xun_fei/ocr', //
// filePath: tempFilePath, //
// name: 'image', // key
// header: {
// 'content-type': 'multipart/form-data'
// },
// success: function(res) {
// let data = JSON.parse(res.data)
// console.log(data)
// if (data.code == 1) {
// uni.showToast({
// title: ''
// });
// that.talkList = that.talkList.filter(item => item.id !== '@');
// if (data.data.words.length > 0) {
// that.content = ''
// for (let i in data.data.words) {
// that.content = that.content + data.data.words[i]
// }
// that.send1()
// }
// }
// },
// fail: function(error) {
// //
// that.talkList = that.talkList.filter(item => item.id !== '@');
// console.log(error, 11);
// }
// })
},
@ -580,40 +733,51 @@
//
// let arry1;
// if (val.indexOf(',') == -1) {
// arry1 = val.split(',')
// } else if (val.indexOf('') == -1) {
// arry1 = val.split('')
// } else {
// arry1.push(val)
// }
},
//
uploadFile(tempFilePath) {
// const temp = []
// for (let i = 0; i < arry1.length; i++) {
// temp.push(
// // 使Promise
// new Promise((resolve, reject) => {
let that = this
// console.log(tempFilePath)
uni.uploadFile({
url: HTTP_REQUEST_URL + '/api/xun_fei/iat', //
filePath: tempFilePath, //
name: 'audio', // key
header: {
'content-type': 'multipart/form-data'
},
success: function(res) {
// ttWss({
// data: arry1[i]
// }).then(res => {
// return resolve(res.data.mp3)
// }).catch(err => {
// return reject(err)
// })
// })
// )
// }
// Promise.all(temp).then(res => {
// // console.log(res,'2222222')
// this.audio_file = res
let data = JSON.parse(res.data)
if (data.code == 1) {
uni.showToast({
title: '语音识别成功'
});
// this.ScanAudio(res, this.currentIndex, 0)
// })
that.talkList = that.talkList.filter(item => item.id !== '@');
if (data.data.words.length > 0) {
that.content = data.data.words
that.send()
}
} else {
that.talkList = that.talkList.filter(item => item.id !== '@');
uni.showToast({
title: '语音识别失败'
});
}
},
fail: function(error) {
//
that.deletespeech()
console.log(error, 11);
uni.hideLoading();
}
})
},
//
@ -650,89 +814,114 @@
},
//
voiceToText() {
let that = this;
sr.voiceToText(data => {
// console.log(JSON.stringify(data));
if (data.code == 1001) {
// that.toTextStatus = "..."
} else if (data.code == 1006) {
// this.toTextStatus = ""
//
// sr.getIatPath(path => {
// that.path = path;
// });
} else if (data.code == 1007) {
// this.toTextStatus = ""
} else if (data.code == 1008) {
// this.volume = data.msg;
} else if (data.code == 1009) { //
//islast
// this.transText = data.msg;
if (data.isLast) {
if (data.msg.length > 0 && this.risshow == false) {
this.content = data.msg
this.send()
} else {
this.content = ''
this.stopVoiceToText()
}
}
} else if (data.code == 1010) { //error
//data.msg
if (data.msg) {
this.transText = data.msg;
}
}
})
},
//
stopVoiceToText() {
//10071009 ios 1007 1006 1009 1010
sr.stopListening();
},
start(e) {
// console.log(e.touches[0].pageX)
this.onFeedTap()
this.touchT = new Date().getTime();
this.islong = true
this.risshow = false
this.$refs.popup.open('center')
//
this.timer = setInterval(() => {
this.num++
}, 1000)
this.btnStatus = 1
recorderManager.start({
//5,
duration: 300000,
// format: "pcm",
});
this.touchStartX = e.touches[0].pageX; //
this.touchStartY = e.touches[0].pageY; //
clearTimeout(this.timer); //
let that=this
this.timer = setTimeout(function() {
//
// alert("")
that.onFeedTap()
that.islong = true
that.risshow = false
that.$refs.popup.open('center')
that.btnStatus = 1
that.voiceToText()
}.bind(this), 1500);
},
move(e) {
let that = this;
let moveX = this.touchMoveX - e.touches[0].pageX;
let moveY = this.touchMoveY - e.touches[0].pageY;
// console.log(-115 > moveX && -240 < moveX,moveY)
let platform = uni.getSystemInfoSync().platform;
if (platform === 'ios') {
if (-115 > moveX && -240 < moveX && moveY < -620 && moveY > -730) {
this.risshow = true
this.deletespeech()
} else {
this.risshow = false
}
} else {
if (-115 > moveX && -240 < moveX && moveY < -359 && moveY > -480) {
this.risshow = true
this.deletespeech()
} else {
this.risshow = false
}
}
},
end() {
this.touchE = new Date().getTime();
if (this.islong) {
this.closePop()
this.islong = false
clearInterval(this.timer) //
this.btnStatus = 0;
this.stopVoiceToText()
this.num = 0
clearInterval(this.timer)
this.btnStatus = 0
recorderManager.stop();
// this.closePop()
if (this.risshow == false && this.touchE - this.touchT > 3000) {
let data = {
"id": '@',
"content": '加载完毕',
"type": 2,
}
this.talkList.push(data);
// ,,,
setTimeout(() => {
let obj = {
status: false,
path: [{
src: this.voicePath,
switchStatus: false,
soundTime: this.num
}]
}
if (this.voicePath.length > 0 && this.risshow == false) {
// this.huashow=true
this.TabItemTap()
throttle(this.uploadFile(this.voicePath), 1000)
}
this.num = 0
}, 500)
} else {
if (!this.risshow) {
uni.showModal({
title: "录音时长不超过3s"
})
}
}
}
@ -780,10 +969,11 @@
this.maskShow = false
this.isshow = true
},
//
//
palyaudio1(item, i) {
this.palystatus = !this.palystatus
console.log(this.audio_file, '111')
if (!this.palystatus) {
@ -805,24 +995,59 @@
},
//
palyaudio(item, i) {
this.palystatus = !this.palystatus
if (!this.palystatus) {
innerAudioContext.src = item.audio_file;
palyaudio(items, i) {
// console.log(this.talkList,items.audio_file,'000000')
if (this.audioContext) {
//
this.audioContext.stop();
this.audioContext = null;
}
this.talkList.forEach((item, index) => {
if (index != i) {
item.playStatus = true
}
// item.playStatus = (index == i);
});
this.$forceUpdate()
this.talkList[i].playStatus = !this.talkList[i].playStatus
if (!this.talkList[i].playStatus) {
if (items.audio_file.length > 0) {
innerAudioContext.src = items.audio_file;
innerAudioContext.play()
this.talkList[i].playStatus = false
} else {
this.talkList[i].playStatus = true
}
} else {
innerAudioContext.pause()
this.talkList[i].playStatus = true
this.$forceUpdate()
}
innerAudioContext.onError((res) => {
console.log(res.errMsg);
console.log(res.errCode);
this.palystatus = true
this.talkList[i].playStatus = true
this.$forceUpdate()
innerAudioContext.destroy()
});
innerAudioContext.onEnded((res) => {
this.palystatus = true
});
this.talkList[i].playStatus = true
this.$forceUpdate()
});
this.audioContext = innerAudioContext;
this.$forceUpdate()
},
@ -959,8 +1184,11 @@
},
//
closeSocketTask() {
try {
this.talkList = this.talkList.filter(item => item.id !== '@');
clearInterval(this.timer);
this.talkList[this.talkList.length - 1].audio_file = ''
this.talkList[this.talkList.length - 1].content = this.c_content + '';
// console.log(this.talkList[this.talkList.length - 1].content);
// this.c_content = '';
@ -976,36 +1204,10 @@
} catch (e) {
//TODO handle the exception
}
},
move(e) {
let that = this;
let moveX = this.touchMoveX - e.touches[0].pageX;
let moveY = this.touchMoveY - e.touches[0].pageY;
// console.log(-115 > moveX && -240 < moveX,moveY)
let platform = uni.getSystemInfoSync().platform;
if (platform === 'ios') {
if (-115 > moveX && -240 < moveX && moveY < -620 && moveY > -730) {
this.risshow = true
this.deletespeech()
} else {
this.risshow = false
}
} else {
if (-115 > moveX && -240 < moveX && moveY < -359 && moveY > -480) {
this.risshow = true
this.deletespeech()
} else {
this.risshow = false
}
}
},
//
send() {
if (!this.content) {
@ -1015,14 +1217,16 @@
})
return;
}
this.showStop = true;
//
let data = {
"id": new Date().getTime(),
"content": this.content,
'Image': this.Imageurl,
"type": 1,
// "pic": this.avatar
"pic": this.avatarType
"pic": this.avatar
}
// console.log(data);
this.TEXT = this.content;
@ -1030,6 +1234,52 @@
this.talkList.push({
"id": new Date().getTime(),
"content": '',
'Image': '',
"type": 2,
// "pic": this.avatarType
});
this.n_content = '';
this.c_content = '';
this.socketing = true;
// return ;
this.$nextTick(() => {
//
this.content = '';
// uni.pageScrollTo({
// scrollTop: 999999, //
// duration: 0
// });
})
this.sendToSpark();
},
send1() {
if (!this.content1) {
uni.showToast({
title: '请重新上传图片',
icon: 'none'
})
return;
}
this.showStop = true;
//
let data = {
"id": new Date().getTime(),
"content": this.content1,
'Image': this.Imageurl,
"type": 3,
// "pic": this.avatar
"pic": this.avatar
}
// console.log(data);
this.TEXT = this.content1;
this.talkList.push(data);
this.talkList.push({
"id": new Date().getTime(),
"content": '',
'Image': '',
"type": 2,
// "pic": this.avatarType
});
@ -1089,6 +1339,7 @@
// }
// }
// };
if (this.historyTextList.length > 9) this.params = JSON.parse(JSON.stringify(this
.historyTextList
.splice(-9)));
@ -1111,10 +1362,17 @@
let dataArray = obj.payload.choices.text;
for (let i = 0; i < dataArray.length; i++) {
this.talkList[this.talkList.length - 1].content += dataArray[i].content;
this.talkList[this.talkList.length - 1].playStatus = true;
this.n_content = this.talkList[this.talkList.length - 1].content;
realThis.tempRes = realThis.tempRes + dataArray[i].content
}
if (this.n_content.length > 0) {
this.nums = this.talkList.length - 1
this.txtspeech(this.n_content, this.talkList.length -
1)
this.showStop = true;
}
this.cavshare(this.talkList)
let temp = JSON.parse(res.data)
// console.log("0726",temp.header.code)
@ -1138,9 +1396,7 @@
"role": "assistant",
"content": this.tempRes
})
this.nums = this.talkList.length - 1
this.txtspeech(this.n_content, this.talkList.length -
1)
setTimeout(() => {
let that = this
realThis.socketTask.close({
@ -1224,7 +1480,7 @@
page {
// background-color: #f5f5f5;
height: 100vh;
// background: url('@/static/icon/bg1.png') no-repeat;
background: url('@/static/icon/bg1.png') no-repeat;
background-size: 100% 100%;
background-attachment: fixed;
background-repeat: no-repeat;
@ -1341,7 +1597,7 @@
width: 100%;
padding-top: var(--status-bar-height);
padding-bottom: 30rpx;
// background: url('@/static/icon/bg1.png');
background: url('@/static/icon/bg1.png');
background-size: cover;
text-align: center;
background-color: transparent;