This commit is contained in:
jia 2023-10-18 10:59:38 +08:00
parent 2b3f5f2e5e
commit 7e224f3d37
1 changed files with 183 additions and 95 deletions

View File

@ -60,10 +60,10 @@
</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)"> <view class="contenta-img" v-if='palystatus' @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)"> <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="palystatus==false">
@ -184,7 +184,6 @@
</uni-popup> </uni-popup>
<qiqbshare ref="child"></qiqbshare> <qiqbshare ref="child"></qiqbshare>
</view> </view>
</template> </template>
@ -275,7 +274,6 @@
touchMoveX: 0, // x touchMoveX: 0, // x
touchMoveY: 0, // y touchMoveY: 0, // y
risshow: false, risshow: false,
touchT: null, touchT: null,
touchE: null, touchE: null,
islong: false, islong: false,
@ -283,8 +281,10 @@
isDraw: false, isDraw: false,
imageSize: { imageSize: {
} },
audio_file: [],
currentIndex: 0,
wv: null
} }
}, },
mounted() { mounted() {
@ -313,6 +313,9 @@
this.avatar = e.avatar; this.avatar = e.avatar;
}) })
}, },
beforeDestroy() { beforeDestroy() {
// #ifdef APP-PLUS // #ifdef APP-PLUS
@ -340,6 +343,9 @@
}) })
}); });
this.list() this.list()
}, },
watch: { watch: {
@ -630,69 +636,93 @@
} }
// #endif // #endif
}, },
//
voiceBegain() {
let _this = this;
let options = {};
//#ifdef APP-PLUS || APP-PLUS-NVUE
options.engine = 'iFly';
options.punctuation = false; //
options.timeout = 10 * 6000; //
plus.speech.startRecognize(options, function(s) {
_this.searchText = _this.searchText + s;
console.log(_this.searchText) //
//
_this.searchValue = s;
_this.searchText = ""
//
_this.words1 = _this.searchValue
_this.words2 = _this.searchText
//
plus.speech.stopRecognize();
}, function(e){
console.log('语音识别失败:'+JSON.stringify(e));
});
//#endif
// #ifdef H5
alert("只有h5平台才有alert方法")
// #endif
},
// //
txtspeech(val, i) { txtspeech(val, i) {
// xuiat({ xuiat({
// text: val text: val
// }).then(res => {
// if (res.code == 1) {
// this.talkList[i].audio_file = res.data.audio_file
// this.nums = this.talkList.length - 1
// // this.palyaudio(res.data)
// }
// }).catch((err) => {
// console.log(err)
// })
ttWss({
data: val
}).then(res => { }).then(res => {
if (res.code == 0) { if (res.code == 1) {
this.talkList[i].audio_file = res.data.mp3 this.talkList[i].audio_file = res.data.audio_file
this.nums = this.talkList.length - 1
this.nums = this.talkList.length - 1 this.nums = this.talkList.length - 1
// this.palyaudio(res.data)
} }
}).catch((err) => { }).catch((err) => {
console.log(err) console.log(err)
}) })
//
// let arry1;
// if (val.indexOf(',') == -1) {
// arry1 = val.split(',')
// } else if (val.indexOf('') == -1) {
// arry1 = val.split('')
// } else {
// arry1.push(val)
// }
// const temp = []
// for (let i = 0; i < arry1.length; i++) {
// temp.push(
// // 使Promise
// new Promise((resolve, reject) => {
// 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
// this.ScanAudio(res, this.currentIndex, 0)
// })
}, },
//
ScanAudio(urls, currentIndex, delayInSeconds) {
if (currentIndex >= urls.length) {
this.palystatus = true;
return false;
}
const music = uni.createInnerAudioContext();
music.src = urls[currentIndex];
console.log(urls[currentIndex])
console.log('播放成功', this.palystatus)
if (this.palystatus) {
this.palystatus = false
music.play();
} else {
music.pause();
}
music.onEnded(() => {
music.destroy();
setTimeout(() => {
this.ScanAudio(urls, currentIndex + 1, delayInSeconds);
}, delayInSeconds * 1000);
});
},
// //
longclick() { longclick() {
if (this.touchE - this.touchT < 1000) { if (this.touchE - this.touchT < 1000) {
@ -702,7 +732,7 @@
}, },
longpress(e) { longpress(e) {
// console.log(e.touches[0].pageX) // console.log(e.touches[0].pageX)
this.voiceBegain()
this.onFeedTap() this.onFeedTap()
this.touchT = new Date().getTime(); this.touchT = new Date().getTime();
this.islong = true this.islong = true
@ -715,8 +745,22 @@
this.btnStatus = 1 this.btnStatus = 1
recorderManager.start({ recorderManager.start({
//5, //5,
duration: 300000 duration: 300000,
sampleRate: 16000, // 8000/16000/44100
numberOfChannels: 1, // 1/2
encodeBitRate: 96000, //
format: "MP3", // aac/mp3
frameSize: 8, //
// format: "pcm",
}); });
recorderManager.onFrameRecorded((res) => {
console.log(res, '111111111111')
let arr1 = res
uni.sendHostEvent('log', option, (ret) => {
//
console.log('语音分片消息成功' + JSON.stringify(arr1));
});
})
this.touchStartX = e.touches[0].pageX; // this.touchStartX = e.touches[0].pageX; //
this.touchStartY = e.touches[0].pageY; // this.touchStartY = e.touches[0].pageY; //
}, },
@ -729,6 +773,7 @@
end() { end() {
this.touchE = new Date().getTime(); this.touchE = new Date().getTime();
if (this.islong) { if (this.islong) {
this.closePop() this.closePop()
// clearInterval(this.timer1) // clearInterval(this.timer1)
@ -783,7 +828,6 @@
// }, 500) // }, 500)
this.islong = false this.islong = false
clearInterval(this.timer) clearInterval(this.timer)
this.btnStatus = 0 this.btnStatus = 0
@ -795,7 +839,7 @@
"id": '@', "id": '@',
"content": '加载完毕', "content": '加载完毕',
"type": 2, "type": 2,
"pic": this.avatarType
} }
this.talkList.push(data); this.talkList.push(data);
// ,,, // ,,,
@ -812,7 +856,10 @@
if (this.voicePath.length > 0 && this.risshow == false) { if (this.voicePath.length > 0 && this.risshow == false) {
// this.huashow=true // this.huashow=true
this.TabItemTap() this.TabItemTap()
throttle(this.uploadFile(this.voicePath), 1000) throttle(this.uploadFile(this.voicePath), 1000)
} }
this.num = 0 this.num = 0
@ -835,29 +882,32 @@
}, },
toBase64() { toBase64() {
pathToBase64(this.voicePath) pathToBase64(this.voicePath)
.then(base64 => { .then(base64 => {
const arrayBuffer = new Uint8Array(base64)
const base1 = uni.arrayBufferToBase64(arrayBuffer.split(0, 1280)) // this.$scope.$getAppWebview().children()[0].evalJS('uniEvent(base64)');
let params = { // const arrayBuffer = new Uint8Array(base64)
common: { // const base1 = uni.arrayBufferToBase64(arrayBuffer.split(0, 1280))
app_id: '2eda6c2e', // let params = {
}, // common: {
business: { // app_id: '2eda6c2e',
language: "zh_cn", // },
domain: "iat", // business: {
accent: "mandarin", // language: "zh_cn",
vad_eos: 5000, // domain: "iat",
dwa: "wpgs", // accent: "mandarin",
}, // vad_eos: 5000,
data: { // dwa: "wpgs",
status: 2, // },
format: "audio/L16;rate=16000", // data: {
encoding: "raw", // status: 2,
audio: base1 // format: "audio/L16;rate=16000",
}, // encoding: "raw",
}; // audio: base1
this.audioTxt = JSON.stringify(params) // },
// };
// this.audioTxt = JSON.stringify(params)
}) })
.catch(error => { .catch(error => {
@ -908,9 +958,31 @@
}, },
// //
palyaudio(item) { palyaudio1(item, i) {
this.palystatus = !this.palystatus this.palystatus = !this.palystatus
console.log(this.audio_file, '111')
if (!this.palystatus) {
this.ScanAudio(this.audio_file, this.currentIndex, 0)
} else {
this.ScanAudio(this.audio_file, this.currentIndex, 0)
// this.txtspeech(item.content, i)
}
// innerAudioContext.onError((res) => {
// console.log(res.errMsg);
// console.log(res.errCode);
// this.palystatus = true
// });
innerAudioContext.onEnded((res) => {
this.palystatus = true
});
},
//
palyaudio(item, i) {
this.palystatus = !this.palystatus
if (!this.palystatus) { if (!this.palystatus) {
innerAudioContext.src = item.audio_file; innerAudioContext.src = item.audio_file;
innerAudioContext.play() innerAudioContext.play()
@ -1086,6 +1158,19 @@
let that = this; let that = this;
let moveX = this.touchMoveX - e.touches[0].pageX; let moveX = this.touchMoveX - e.touches[0].pageX;
let moveY = this.touchMoveY - e.touches[0].pageY; 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) { if (-115 > moveX && -240 < moveX && moveY < -359 && moveY > -480) {
@ -1095,6 +1180,7 @@
} else { } else {
this.risshow = false this.risshow = false
} }
}
}, },
audiosckt() { audiosckt() {
@ -1212,7 +1298,7 @@
"id": new Date().getTime(), "id": new Date().getTime(),
"content": this.content, "content": this.content,
"type": 1, "type": 1,
"pic": this.avatar "pic": this.avatarType
} }
this.TEXT = this.content, this.TEXT = this.content,
this.talkList.push(data); this.talkList.push(data);
@ -1220,7 +1306,7 @@
"id": new Date().getTime(), "id": new Date().getTime(),
"content": '', "content": '',
"type": 2, "type": 2,
"pic": this.avatarType // "pic": this.avatarType
}); });
this.n_content = ''; this.n_content = '';
this.c_content = ''; this.c_content = '';
@ -1308,15 +1394,16 @@
"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({
success(res) { success(res) {
console.log('关闭成功', res) console.log('关闭成功', res)
that.nums = that.talkList.length - 1
that.txtspeech(that.n_content, that.talkList.length -
1)
realThis.wsLiveFlag = false; realThis.wsLiveFlag = false;
}, },
@ -1346,7 +1433,8 @@
"id": new Date().getTime(), "id": new Date().getTime(),
"content": this.content, "content": this.content,
"type": 1, "type": 1,
"pic": this.avatar // "pic": this.avatar
"pic": this.avatarType
} }
// console.log(data); // console.log(data);
this.TEXT = this.content; this.TEXT = this.content;
@ -1462,15 +1550,15 @@
"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({
success(res) { success(res) {
console.log('关闭成功', res) console.log('关闭成功', res)
that.nums = that.talkList.length - 1
that.txtspeech(that.n_content, that.talkList.length -
1)
realThis.wsLiveFlag = false; realThis.wsLiveFlag = false;
@ -1548,7 +1636,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;
@ -1665,7 +1753,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;