@@ -142,7 +142,6 @@ const emit = defineEmits(['update:data', 'regeneration'])
142142
143143const audioPlayer = ref <HTMLAudioElement [] | null >([])
144144const audioCiontainer = ref <HTMLDivElement >()
145- const audioPlayerStatus = ref (false )
146145const buttonData = ref (props .data )
147146const loading = ref (false )
148147
@@ -271,13 +270,15 @@ class AudioManage {
271270 tryList: Array <number >
272271 ttsType: string
273272 root: Element
273+ is_end: boolean
274274 constructor (ttsType : string , root : HTMLDivElement ) {
275275 this .textList = []
276276 this .audioList = []
277277 this .statusList = []
278278 this .tryList = []
279279 this .ttsType = ttsType
280280 this .root = root
281+ this .is_end = false
281282 }
282283 appendTextList(textList : Array <string >) {
283284 const newTextList = textList .slice (this .textList .length )
@@ -300,8 +301,9 @@ class AudioManage {
300301 audioElement .onended = () => {
301302 this .statusList [index ] = AudioStatus .END
302303 // 如果所有的节点都播放结束
303- if (this .statusList .every ((item ) => item === AudioStatus .END )) {
304+ if (this .statusList .every ((item ) => item === AudioStatus .END ) && this . is_end ) {
304305 this .statusList = this .statusList .map ((item ) => AudioStatus .READY )
306+ this .is_end = false
305307 } else {
306308 // next
307309 this .play ()
@@ -323,21 +325,18 @@ class AudioManage {
323325 const text = await res .text ()
324326 MsgError (text )
325327 this .statusList [index ] = AudioStatus .ERROR
326- this .play ()
327- return
328+ throw ' '
328329 }
329330 // 假设我们有一个 MP3 文件的字节数组
330331 // 创建 Blob 对象
331332 const blob = new Blob ([res ], { type: ' audio/mp3' })
332-
333333 // 创建对象 URL
334334 const url = URL .createObjectURL (blob )
335335 audioElement .src = url
336336 this .statusList [index ] = AudioStatus .READY
337337 this .play ()
338338 })
339339 .catch ((err ) => {
340- console .log (' err: ' , err )
341340 this .statusList [index ] = AudioStatus .ERROR
342341 this .play ()
343342 })
@@ -348,9 +347,6 @@ class AudioManage {
348347 const speechSynthesisUtterance: SpeechSynthesisUtterance = new SpeechSynthesisUtterance (
349348 text
350349 )
351- speechSynthesisUtterance .onpause = () => {
352- console .log (' onpause' )
353- }
354350 speechSynthesisUtterance .onend = () => {
355351 this .statusList [index ] = AudioStatus .END
356352 // 如果所有的节点都播放结束
@@ -389,8 +385,8 @@ class AudioManage {
389385 if (res .type === ' application/json' ) {
390386 const text = await res .text ()
391387 MsgError (text )
392- this . statusList [ index ] = AudioStatus . ERROR
393- return
388+
389+ throw ' '
394390 }
395391 // 假设我们有一个 MP3 文件的字节数组
396392 // 创建 Blob 对象
@@ -405,6 +401,7 @@ class AudioManage {
405401 .catch ((err ) => {
406402 console .log (' err: ' , err )
407403 this .statusList [index ] = AudioStatus .ERROR
404+ this .play ()
408405 })
409406 }
410407 }
@@ -414,6 +411,9 @@ class AudioManage {
414411 return this .statusList .some ((item ) => [AudioStatus .PLAY_INT ].includes (item ))
415412 }
416413 play(text ? : string , is_end ? : boolean , self ? : boolean ) {
414+ if (is_end ) {
415+ this .is_end = true
416+ }
417417 if (self ) {
418418 this .tryList = this .tryList .map ((item ) => 0 )
419419 }
@@ -431,7 +431,6 @@ class AudioManage {
431431 const index = this .statusList .findIndex ((status ) =>
432432 [AudioStatus .MOUNTED , AudioStatus .READY ].includes (status )
433433 )
434-
435434 if (index < 0 || this .statusList [index ] === AudioStatus .MOUNTED ) {
436435 return
437436 }
@@ -497,6 +496,7 @@ class AudioManage {
497496 },
498497 is_end
499498 )
499+
500500 return split
501501 }
502502}
0 commit comments