Commit 2761564e by 前端

fixed

1 parent dcc26ca3
...@@ -61,6 +61,16 @@ Page({ ...@@ -61,6 +61,16 @@ Page({
if(list.length == 0) { if(list.length == 0) {
return this.back() return this.back()
} }
let isJump = true;
list.forEach(i=>{
if(i.role == 2) {
isJump = false
}
})
if(isJump) {
wx.$util.showToast('你还未说话')
return
}
const chatList = JSON.stringify(audioBox.data.list); const chatList = JSON.stringify(audioBox.data.list);
wx.setStorageSync("chatList", chatList) wx.setStorageSync("chatList", chatList)
const { const {
...@@ -126,8 +136,8 @@ Page({ ...@@ -126,8 +136,8 @@ Page({
step: 'defense', step: 'defense',
showScenePopup: false, showScenePopup: false,
main_point, main_point,
roleInspiration: attackScript[index].sale_message, roleInspiration: attackScript[index].sale_message.replace(/,/g,',').replace(/。/g,'。'),
inspirationContent: attackScript[index].sale_message inspirationContent: attackScript[index].sale_message.replace(/,/g,',').replace(/。/g,'。')
}) })
}, },
// 保存场景回调 // 保存场景回调
...@@ -463,7 +473,7 @@ Page({ ...@@ -463,7 +473,7 @@ Page({
const list = JSON.parse(attackScript); const list = JSON.parse(attackScript);
const scriptList = list.map(i => { const scriptList = list.map(i => {
return { return {
content: i.attack_message content: i.attack_message.replace(/,/g,',').replace(/。/g,'。')
} }
}) })
this.setData({ this.setData({
......
...@@ -7,7 +7,6 @@ const SpeechSynthesizer = require("~/utils/aliyun/tts") ...@@ -7,7 +7,6 @@ const SpeechSynthesizer = require("~/utils/aliyun/tts")
const sleep = require("~/utils/aliyun/util").sleep const sleep = require("~/utils/aliyun/util").sleep
const formatTime = require("~/utils/aliyun/util").formatTime const formatTime = require("~/utils/aliyun/util").formatTime
const fs = wx.getFileSystemManager() const fs = wx.getFileSystemManager()
let ctx = wx.createInnerAudioContext()
let timer = null let timer = null
Component({ Component({
...@@ -21,18 +20,17 @@ Component({ ...@@ -21,18 +20,17 @@ Component({
type: Boolean, type: Boolean,
observer: function (n) { observer: function (n) {
if (n) { if (n) {
timer = setInterval(()=>{ timer = setInterval(() => {
this.stopAudio() this.stopAudio()
},300) }, 300)
this.stopAudio() this.stopAudio()
const { const {
list list
} = this.data; } = this.data;
this.setData({ this.setData({
list, list
audioIndex:''
}) })
}else { } else {
clearInterval(timer) clearInterval(timer)
} }
} }
...@@ -43,7 +41,7 @@ Component({ ...@@ -43,7 +41,7 @@ Component({
* 组件的初始数据 * 组件的初始数据
*/ */
data: { data: {
status:'end', status: 'end',
list: [], list: [],
audioIndex: '', audioIndex: '',
ttsStart: false, ttsStart: false,
...@@ -105,12 +103,8 @@ Component({ ...@@ -105,12 +103,8 @@ Component({
fs.close({ fs.close({
fd: this.data.saveFd, fd: this.data.saveFd,
success: (res) => { success: (res) => {
this.setAudio(this.data.selectIndex,this.data.saveFile,'ai') this.setAudio(this.data.selectIndex, this.data.saveFile, 'ai')
ctx.onError((res) => { // this.data.ctx.onEnded((res) => {
console.log(res.errMsg)
console.log(res.errCode)
})
// ctx.onEnded((res) => {
// const { // const {
// list, // list,
// selectIndex // selectIndex
...@@ -155,79 +149,75 @@ Component({ ...@@ -155,79 +149,75 @@ Component({
const curPage = pages[pages.length - 1]; const curPage = pages[pages.length - 1];
curPage.toBottom() curPage.toBottom()
}, },
setAudio(index,filePath,type) { setAudio(index, filePath, type) {
ctx = wx.createInnerAudioContext() if(!this.data['ctx_'+index])
this.data['ctx_'+index] = wx.createInnerAudioContext()
const { const {
list, list,
audioIndex, audioIndex,
status status
} = this.data; } = this.data;
if(type) { if (type) {
list[index].filePath = filePath; const idx = list.findIndex(i=>i.id == index)
list[idx].filePath = filePath;
this.setData({list})
this.toBottom() this.toBottom()
} }
console.log(index,audioIndex,status) console.log(index, audioIndex, status)
// if (index === audioIndex && status == 'start') { this.data['ctx_'+index].src = filePath; // 替换为你的音频文件路径
// ctx.pause();
// }
// if (index === audioIndex && status == 'pause') {
// ctx.play();
// return
// }
this.setData({
list,
audioIndex:index
})
ctx.src = filePath; // 替换为你的音频文件路径
// 监听播放完成事件 // 监听播放完成事件
const _this = this; const _this = this;
ctx.onEnded(() => { this.data['ctx_'+index].onEnded(() => {
console.log('结束...')
const pages = getCurrentPages()
const curPage = pages[pages.length - 1];
curPage.toBottom()
_this.setData({ _this.setData({
audioIndex: null status: 'ending'
}) })
// fs.unlink({ console.log('结束...')
// filePath: _this.data.saveFile,
// success: (res) => {
// console.log(`remove ${_this.data.saveFile} done`)
// _this.data.saveFile = null
// _this.data.saveFd = null
// },
// failed: (res) => {
// console.log("remove failed:" + res.errMsg)
// }
// })
}); });
ctx.play(); this.data['ctx_'+index].onPause(() => {
this.setData({
status: 'pause'
})
console.log('暂停...')
})
if (index === audioIndex && status == 'start') {
this.data['ctx_'+index].pause()
return
}
if (index === audioIndex && status == 'pause') {
this.data['ctx_'+index].play()
return
}
this.stopAudio()
this.setData({
audioIndex: index
})
this.data['ctx_'+index].play();
// 开始播放音频 // 开始播放音频
ctx.onPlay(() => { this.data['ctx_'+index].onPlay(() => {
this.setData({status:'start'}) this.setData({
console.log('开始...') status: 'start'
}) })
ctx.onPause(() => { console.log('开始...')
this.setData({status:'pause'})
console.log('暂停...')
}) })
}, },
//结束播放 //结束播放
stopAudio() { stopAudio() {
ctx = wx.createInnerAudioContext() const {audioIndex} = this.data
ctx.stop() if(this.data['ctx_'+audioIndex])
this.data['ctx_'+audioIndex].stop()
}, },
//自己声音播放 //自己声音播放
playVoice: wx.$util.throttle(function (e) { playVoice: wx.$util.throttle(function (e) {
this.stopAudio()
const { const {
index, id,
file: filePath // 获取语音文件的路径或URL file: filePath // 获取语音文件的路径或URL
} = e.currentTarget.dataset } = e.currentTarget.dataset
this.setAudio(index,filePath) this.setAudio(id, filePath)
}, 1500), }, 1000),
addList(val, isPlay) { addList(val, isPlay) {
val.id = new Date().getTime()
let { let {
list list
} = this.data; } = this.data;
...@@ -242,7 +232,7 @@ Component({ ...@@ -242,7 +232,7 @@ Component({
list = [...list, val] list = [...list, val]
this.setData({ this.setData({
list list
},()=>{ }, () => {
this.toBottom() this.toBottom()
}) })
if (val.role == 2) { if (val.role == 2) {
...@@ -252,7 +242,7 @@ Component({ ...@@ -252,7 +242,7 @@ Component({
} }
if (isPlay) { if (isPlay) {
this.stopAudio() this.stopAudio()
this.playAudio(list.length - 1) this.playAudio(val.id)
} }
}, },
getList(step, defenseIndex) { getList(step, defenseIndex) {
...@@ -277,6 +267,10 @@ Component({ ...@@ -277,6 +267,10 @@ Component({
const { const {
list list
} = this.data; } = this.data;
if(!list[list.length-1].content) {
wx.$util.showToast('AI还未回复')
return
}
list.pop(); list.pop();
list.pop(); list.pop();
this.setData({ this.setData({
...@@ -299,10 +293,11 @@ Component({ ...@@ -299,10 +293,11 @@ Component({
} }
this.setData({ this.setData({
list list
},()=>{ }, () => {
this.toBottom() this.toBottom()
}) })
if (!index) this.playAudio(len) console.log(list,len)
if (!index) this.playAudio(list[len].id)
}, },
handleHidden(e) { handleHidden(e) {
const { const {
...@@ -333,7 +328,7 @@ Component({ ...@@ -333,7 +328,7 @@ Component({
console.log(33) console.log(33)
let index = e.currentTarget ? e.currentTarget.dataset.index : e let index = e.currentTarget ? e.currentTarget.dataset.index : e
this.onTtsStart(index) this.onTtsStart(index)
}, 1500), }, 1000),
async onTtsStart(index) { async onTtsStart(index) {
const { const {
list, list,
...@@ -354,12 +349,14 @@ Component({ ...@@ -354,12 +349,14 @@ Component({
this.data.saveFd = res.fd this.data.saveFd = res.fd
this.data.saveFile = savePath this.data.saveFile = savePath
let param = this.data.tts.defaultStartParams() let param = this.data.tts.defaultStartParams()
param.text = list[index].content; const idx = list.findIndex(i=>i.id == index)
param.text = list[idx].content;
param.voice = this.data.sex == 1 ? "aishuo" : "aixia" param.voice = this.data.sex == 1 ? "aishuo" : "aixia"
try { try {
await this.data.tts.start(param) await this.data.tts.start(param)
this.setData({ this.setData({
list,audioIndex:index list,
audioIndex: idx
}) })
console.log("tts done") console.log("tts done")
this.data.ttsStart = false this.data.ttsStart = false
......
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
<view class="chat-box"> <view class="chat-box">
<!-- <audio-tts id="audio_{{index}}" audioInfo="{{item}}"></audio-tts> --> <!-- <audio-tts id="audio_{{index}}" audioInfo="{{item}}"></audio-tts> -->
<view class="audio-box" wx:if="{{item.filePath}}"> <view class="audio-box" wx:if="{{item.filePath}}">
<view class="audio-left" data-file="{{item.filePath}}" data-index="{{index}}" bindtap="playVoice"> <view class="audio-left" data-file="{{item.filePath}}" data-id="{{item.id}}" bindtap="playVoice">
<view class="wifi-symbol"> <view class="wifi-symbol">
<gl-image class="icon" wx:if="{{audioIndex === index}}" src="/aiCheck/audio_b.gif"></gl-image> <gl-image class="icon" wx:if="{{audioIndex === item.id && status == 'start'}}" src="/aiCheck/audio_b.gif"></gl-image>
<gl-image class="icon" wx:else src="/aiCheck/audio_b.png"></gl-image> <gl-image class="icon" wx:else src="/aiCheck/audio_b.png"></gl-image>
</view> </view>
<text>{{item.times}}"</text> <text>{{item.times}}"</text>
...@@ -18,15 +18,15 @@ ...@@ -18,15 +18,15 @@
<view class="second loadding"></view> <view class="second loadding"></view>
<view class="third loadding"></view> <view class="third loadding"></view>
</view> </view>
<view class="content-box" wx:if="{{item.filePath}}">{{item.content}}</view> <view class="content-box" wx:if="{{item.content}}">{{item.content}}</view>
</view> </view>
</view> </view>
<view class="chat-right" wx:if="{{item.role == 2}}"> <view class="chat-right" wx:if="{{item.role == 2}}">
<view class="chat-box"> <view class="chat-box">
<view class="audio-right" data-file="{{item.filePath}}" data-index="{{index}}" bindtap="playVoice"> <view class="audio-right" data-file="{{item.filePath}}" data-id="{{item.id}}" bindtap="playVoice">
<text>{{item.times}}"</text> <text>{{item.times}}"</text>
<view class="wifi-symbol"> <view class="wifi-symbol">
<gl-image class="icon" wx:if="{{audioIndex === index}}" src="/aiCheck/audio_w.gif"></gl-image> <gl-image class="icon" wx:if="{{audioIndex === item.id && status == 'start'}}" src="/aiCheck/audio_w.gif"></gl-image>
<gl-image class="icon" wx:else src="/aiCheck/audio_w.png"></gl-image> <gl-image class="icon" wx:else src="/aiCheck/audio_w.png"></gl-image>
</view> </view>
</view> </view>
......
...@@ -57,6 +57,7 @@ Component({ ...@@ -57,6 +57,7 @@ Component({
times:0 times:0
}) })
clearInterval(timer) clearInterval(timer)
timer = null
}, },
onSrStop: async function () { onSrStop: async function () {
console.log('onSrStop') console.log('onSrStop')
...@@ -201,7 +202,7 @@ Component({ ...@@ -201,7 +202,7 @@ Component({
onStart() { onStart() {
this.onSrStart() this.onSrStart()
}, },
onReset() { onReset: wx.$util.throttle(function (e) {
this.setData({ this.setData({
isClose: true isClose: true
}, () => { }, () => {
...@@ -216,7 +217,7 @@ Component({ ...@@ -216,7 +217,7 @@ Component({
}) })
},300) },300)
}, },1500),
onClose() { onClose() {
this.setData({ this.setData({
isClose: true isClose: true
......
...@@ -119,7 +119,7 @@ Page({ ...@@ -119,7 +119,7 @@ Page({
uuid uuid
} = wx.$util.getUserInfo(); } = wx.$util.getUserInfo();
if (history_message) { if (history_message) {
this.handleSave(chatList,'',uuid,batch_id) this.handleSave(chatList,'',uuid,batch_id,roleType)
wx.showLoading({ wx.showLoading({
title: '加载中', title: '加载中',
}) })
...@@ -189,13 +189,13 @@ Page({ ...@@ -189,13 +189,13 @@ Page({
}) })
}, },
handleSave(list, result, uuid, batchId) { handleSave(list, result, uuid, batchId,roleType) {
const sparringContent = JSON.stringify(list) const sparringContent = JSON.stringify(list)
const checkResult = JSON.stringify(result) const checkResult = JSON.stringify(result)
aiApi.setSparringSave({ aiApi.setSparringSave({
staffUuid: uuid, staffUuid: uuid,
batchId, batchId,
roleType: 1, roleType,
sparringContent, sparringContent,
checkResult checkResult
}).then(res => { }).then(res => {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!