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 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>
</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>
</view>
<view class="contenta-ai" v-show="palystatus==false">
@ -184,7 +184,6 @@
</uni-popup>
<qiqbshare ref="child"></qiqbshare>
</view>
</template>
@ -275,7 +274,6 @@
touchMoveX: 0, // x
touchMoveY: 0, // y
risshow: false,
touchT: null,
touchE: null,
islong: false,
@ -283,8 +281,10 @@
isDraw: false,
imageSize: {
}
},
audio_file: [],
currentIndex: 0,
wv: null
}
},
mounted() {
@ -313,6 +313,9 @@
this.avatar = e.avatar;
})
},
beforeDestroy() {
// #ifdef APP-PLUS
@ -340,6 +343,9 @@
})
});
this.list()
},
watch: {
@ -630,69 +636,93 @@
}
// #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) {
// xuiat({
// 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
xuiat({
text: val
}).then(res => {
if (res.code == 0) {
this.talkList[i].audio_file = res.data.mp3
this.nums = this.talkList.length - 1
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)
})
//
// 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() {
if (this.touchE - this.touchT < 1000) {
@ -702,7 +732,7 @@
},
longpress(e) {
// console.log(e.touches[0].pageX)
this.voiceBegain()
this.onFeedTap()
this.touchT = new Date().getTime();
this.islong = true
@ -715,8 +745,22 @@
this.btnStatus = 1
recorderManager.start({
//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.touchStartY = e.touches[0].pageY; //
},
@ -729,6 +773,7 @@
end() {
this.touchE = new Date().getTime();
if (this.islong) {
this.closePop()
// clearInterval(this.timer1)
@ -783,7 +828,6 @@
// }, 500)
this.islong = false
clearInterval(this.timer)
this.btnStatus = 0
@ -795,7 +839,7 @@
"id": '@',
"content": '加载完毕',
"type": 2,
"pic": this.avatarType
}
this.talkList.push(data);
// ,,,
@ -812,7 +856,10 @@
if (this.voicePath.length > 0 && this.risshow == false) {
// this.huashow=true
this.TabItemTap()
throttle(this.uploadFile(this.voicePath), 1000)
}
this.num = 0
@ -835,29 +882,32 @@
},
toBase64() {
pathToBase64(this.voicePath)
.then(base64 => {
const arrayBuffer = new Uint8Array(base64)
const base1 = uni.arrayBufferToBase64(arrayBuffer.split(0, 1280))
let params = {
common: {
app_id: '2eda6c2e',
},
business: {
language: "zh_cn",
domain: "iat",
accent: "mandarin",
vad_eos: 5000,
dwa: "wpgs",
},
data: {
status: 2,
format: "audio/L16;rate=16000",
encoding: "raw",
audio: base1
},
};
this.audioTxt = JSON.stringify(params)
// this.$scope.$getAppWebview().children()[0].evalJS('uniEvent(base64)');
// const arrayBuffer = new Uint8Array(base64)
// const base1 = uni.arrayBufferToBase64(arrayBuffer.split(0, 1280))
// let params = {
// common: {
// app_id: '2eda6c2e',
// },
// business: {
// language: "zh_cn",
// domain: "iat",
// accent: "mandarin",
// vad_eos: 5000,
// dwa: "wpgs",
// },
// data: {
// status: 2,
// format: "audio/L16;rate=16000",
// encoding: "raw",
// audio: base1
// },
// };
// this.audioTxt = JSON.stringify(params)
})
.catch(error => {
@ -908,9 +958,31 @@
},
//
palyaudio(item) {
palyaudio1(item, i) {
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) {
innerAudioContext.src = item.audio_file;
innerAudioContext.play()
@ -1086,6 +1158,19 @@
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) {
@ -1095,6 +1180,7 @@
} else {
this.risshow = false
}
}
},
audiosckt() {
@ -1212,7 +1298,7 @@
"id": new Date().getTime(),
"content": this.content,
"type": 1,
"pic": this.avatar
"pic": this.avatarType
}
this.TEXT = this.content,
this.talkList.push(data);
@ -1220,7 +1306,7 @@
"id": new Date().getTime(),
"content": '',
"type": 2,
"pic": this.avatarType
// "pic": this.avatarType
});
this.n_content = '';
this.c_content = '';
@ -1308,15 +1394,16 @@
"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({
success(res) {
console.log('关闭成功', res)
that.nums = that.talkList.length - 1
that.txtspeech(that.n_content, that.talkList.length -
1)
realThis.wsLiveFlag = false;
},
@ -1346,7 +1433,8 @@
"id": new Date().getTime(),
"content": this.content,
"type": 1,
"pic": this.avatar
// "pic": this.avatar
"pic": this.avatarType
}
// console.log(data);
this.TEXT = this.content;
@ -1462,15 +1550,15 @@
"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({
success(res) {
console.log('关闭成功', res)
that.nums = that.talkList.length - 1
that.txtspeech(that.n_content, that.talkList.length -
1)
realThis.wsLiveFlag = false;
@ -1548,7 +1636,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;
@ -1665,7 +1753,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;