|
@@ -30,6 +30,7 @@
|
|
|
data(){
|
|
|
return{
|
|
|
readSrc:"",
|
|
|
+ innerAudioContext:null,
|
|
|
viewData:{
|
|
|
taskTitle:"",
|
|
|
taskContent:[]
|
|
@@ -75,6 +76,11 @@
|
|
|
},
|
|
|
onUnload() {
|
|
|
uni.removeStorageSync('index-detail-info')
|
|
|
+ if(this.innerAudioContext){
|
|
|
+ this.innerAudioContext.stop();
|
|
|
+ this.innerAudioContext.destroy()
|
|
|
+ this.innerAudioContext=null;
|
|
|
+ }
|
|
|
},
|
|
|
methods:{
|
|
|
submitForm(){
|
|
@@ -108,22 +114,30 @@
|
|
|
},
|
|
|
async read(){
|
|
|
let taskContent=this.viewData.taskContent
|
|
|
- let time=2;
|
|
|
+
|
|
|
+ let time=3;
|
|
|
+ if(this.innerAudioContext){
|
|
|
+ this.innerAudioContext.stop();
|
|
|
+ }else{
|
|
|
+ this.innerAudioContext = uni.createInnerAudioContext();
|
|
|
+ }
|
|
|
for(let i=0;i<taskContent.length;i++){
|
|
|
- await this.playAudio(this.getreadSrc(taskContent[i].text))
|
|
|
- await this.playAudio(this.getreadSrc(taskContent[i].text))
|
|
|
- await this.playAudio(this.getreadSrc(taskContent[i].text))
|
|
|
+ for(let j=0;j<time;j++){
|
|
|
+ await this.playAudio(this.getreadSrc(taskContent[i].text))
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
getreadSrc(ttsText){
|
|
|
let cuid="hyy-"+(new Date().getTime());
|
|
|
let access_token=this.tts_token
|
|
|
- let readUrl=`https://tsn.baidu.com/text2audio?lan=zh&ctp=1&cuid=${cuid}&tok=${access_token}&vol=9&per=0&spd=5&pit=5&aue=3&tex=${ttsText}`;
|
|
|
+ let spd=3
|
|
|
+ let per=0;
|
|
|
+ let readUrl=`https://tsn.baidu.com/text2audio?lan=zh&ctp=1&cuid=${cuid}&tok=${access_token}&vol=9&per=${per}&spd=${spd}&pit=5&aue=3&tex=${ttsText}`;
|
|
|
return readUrl;
|
|
|
},
|
|
|
playAudio(src,sleep=3000){
|
|
|
return new Promise((resolve, reject)=>{
|
|
|
- var innerAudioContext = uni.createInnerAudioContext();
|
|
|
+ var innerAudioContext = this.innerAudioContext;
|
|
|
innerAudioContext.autoplay = true;
|
|
|
innerAudioContext.src = src;
|
|
|
innerAudioContext.onPlay(() => {
|
|
@@ -136,10 +150,9 @@
|
|
|
});
|
|
|
innerAudioContext.onEnded(()=>{
|
|
|
setTimeout(()=>{
|
|
|
- innerAudioContext=null
|
|
|
resolve()
|
|
|
},sleep)
|
|
|
- })
|
|
|
+ })
|
|
|
})
|
|
|
},
|
|
|
async getTTStoken() {
|