Fix/gladia multi sessions (#1487)

* support gladia transcribe multi channels

* wip
This commit is contained in:
Hoan Luu Huu
2026-01-07 22:46:33 +07:00
committed by GitHub
parent ba275ef547
commit e4ec0025c3
4 changed files with 20 additions and 25 deletions

View File

@@ -500,6 +500,10 @@ class TaskGather extends SttTask {
this.addCustomEventListener(ep, GladiaTranscriptionEvents.ConnectFailure, this.addCustomEventListener(ep, GladiaTranscriptionEvents.ConnectFailure,
this._onVendorConnectFailure.bind(this, cs, ep)); this._onVendorConnectFailure.bind(this, cs, ep));
this.addCustomEventListener(ep, GladiaTranscriptionEvents.Error, this._onVendorError.bind(this, cs, ep)); this.addCustomEventListener(ep, GladiaTranscriptionEvents.Error, this._onVendorError.bind(this, cs, ep));
// gladia require unique url for each session
const {host, path} = await this.createGladiaLiveSession();
opts.GLADIA_SPEECH_HOST = host;
opts.GLADIA_SPEECH_PATH = path;
break; break;
case 'soniox': case 'soniox':

View File

@@ -203,26 +203,14 @@ class SttTask extends Task {
if (cs.hasGlobalSttPunctuation && !this.data.recognizer.punctuation) { if (cs.hasGlobalSttPunctuation && !this.data.recognizer.punctuation) {
this.data.recognizer.punctuation = cs.globalSttPunctuation; this.data.recognizer.punctuation = cs.globalSttPunctuation;
} }
if (this.vendor === 'gladia') {
const { api_key, region } = this.sttCredentials;
const {url} = await this.createGladiaLiveSession({
api_key, region,
model: this.data.recognizer.model || 'solaria-1',
options: this.data.recognizer.gladiaOptions || {}
});
const {host, pathname, search} = new URL(url);
this.sttCredentials.host = host;
this.sttCredentials.path = `${pathname}${search}`;
}
} }
async createGladiaLiveSession({ async createGladiaLiveSession() {
api_key, const { api_key, region = 'us-west' } = this.sttCredentials;
region = 'us-west', const model = this.data.recognizer.model || 'solaria-1';
model = 'solaria-1', const options = this.data.recognizer.gladiaOptions || {};
options = {},
}) {
const url = `https://api.gladia.io/v2/live?region=${region}`; const url = `https://api.gladia.io/v2/live?region=${region}`;
const response = await fetch(url, { const response = await fetch(url, {
method: 'POST', method: 'POST',
@@ -252,7 +240,9 @@ class SttTask extends Task {
const data = await response.json(); const data = await response.json();
this.logger.debug({url: data.url}, 'Gladia Call registered'); this.logger.debug({url: data.url}, 'Gladia Call registered');
return data;
const {host, pathname, search} = new URL(data.url);
return {host, path: `${pathname}${search}`};
} }
addCustomEventListener(ep, event, handler) { addCustomEventListener(ep, event, handler) {

View File

@@ -459,6 +459,14 @@ class TaskTranscribe extends SttTask {
else if (this.data.recognizer?.hints?.length > 0) { else if (this.data.recognizer?.hints?.length > 0) {
prompt = this.data.recognizer?.hints.join(', '); prompt = this.data.recognizer?.hints.join(', ');
} }
} else if (this.vendor === 'gladia') {
// gladia require unique url for each session
const {host, path} = await this.createGladiaLiveSession();
await ep.set({
GLADIA_SPEECH_HOST: host,
GLADIA_SPEECH_PATH: path,
})
.catch((err) => this.logger.info(err, 'Error setting channel variables'));
} }
await ep.startTranscription({ await ep.startTranscription({

View File

@@ -1085,13 +1085,6 @@ module.exports = (logger) => {
...(keyterms && keyterms.length > 0 && {DEEPGRAMFLUX_SPEECH_KEYTERMS: keyterms.join(',')}), ...(keyterms && keyterms.length > 0 && {DEEPGRAMFLUX_SPEECH_KEYTERMS: keyterms.join(',')}),
}; };
} }
else if ('gladia' === vendor) {
const {host, path} = sttCredentials;
opts = {
GLADIA_SPEECH_HOST: host,
GLADIA_SPEECH_PATH: path,
};
}
else if ('soniox' === vendor) { else if ('soniox' === vendor) {
const {sonioxOptions = {}} = rOpts; const {sonioxOptions = {}} = rOpts;
const {storage = {}} = sonioxOptions; const {storage = {}} = sonioxOptions;