Commit 1c8f0d7d by 前端

Merge branch 'AI_V1.0.0' of http://192.168.3.233:8090/saas_plus/dj-car-boutique-…

…work-wechat into AI_V1.0.0
2 parents ae63df22 19c26a25
...@@ -72,9 +72,12 @@ Page({ ...@@ -72,9 +72,12 @@ Page({
}) })
}, },
toBottom() { toBottom() {
setTimeout(()=>{
this.setData({ this.setData({
scrollTop: 99999 scrollTop: 99999
}) })
},10)
}, },
// 头部返回上一级 // 头部返回上一级
back() { back() {
...@@ -104,7 +107,6 @@ Page({ ...@@ -104,7 +107,6 @@ Page({
} }
const audioBox = this.selectComponent('#audioBox'); const audioBox = this.selectComponent('#audioBox');
audioBox.addList(addVal,1) audioBox.addList(addVal,1)
this.toBottom()
const chatList = audioBox.data.list; const chatList = audioBox.data.list;
const point = attackScript[index].main_point; const point = attackScript[index].main_point;
let main_point = '' let main_point = ''
...@@ -178,7 +180,6 @@ Page({ ...@@ -178,7 +180,6 @@ Page({
inspirationContent: '', inspirationContent: '',
showSpeechPopup: false showSpeechPopup: false
}, () => { }, () => {
this.toBottom()
this.getSparring(content); this.getSparring(content);
this.getEnhancement(content); this.getEnhancement(content);
}) })
...@@ -318,7 +319,7 @@ Page({ ...@@ -318,7 +319,7 @@ Page({
defense_step, defense_step,
step: next_step step: next_step
}, () => { }, () => {
this.toBottom() // this.toBottom()
// const l = chatList.length - 1 // const l = chatList.length - 1
// const audio_com = this.selectComponent(`#audio_${l}`); // const audio_com = this.selectComponent(`#audio_${l}`);
// audio_com.onTtsStart() // audio_com.onTtsStart()
......
...@@ -7,7 +7,7 @@ const SpeechSynthesizer = require("~/utils/aliyun/tts") ...@@ -7,7 +7,7 @@ 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()
const ctx = wx.createInnerAudioContext() let ctx = wx.createInnerAudioContext()
let timer = null let timer = null
Component({ Component({
...@@ -28,11 +28,9 @@ Component({ ...@@ -28,11 +28,9 @@ Component({
const { const {
list list
} = this.data; } = this.data;
list.forEach(i => {
i.openAudio = false;
})
this.setData({ this.setData({
list list,
audioIndex:''
}) })
}else { }else {
clearInterval(timer) clearInterval(timer)
...@@ -45,7 +43,9 @@ Component({ ...@@ -45,7 +43,9 @@ Component({
* 组件的初始数据 * 组件的初始数据
*/ */
data: { data: {
status:'end',
list: [], list: [],
audioIndex: '',
ttsStart: false, ttsStart: false,
ttsText: "是的发生大客户" ttsText: "是的发生大客户"
}, },
...@@ -101,53 +101,38 @@ Component({ ...@@ -101,53 +101,38 @@ Component({
tts.on("completed", async (msg) => { tts.on("completed", async (msg) => {
console.log("Client recv completed:", msg) console.log("Client recv completed:", msg)
await sleep(500) await sleep(100)
fs.close({ fs.close({
fd: this.data.saveFd, fd: this.data.saveFd,
success: (res) => { success: (res) => {
ctx.autoplay = true this.setAudio(this.data.selectIndex,this.data.saveFile,'ai')
ctx.src = this.data.saveFile
ctx.onPlay(() => {
console.log('start playing..')
})
ctx.onError((res) => { ctx.onError((res) => {
console.log(res.errMsg) console.log(res.errMsg)
console.log(res.errCode) console.log(res.errCode)
fs.unlink({
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.onEnded((res) => {
const {
list,
selectIndex
} = this.data;
if (list[selectIndex]) {
list[selectIndex].openAudio = false;
this.setData({
list
})
}
fs.unlink({
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.onEnded((res) => {
// const {
// list,
// selectIndex
// } = this.data;
// if (list[selectIndex]) {
// list[selectIndex].openAudio = false;
// this.setData({
// list
// })
// }
// fs.unlink({
// 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)
// }
// })
// })
}, },
fail: (res) => { fail: (res) => {
console.log("saved file error:" + res.errMsg) console.log("saved file error:" + res.errMsg)
...@@ -165,40 +150,81 @@ Component({ ...@@ -165,40 +150,81 @@ Component({
this.data.tts = tts this.data.tts = tts
}, },
//暂停播放 toBottom() {
stopAudio() { const pages = getCurrentPages()
ctx.stop() const curPage = pages[pages.length - 1];
curPage.toBottom()
}, },
//自己声音播放 setAudio(index,filePath,type) {
playVoice: wx.$util.throttle(function (e) { ctx = wx.createInnerAudioContext()
this.stopAudio()
const {
index,
file: filePath // 获取语音文件的路径或URL
} = e.currentTarget.dataset
const { const {
list list,
audioIndex,
status
} = this.data; } = this.data;
list.forEach(i => { if(type) {
i.openAudio = false; list[index].filePath = filePath;
}) this.toBottom()
list[index].openAudio = true; }
console.log(list, index, filePath) console.log(index,audioIndex,status)
// if (index === audioIndex && status == 'start') {
// ctx.pause();
// }
// if (index === audioIndex && status == 'pause') {
// ctx.play();
// return
// }
this.setData({ this.setData({
list list,
audioIndex:index
}) })
const _this = this;
ctx.src = filePath; // 替换为你的音频文件路径 ctx.src = filePath; // 替换为你的音频文件路径
// 监听播放完成事件 // 监听播放完成事件
const _this = this;
ctx.onEnded(() => { ctx.onEnded(() => {
list[index].openAudio = false; console.log('结束...')
const pages = getCurrentPages()
const curPage = pages[pages.length - 1];
curPage.toBottom()
_this.setData({ _this.setData({
list audioIndex: null
}) })
// fs.unlink({
// 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(); ctx.play();
// 开始播放音频
ctx.onPlay(() => {
this.setData({status:'start'})
console.log('开始...')
})
ctx.onPause(() => {
this.setData({status:'pause'})
console.log('暂停...')
})
},
//结束播放
stopAudio() {
ctx.stop()
},
//自己声音播放
playVoice: wx.$util.throttle(function (e) {
this.stopAudio()
const {
index,
file: filePath // 获取语音文件的路径或URL
} = e.currentTarget.dataset
this.setAudio(index,filePath)
}, 1500), }, 1500),
addList(val, isPlay) { addList(val, isPlay) {
let { let {
...@@ -215,6 +241,8 @@ Component({ ...@@ -215,6 +241,8 @@ Component({
list = [...list, val] list = [...list, val]
this.setData({ this.setData({
list list
},()=>{
this.toBottom()
}) })
if (val.role == 2) { if (val.role == 2) {
this.setData({ this.setData({
...@@ -269,6 +297,8 @@ Component({ ...@@ -269,6 +297,8 @@ Component({
} }
this.setData({ this.setData({
list list
},()=>{
this.toBottom()
}) })
if (!index) this.playAudio(len) if (!index) this.playAudio(len)
}, },
...@@ -304,12 +334,8 @@ Component({ ...@@ -304,12 +334,8 @@ Component({
}, 1500), }, 1500),
async onTtsStart(index) { async onTtsStart(index) {
const { const {
list list,
} = this.data; } = this.data;
if (list[index].openAudio == true) {
// ctx.pause();
return
}
this.stopAudio() this.stopAudio()
this.setData({ this.setData({
selectIndex: index selectIndex: index
...@@ -330,12 +356,8 @@ Component({ ...@@ -330,12 +356,8 @@ Component({
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)
list.forEach(i => {
i.openAudio = false;
})
list[index].openAudio = true;
this.setData({ this.setData({
list list,audioIndex:index
}) })
console.log("tts done") console.log("tts done")
this.data.ttsStart = false this.data.ttsStart = false
......
...@@ -105,6 +105,22 @@ ...@@ -105,6 +105,22 @@
border: 5rpx solid #fff; border: 5rpx solid #fff;
} }
} }
.loadding {
display: inline-block;
width: 14rpx;
height: 14rpx;
border-radius: 50%;
margin-right: 24rpx;
&.first {
background-color: rgba(57, 137, 254, 0.3);
}
&.second {
background-color: rgba(57, 137, 254, 0.5);
}
&.third {
background-color: rgba(57, 137, 254, 0.7);
}
}
.audio-left { .audio-left {
font-size: 30rpx; font-size: 30rpx;
color: #333333; color: #333333;
......
<!--packageEquity/pages/aiCheck/components/AudioTts/AudioTts.wxml--> <!--packageEquity/pages/aiCheck/components/AudioTts/AudioTts.wxml-->
<view class="chat-item" wx:for="{{list}}"> <view class="chat-item" wx:for="{{list}}">
<view class="chat-left" wx:if="{{item.role == 1 && item.content}}"> <view class="chat-left" wx:if="{{item.role == 1}}">
<image class="avatar-icon" src="{{avatar}}"></image> <image class="avatar-icon" src="{{avatar}}"></image>
<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"> <view class="audio-box" wx:if="{{item.filePath}}">
<view class="audio-left" data-index="{{index}}" bindtap="playAudio"> <view class="audio-left" data-file="{{item.filePath}}" data-index="{{index}}" bindtap="playVoice">
<view class="wifi-symbol"> <view class="wifi-symbol">
<gl-image class="icon" wx:if="{{item.openAudio}}" src="/aiCheck/audio_b.gif"></gl-image> <gl-image class="icon" wx:if="{{audioIndex === index}}" 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>
</view> </view>
</view> </view>
<view class="content-box">{{item.content}}</view> <view class="audio-left" wx:else>
<view class="first loadding"></view>
<view class="second loadding"></view>
<view class="third loadding"></view>
</view>
<view class="content-box" wx:if="{{item.filePath}}">{{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}}">
...@@ -22,7 +26,7 @@ ...@@ -22,7 +26,7 @@
<view class="audio-right" data-file="{{item.filePath}}" data-index="{{index}}" bindtap="playVoice"> <view class="audio-right" data-file="{{item.filePath}}" data-index="{{index}}" bindtap="playVoice">
<text>{{item.times}}"</text> <text>{{item.times}}"</text>
<view class="wifi-symbol"> <view class="wifi-symbol">
<gl-image class="icon" wx:if="{{item.openAudio}}" src="/aiCheck/audio_w.gif"></gl-image> <gl-image class="icon" wx:if="{{audioIndex === index}}" 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>
......
...@@ -108,7 +108,7 @@ Component({ ...@@ -108,7 +108,7 @@ Component({
duration: 600000, duration: 600000,
numberOfChannels: 1, numberOfChannels: 1,
sampleRate: 16000, sampleRate: 16000,
format: "mp3", format: "PCM",
frameSize: 4 frameSize: 4
}) })
}, },
...@@ -178,7 +178,7 @@ Component({ ...@@ -178,7 +178,7 @@ Component({
if (!isClose) { if (!isClose) {
if (!result) { if (!result) {
wx.$util.showToast('没有声音') wx.$util.showToast('没有声音')
this.data.srStart = false // this.data.srStart = false
this.triggerEvent('close') this.triggerEvent('close')
return return
} }
......
...@@ -182,7 +182,7 @@ Page({ ...@@ -182,7 +182,7 @@ Page({
try { try {
const chatList = JSON.parse(JSON.parse(sparringContent)) const chatList = JSON.parse(JSON.parse(sparringContent))
this.setData({chatList}) this.setData({chatList})
this.setDetail(JSON.parse(checkResult)) this.setDetail(JSON.parse(checkResult.replace(/\'/g,"\"")))
} catch (error) { } catch (error) {
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!