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