@@ -142,7 +142,6 @@ const emit = defineEmits(['update:data', 'regeneration'])
142
142
143
143
const audioPlayer = ref <HTMLAudioElement [] | null >([])
144
144
const audioCiontainer = ref <HTMLDivElement >()
145
- const audioPlayerStatus = ref (false )
146
145
const buttonData = ref (props .data )
147
146
const loading = ref (false )
148
147
@@ -271,13 +270,15 @@ class AudioManage {
271
270
tryList: Array <number >
272
271
ttsType: string
273
272
root: Element
273
+ is_end: boolean
274
274
constructor (ttsType : string , root : HTMLDivElement ) {
275
275
this .textList = []
276
276
this .audioList = []
277
277
this .statusList = []
278
278
this .tryList = []
279
279
this .ttsType = ttsType
280
280
this .root = root
281
+ this .is_end = false
281
282
}
282
283
appendTextList(textList : Array <string >) {
283
284
const newTextList = textList .slice (this .textList .length )
@@ -300,8 +301,9 @@ class AudioManage {
300
301
audioElement .onended = () => {
301
302
this .statusList [index ] = AudioStatus .END
302
303
// 如果所有的节点都播放结束
303
- if (this .statusList .every ((item ) => item === AudioStatus .END )) {
304
+ if (this .statusList .every ((item ) => item === AudioStatus .END ) && this . is_end ) {
304
305
this .statusList = this .statusList .map ((item ) => AudioStatus .READY )
306
+ this .is_end = false
305
307
} else {
306
308
// next
307
309
this .play ()
@@ -323,21 +325,18 @@ class AudioManage {
323
325
const text = await res .text ()
324
326
MsgError (text )
325
327
this .statusList [index ] = AudioStatus .ERROR
326
- this .play ()
327
- return
328
+ throw ' '
328
329
}
329
330
// 假设我们有一个 MP3 文件的字节数组
330
331
// 创建 Blob 对象
331
332
const blob = new Blob ([res ], { type: ' audio/mp3' })
332
-
333
333
// 创建对象 URL
334
334
const url = URL .createObjectURL (blob )
335
335
audioElement .src = url
336
336
this .statusList [index ] = AudioStatus .READY
337
337
this .play ()
338
338
})
339
339
.catch ((err ) => {
340
- console .log (' err: ' , err )
341
340
this .statusList [index ] = AudioStatus .ERROR
342
341
this .play ()
343
342
})
@@ -348,9 +347,6 @@ class AudioManage {
348
347
const speechSynthesisUtterance: SpeechSynthesisUtterance = new SpeechSynthesisUtterance (
349
348
text
350
349
)
351
- speechSynthesisUtterance .onpause = () => {
352
- console .log (' onpause' )
353
- }
354
350
speechSynthesisUtterance .onend = () => {
355
351
this .statusList [index ] = AudioStatus .END
356
352
// 如果所有的节点都播放结束
@@ -389,8 +385,8 @@ class AudioManage {
389
385
if (res .type === ' application/json' ) {
390
386
const text = await res .text ()
391
387
MsgError (text )
392
- this . statusList [ index ] = AudioStatus . ERROR
393
- return
388
+
389
+ throw ' '
394
390
}
395
391
// 假设我们有一个 MP3 文件的字节数组
396
392
// 创建 Blob 对象
@@ -405,6 +401,7 @@ class AudioManage {
405
401
.catch ((err ) => {
406
402
console .log (' err: ' , err )
407
403
this .statusList [index ] = AudioStatus .ERROR
404
+ this .play ()
408
405
})
409
406
}
410
407
}
@@ -414,6 +411,9 @@ class AudioManage {
414
411
return this .statusList .some ((item ) => [AudioStatus .PLAY_INT ].includes (item ))
415
412
}
416
413
play(text ? : string , is_end ? : boolean , self ? : boolean ) {
414
+ if (is_end ) {
415
+ this .is_end = true
416
+ }
417
417
if (self ) {
418
418
this .tryList = this .tryList .map ((item ) => 0 )
419
419
}
@@ -431,7 +431,6 @@ class AudioManage {
431
431
const index = this .statusList .findIndex ((status ) =>
432
432
[AudioStatus .MOUNTED , AudioStatus .READY ].includes (status )
433
433
)
434
-
435
434
if (index < 0 || this .statusList [index ] === AudioStatus .MOUNTED ) {
436
435
return
437
436
}
@@ -497,6 +496,7 @@ class AudioManage {
497
496
},
498
497
is_end
499
498
)
499
+
500
500
return split
501
501
}
502
502
}
0 commit comments