From fbd0782258fb46671ca7595b7d4b571e95693b94 Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Wed, 2 Aug 2023 19:06:31 -0400 Subject: [PATCH] #388 - support custom speech vendor in transcribe verb (#414) Co-authored-by: Hoan Luu Huu <110280845+xquanluu@users.noreply.github.com> --- lib/tasks/transcribe.js | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/tasks/transcribe.js b/lib/tasks/transcribe.js index 25a55f82..1f858d0c 100644 --- a/lib/tasks/transcribe.js +++ b/lib/tasks/transcribe.js @@ -234,7 +234,19 @@ class TaskTranscribe extends Task { this._onVadDetected.bind(this, cs, ep)); break; default: - throw new Error(`Invalid vendor ${this.vendor}`); + if (this.vendor.startsWith('custom:')) { + this.bugname = `${this.vendor}_transcribe`; + ep.addCustomEventListener(JambonzTranscriptionEvents.Transcription, this._onTranscription.bind(this, cs, ep)); + ep.addCustomEventListener(JambonzTranscriptionEvents.Connect, this._onJambonzConnect.bind(this, cs, ep)); + ep.addCustomEventListener(JambonzTranscriptionEvents.ConnectFailure, + this._onJambonzConnectFailure.bind(this, cs, ep)); + break; + } + else { + this.notifyError({ msg: 'ASR error', details:`Invalid vendor ${this.vendor}`}); + this.notifyTaskDone(); + throw new Error(`Invalid vendor ${this.vendor}`); + } } /* common handler for all stt engine errors */ @@ -408,6 +420,24 @@ class TaskTranscribe extends Task { this.notifyTaskDone(); } + _onJambonzConnect(_cs, _ep) { + this.logger.debug('TaskTranscribe:_onJambonzConnect'); + } + + _onJambonzConnectFailure(cs, _ep, evt) { + const {reason} = evt; + const {writeAlerts, AlertType} = cs.srf.locals; + this.logger.info({evt}, 'TaskTranscribe:_onJambonzConnectFailure'); + writeAlerts({ + account_sid: cs.accountSid, + alert_type: AlertType.STT_FAILURE, + message: `Failed connecting to ${this.vendor} speech recognizer: ${reason}`, + vendor: this.vendor, + }).catch((err) => this.logger.info({err}, 'Error generating alert for jambonz custom connection failure')); + this.notifyError({msg: 'ASR error', details:`Failed connecting to speech vendor ${this.vendor}: ${reason}`}); + this.notifyTaskDone(); + } + _onIbmConnect(_cs, _ep) { this.logger.debug('TaskTranscribe:_onIbmConnect'); }