feat pause resume transcribe (#438)

* feat pause resume transcribe

* wip

* fix jslint

* update fsmrf
This commit is contained in:
Hoan Luu Huu
2023-08-31 09:43:50 +07:00
committed by GitHub
parent c10c561ba1
commit 2935574440
5 changed files with 65 additions and 11 deletions

View File

@@ -9,7 +9,8 @@ const {
SonioxTranscriptionEvents,
IbmTranscriptionEvents,
NvidiaTranscriptionEvents,
JambonzTranscriptionEvents
JambonzTranscriptionEvents,
TranscribeStatus
} = require('../utils/constants');
const { normalizeJambones } = require('@jambonz/verb-specifications');
const SttTask = require('./stt-task');
@@ -119,8 +120,7 @@ class TaskTranscribe extends SttTask {
this.removeSpeechListeners(ep);
}
async kill(cs) {
super.kill(cs);
async _stopTranscription() {
let stopTranscription = false;
if (this.ep?.connected) {
stopTranscription = true;
@@ -132,6 +132,13 @@ class TaskTranscribe extends SttTask {
this.ep2.stopTranscription({vendor: this.vendor})
.catch((err) => this.logger.info(err, 'Error TaskTranscribe:kill'));
}
return stopTranscription;
}
async kill(cs) {
super.kill(cs);
const stopTranscription = this._stopTranscription();
// hangup after 1 sec if we don't get a final transcription
if (stopTranscription) this._timer = setTimeout(() => this.notifyTaskDone(), 1500);
else this.notifyTaskDone();
@@ -139,6 +146,23 @@ class TaskTranscribe extends SttTask {
await this.awaitTaskDone();
}
async updateTranscribe(status) {
if (!this.killed && this.ep && this.ep.connected) {
this.logger.info(`TaskTranscribe:updateTranscribe status ${status}`);
switch (status) {
case TranscribeStatus.Pause:
await this._stopTranscription();
break;
case TranscribeStatus.Resume:
await this._startTranscribing(this.cs, this.ep, 1);
if (this.separateRecognitionPerChannel && this.ep2) {
await this._startTranscribing(this.cs, this.ep2, 2);
}
break;
}
}
}
async _startTranscribing(cs, ep, channel) {
const opts = this.setChannelVarsForStt(this, this.sttCredentials, this.data.recognizer);
switch (this.vendor) {