Skip to content

Commit c043939

Browse files
committed
fix: Limit the number of retries for text to speech conversion
1 parent 66f674f commit c043939

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

ui/src/components/ai-chat/component/operation-button/ChatOperationButton.vue

+11-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
@click="
3030
() => {
3131
bus.emit('play:pause', props.data.record_id)
32-
audioManage?.play(props.data.answer_text, true)
32+
audioManage?.play(props.data.answer_text, true, true)
3333
}
3434
"
3535
>
@@ -261,12 +261,14 @@ class AudioManage {
261261
textList: Array<string>
262262
statusList: Array<AudioStatus>
263263
audioList: Array<HTMLAudioElement | SpeechSynthesisUtterance>
264+
tryList: Array<number>
264265
ttsType: string
265266
root: Element
266267
constructor(ttsType: string, root: HTMLDivElement) {
267268
this.textList = []
268269
this.audioList = []
269270
this.statusList = []
271+
this.tryList = []
270272
this.ttsType = ttsType
271273
this.root = root
272274
}
@@ -279,6 +281,7 @@ class AudioManage {
279281
newTextList.forEach((text, index) => {
280282
this.textList.push(text)
281283
this.statusList.push(AudioStatus.MOUNTED)
284+
this.tryList.push(1)
282285
index = this.textList.length - 1
283286
if (this.ttsType === 'TTS') {
284287
const audioElement: HTMLAudioElement = document.createElement('audio')
@@ -363,10 +366,12 @@ class AudioManage {
363366
}
364367
reTryError() {
365368
this.statusList.forEach((status, index) => {
366-
if (status === AudioStatus.ERROR) {
369+
if (status === AudioStatus.ERROR && this.tryList[index] <= 3) {
370+
this.tryList[index]++
367371
const audioElement = this.audioList[index]
368372
if (audioElement instanceof HTMLAudioElement) {
369373
const text = this.textList[index]
374+
this.statusList[index] = AudioStatus.MOUNTED
370375
applicationApi
371376
.postTextToSpeech(
372377
(props.applicationId as string) || (id as string),
@@ -401,7 +406,10 @@ class AudioManage {
401406
isPlaying() {
402407
return this.statusList.some((item) => [AudioStatus.PLAY_INT].includes(item))
403408
}
404-
play(text?: string, is_end?: boolean) {
409+
play(text?: string, is_end?: boolean, self?: boolean) {
410+
if (self) {
411+
this.tryList = this.tryList.map((item) => 0)
412+
}
405413
if (text) {
406414
const textList = this.getTextList(text, is_end ? true : false)
407415
this.appendTextList(textList)

0 commit comments

Comments
 (0)