修改语音识别

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() { down() {
uni.showLoading({ uni.showLoading({
title: '保存中' title: '保存中'
}) })
uni.canvasToTempFilePath({
canvasId: 'ctx',
quality: 1,
success: (res) => {
uni.hideLoading()
console.log(res)
this.$emit('down', res)
this.show = false
//
uni.saveImageToPhotosAlbum({ uni.saveImageToPhotosAlbum({
filePath: res.tempFilePath, filePath: this.tempImage,
success: (res) => { success: (res) => {
console.log('保存') console.log('保存')
uni.hideLoading()
this.close()
uni.showModal({ uni.showModal({
title: '保存成功' title: '保存成功'
}) })
} }
}) })
}
})
}, },
// //
drawBg(ctx, w, h, r, color) { drawBg(ctx, w, h, r, color) {

View File

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

View File

@ -6,7 +6,7 @@
<view class="" style="position: absolute;left: 30rpx;"><i class="iconfont icon-xiangzuo" <view class="" style="position: absolute;left: 30rpx;"><i class="iconfont icon-xiangzuo"
style="font-size: 40rpx;text-align: left;"></i></view> style="font-size: 40rpx;text-align: left;"></i></view>
<view class="" style="font-size: 30rpx;"> <view class="" style="font-size: 30rpx;">
农业咨询 情感咨询
</view> </view>
</view> </view>
<view style="padding-top:var(--status-bar-height);padding-bottom: 30rpx; margin-bottom: 30rpx;"></view> <view style="padding-top:var(--status-bar-height);padding-bottom: 30rpx; margin-bottom: 30rpx;"></view>
@ -36,9 +36,9 @@
</view> </view>
<view v-for="(item,index) in talkList" :key="index" :id="`msg-${item.id}`"> <view v-for="(item,index) in talkList" :key="index" :id="`msg-${item.id}`">
<view class="item flex_col" :class="item.type == 1 ? 'push':'pull' "> <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 :src="item.type==1?avatar:item.pic" mode="aspectFill" class="pic" v-if="item.pic">
</image> </image>
<view class="content" v-if="item.id=='@'"> <view class="content" v-if="item.id=='@'">
<!-- 加载中 --> <!-- 加载中 -->
<view class="blinking-box"> <view class="blinking-box">
@ -49,28 +49,36 @@
<view class="" v-else> <view class="" v-else>
<view v-if="talkList.length-1==index" class="multiline-text"> <view v-if="talkList.length-1==index" class="multiline-text">
<view class="content"> <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" <bing-math v-if="c_content!=''" :key="`math-${item.id}`" class="bing-math1"
:latex="c_content"></bing-math> :latex="c_content"></bing-math>
<view v-else class="blinking-box"> <view v-else class="blinking-box">
<image src="@/static/icon/ioc.gif" mode="aspectFit"></image> <image src="@/static/icon/ioc.gif" mode="aspectFit"></image>
<view class="">正在快速生成答案</view> <view class="">正在快速生成答案</view>
</view> </view>
</view> </view>
</view>
<view class="contenta" v-if="c_content!=''&&index==nums"> <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> <image src="@/static/icon/ai7.png" mode="aspectFit"></image>
</view> </view>
<view class="contenta-img" v-else @click="palyaudio(item,index)"> <view class="contenta-img" v-else @click="palyaudio(item,index)">
<image src="@/static/icon/ai8.png" mode="aspectFit"></image> <image src="@/static/icon/ai8.png" mode="aspectFit"></image>
</view> </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> <image src="@/static/icon/ai.gif" mode="aspectFit"></image>
</view> </view>
<view class="contenta-imga" @tap="copyContent(c_content)" <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> <image src="@/static/icon/ai10.png" mode="aspectFit"></image>
</view> </view>
<view class="contenta-imga" @click="Share"> <view class="contenta-imga" @click="Share">
@ -78,13 +86,42 @@
</view> </view>
</view> </view>
</view> </view>
<view v-else class="content multiline-text">
<view v-else>
<!-- <rich-text :nodes="item.content"></rich-text> --> <!-- <rich-text :nodes="item.content"></rich-text> -->
<view class="" v-if="item.type==3"
<bing-math :key="`math-${item.id}`" class="bing-math" :latex="item.content"></bing-math> 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>
</view> </view>
</view> </view>
@ -112,7 +149,7 @@
</view> </view>
<view class="flex_c_txt" v-else> <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? "松开手指发送录音": "上划取消"}} {{btnStatus==0? "按住说话":btnStatus==1? "说话中...": btnStatus==2? "松开手指发送录音": "上划取消"}}
</view> </view>
<!-- <view :class=" btnStatus==0? 'footerBtn': btnStatus==1?'footerBtn_star':'footerBtn_move'"> <!-- <view :class=" btnStatus==0? 'footerBtn': btnStatus==1?'footerBtn_star':'footerBtn_move'">
@ -144,7 +181,7 @@
</uni-transition> </uni-transition>
<uni-popup ref="popup" :mask-click="false"> <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 class="move">
<view v-if="btnStatus!==0" :class="btnStatus==3? 'move_center_clear': 'move_center'"> <view v-if="btnStatus!==0" :class="btnStatus==3? 'move_center_clear': 'move_center'">
@ -195,6 +232,7 @@
fileToBase64, fileToBase64,
dataURLtoBlob, dataURLtoBlob,
ttWss, ttWss,
ttocr
} from "@/api/api.js" } from "@/api/api.js"
import { import {
HTTP_REQUEST_URL HTTP_REQUEST_URL
@ -213,11 +251,8 @@
import qiqbshare from "@/components/qiqb-share/qiqb-share.vue" import qiqbshare from "@/components/qiqb-share/qiqb-share.vue"
const recorderManager = uni.getRecorderManager()
// module
const sr = uni.requireNativePlugin("YL-SpeechRecognition")
const innerAudioContext = uni.createInnerAudioContext() const innerAudioContext = uni.createInnerAudioContext()
export default { export default {
components: { components: {
'bing-math': BingMath, 'bing-math': BingMath,
@ -256,7 +291,6 @@
isshow: true, isshow: true,
shouldScrollToBottom: true, shouldScrollToBottom: true,
nums: 0, nums: 0,
palystatus: true, //
recordFlg: true, // recordFlg: true, //
btnStatus: 0, // btnStatus: 0, //
audioDuration: "", audioDuration: "",
@ -282,7 +316,12 @@
}, },
audio_file: [], audio_file: [],
currentIndex: 0, currentIndex: 0,
wv: null kk: 1,
wv: null,
Imageurl: '',
content1: '',
audioContext: null, // innerAudioContext
} }
}, },
mounted() { 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() { onLoad() {
let avatar = uni.getStorageSync('avatar'); let avatar = uni.getStorageSync('avatar');
avatar ? this.avatar = avatar : null; avatar ? this.avatar = avatar : null;
@ -338,6 +367,23 @@
this.getHistoryMsg(); 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: { watch: {
n_content(n, o) { n_content(n, o) {
@ -426,27 +472,57 @@
}, },
// //
album() { album() {
let that = this
uni.chooseImage({ uni.chooseImage({
count: 1, count: 1,
sizeType: ['original', 'compressed'], sizeType: ['original', 'compressed'],
sourceType: ['album'], //cameraalbum sourceType: ['album'], //cameraalbum
success: (res) => { success: (res) => {
// const tempFilePaths = res.tempFilePaths; // 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": '@', "id": '@',
"content": '', "content": '',
"type": 2, "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() { camera() {
let that = this
uni.chooseImage({ uni.chooseImage({
count: 1, count: 1,
sizeType: ['original', 'compressed'], sizeType: ['original', 'compressed'],
@ -454,14 +530,44 @@
success: (res) => { success: (res) => {
console.log(res); console.log(res);
// const tempFilePaths = res.tempFilePaths; // const tempFilePaths = res.tempFilePaths;
this.imgfile(res.tempFilePaths) console.log(res.tempFilePaths)
let data = { 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": '@', "id": '@',
"content": '', "content": '',
"type": 2, "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) { imgfile(tempFilePath) {
let that = this let that = this
console.log(tempFilePath, '2') that.content1 = ''
uni.uploadFile({ // console.log(tempFilePath, '2')
url: HTTP_REQUEST_URL + '/api/xun_fei/ocr', // ttocr({
filePath: tempFilePath[0], // image: tempFilePath
name: 'image', // key }).then(res => {
header: {
'content-type': 'multipart/form-data'
},
success: function(res) {
let data = JSON.parse(res.data) if (res.code == 1) {
console.log(data)
if (data.code == 1) {
uni.showToast({ uni.showToast({
title: '图片识别成功' title: '图片识别成功'
}); });
console.log(res.data.words)
that.gnishow = false
that.talkList = that.talkList.filter(item => item.id !== '@'); that.talkList = that.talkList.filter(item => item.id !== '@');
if (data.data.words.length > 0) {
that.content = '' if (res.data.words.length > 0) {
for (let i in data.data.words) {
that.content = that.content + data.data.words[i] for (let i in res.data.words) {
} that.content1 += res.data.words[i]
if (res.data.words.length - 1 == i) {
that.send1() that.send1()
} }
}
} }
},
fail: function(error) { }
//
}).catch((err) => {
that.talkList = that.talkList.filter(item => item.id !== '@'); 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) { uploadFile(tempFilePath) {
// arry1 = val.split(',')
// } else if (val.indexOf('') == -1) {
// arry1 = val.split('')
// } else {
// arry1.push(val)
// }
// const temp = [] let that = this
// for (let i = 0; i < arry1.length; i++) { // console.log(tempFilePath)
// temp.push( uni.uploadFile({
// // 使Promise url: HTTP_REQUEST_URL + '/api/xun_fei/iat', //
// new Promise((resolve, reject) => { 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) let data = JSON.parse(res.data)
// }).catch(err => { if (data.code == 1) {
// return reject(err) uni.showToast({
// }) title: '语音识别成功'
// }) });
// )
// }
// Promise.all(temp).then(res => {
// // console.log(res,'2222222')
// this.audio_file = res
// 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) { 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.touchStartX = e.touches[0].pageX; //
this.touchStartY = e.touches[0].pageY; // 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() { end() {
this.touchE = new Date().getTime();
if (this.islong) { if (this.islong) {
this.closePop() this.closePop()
this.islong = false this.islong = false
clearInterval(this.timer) // clearInterval(this.timer)
this.btnStatus = 0; this.btnStatus = 0
this.stopVoiceToText() recorderManager.stop();
this.num = 0
// 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.maskShow = false
this.isshow = true this.isshow = true
}, },
// //
palyaudio1(item, i) { palyaudio1(item, i) {
this.palystatus = !this.palystatus
console.log(this.audio_file, '111') console.log(this.audio_file, '111')
if (!this.palystatus) { if (!this.palystatus) {
@ -805,24 +995,59 @@
}, },
// //
palyaudio(item, i) { palyaudio(items, i) {
this.palystatus = !this.palystatus
if (!this.palystatus) { // console.log(this.talkList,items.audio_file,'000000')
innerAudioContext.src = item.audio_file; 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() innerAudioContext.play()
this.talkList[i].playStatus = false
} else {
this.talkList[i].playStatus = true
}
} else { } else {
innerAudioContext.pause() innerAudioContext.pause()
this.talkList[i].playStatus = true
this.$forceUpdate()
} }
innerAudioContext.onError((res) => { innerAudioContext.onError((res) => {
console.log(res.errMsg); console.log(res.errMsg);
console.log(res.errCode); console.log(res.errCode);
this.palystatus = true this.talkList[i].playStatus = true
this.$forceUpdate()
innerAudioContext.destroy()
}); });
innerAudioContext.onEnded((res) => { innerAudioContext.onEnded((res) => {
this.palystatus = true
});
this.talkList[i].playStatus = true
this.$forceUpdate()
});
this.audioContext = innerAudioContext;
this.$forceUpdate()
}, },
@ -959,8 +1184,11 @@
}, },
// //
closeSocketTask() { closeSocketTask() {
try { try {
this.talkList = this.talkList.filter(item => item.id !== '@');
clearInterval(this.timer); clearInterval(this.timer);
this.talkList[this.talkList.length - 1].audio_file = ''
this.talkList[this.talkList.length - 1].content = this.c_content + ''; this.talkList[this.talkList.length - 1].content = this.c_content + '';
// console.log(this.talkList[this.talkList.length - 1].content); // console.log(this.talkList[this.talkList.length - 1].content);
// this.c_content = ''; // this.c_content = '';
@ -976,36 +1204,10 @@
} catch (e) { } catch (e) {
//TODO handle the exception //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() { send() {
if (!this.content) { if (!this.content) {
@ -1015,14 +1217,16 @@
}) })
return; return;
} }
this.showStop = true;
// //
let data = { let data = {
"id": new Date().getTime(), "id": new Date().getTime(),
"content": this.content, "content": this.content,
'Image': this.Imageurl,
"type": 1, "type": 1,
// "pic": this.avatar // "pic": this.avatar
"pic": this.avatarType "pic": this.avatar
} }
// console.log(data); // console.log(data);
this.TEXT = this.content; this.TEXT = this.content;
@ -1030,6 +1234,52 @@
this.talkList.push({ this.talkList.push({
"id": new Date().getTime(), "id": new Date().getTime(),
"content": '', "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, "type": 2,
// "pic": this.avatarType // "pic": this.avatarType
}); });
@ -1089,6 +1339,7 @@
// } // }
// } // }
// }; // };
if (this.historyTextList.length > 9) this.params = JSON.parse(JSON.stringify(this if (this.historyTextList.length > 9) this.params = JSON.parse(JSON.stringify(this
.historyTextList .historyTextList
.splice(-9))); .splice(-9)));
@ -1111,10 +1362,17 @@
let dataArray = obj.payload.choices.text; let dataArray = obj.payload.choices.text;
for (let i = 0; i < dataArray.length; i++) { for (let i = 0; i < dataArray.length; i++) {
this.talkList[this.talkList.length - 1].content += dataArray[i].content; 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; this.n_content = this.talkList[this.talkList.length - 1].content;
realThis.tempRes = realThis.tempRes + dataArray[i].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) this.cavshare(this.talkList)
let temp = JSON.parse(res.data) let temp = JSON.parse(res.data)
// console.log("0726",temp.header.code) // console.log("0726",temp.header.code)
@ -1138,9 +1396,7 @@
"role": "assistant", "role": "assistant",
"content": this.tempRes "content": this.tempRes
}) })
this.nums = this.talkList.length - 1
this.txtspeech(this.n_content, this.talkList.length -
1)
setTimeout(() => { setTimeout(() => {
let that = this let that = this
realThis.socketTask.close({ realThis.socketTask.close({
@ -1224,7 +1480,7 @@
page { page {
// background-color: #f5f5f5; // background-color: #f5f5f5;
height: 100vh; height: 100vh;
// background: url('@/static/icon/bg1.png') no-repeat; background: url('@/static/icon/bg1.png') no-repeat;
background-size: 100% 100%; background-size: 100% 100%;
background-attachment: fixed; background-attachment: fixed;
background-repeat: no-repeat; background-repeat: no-repeat;
@ -1341,7 +1597,7 @@
width: 100%; width: 100%;
padding-top: var(--status-bar-height); padding-top: var(--status-bar-height);
padding-bottom: 30rpx; padding-bottom: 30rpx;
// background: url('@/static/icon/bg1.png'); background: url('@/static/icon/bg1.png');
background-size: cover; background-size: cover;
text-align: center; text-align: center;
background-color: transparent; background-color: transparent;