From 4065db1d888bc70b205d3c3b9d1d8f88ed90f69c Mon Sep 17 00:00:00 2001 From: Hoan HL Date: Thu, 27 Nov 2025 15:07:57 +0700 Subject: [PATCH] fixed transcribe cannot fallback for specific endpoint --- lib/tasks/stt-task.js | 20 ++++++++++++++++---- lib/tasks/transcribe.js | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/tasks/stt-task.js b/lib/tasks/stt-task.js index 79201185..f02d9776 100644 --- a/lib/tasks/stt-task.js +++ b/lib/tasks/stt-task.js @@ -260,8 +260,19 @@ class SttTask extends Task { ep.addCustomEventListener(event, handler); } - removeCustomEventListeners() { - this.eventHandlers.forEach((h) => h.ep.removeCustomEventListener(h.event, h.handler)); + removeCustomEventListeners(ep) { + if (ep) { + // for specific endpoint + this.eventHandlers.filter((h) => h.ep === ep).forEach((h) => { + h.ep.removeCustomEventListener(h.event, h.handler); + }); + this.eventHandlers = this.eventHandlers.filter((h) => h.ep !== ep); + return; + } else { + // for all endpoints + this.eventHandlers.forEach((h) => h.ep.removeCustomEventListener(h.event, h.handler)); + this.eventHandlers = []; + } } async _initSpeechCredentials(cs, vendor, label) { @@ -333,7 +344,8 @@ class SttTask extends Task { return this.fallbackVendor && this.isHandledByPrimaryProvider && !this.cs.hasFallbackAsr; } - async _initFallback() { + // gather does not need to provide ep, but transcribe does as it might has 2 legs + async _initFallback(ep) { assert(this.fallbackVendor, 'fallback failed without fallbackVendor configuration'); this.logger.info(`Failed to use primary STT provider, fallback to ${this.fallbackVendor}`); this.isHandledByPrimaryProvider = false; @@ -346,7 +358,7 @@ class SttTask extends Task { this.data.recognizer.label = this.label; this.sttCredentials = await this._initSpeechCredentials(this.cs, this.vendor, this.label); // cleanup previous listener from previous vendor - this.removeCustomEventListeners(); + this.removeCustomEventListeners(ep); } async compileHintsForCobalt(ep, hostport, model, token, hints) { diff --git a/lib/tasks/transcribe.js b/lib/tasks/transcribe.js index ec51685c..2ea6d199 100644 --- a/lib/tasks/transcribe.js +++ b/lib/tasks/transcribe.js @@ -786,7 +786,7 @@ class TaskTranscribe extends SttTask { try { this.notifyError({ msg: 'ASR error', details:`STT Vendor ${this.vendor} error: ${evt.error || evt.reason}`, failover: 'in progress'}); - await this._initFallback(); + await this._initFallback(_ep); let channel = 1; if (this.ep !== _ep) { channel = 2;