support mod_cartesia_transcribe (#1245)

This commit is contained in:
Hoan Luu Huu
2025-06-18 01:54:26 +07:00
committed by GitHub
parent 259dedcded
commit 5be6c54339
6 changed files with 67 additions and 0 deletions

View File

@@ -1097,6 +1097,7 @@ class CallSession extends Emitter {
return { return {
api_key: credential.api_key, api_key: credential.api_key,
model_id: credential.model_id, model_id: credential.model_id,
stt_model_id: credential.stt_model_id,
embedding: credential.embedding, embedding: credential.embedding,
options: credential.options options: credential.options
}; };

View File

@@ -12,6 +12,7 @@ const {
JambonzTranscriptionEvents, JambonzTranscriptionEvents,
AssemblyAiTranscriptionEvents, AssemblyAiTranscriptionEvents,
VoxistTranscriptionEvents, VoxistTranscriptionEvents,
CartesiaTranscriptionEvents,
OpenAITranscriptionEvents, OpenAITranscriptionEvents,
VadDetection, VadDetection,
VerbioTranscriptionEvents, VerbioTranscriptionEvents,
@@ -546,6 +547,17 @@ class TaskGather extends SttTask {
this._onVendorConnectFailure.bind(this, cs, ep)); this._onVendorConnectFailure.bind(this, cs, ep));
break; break;
case 'cartesia':
this.bugname = `${this.bugname_prefix}cartesia_transcribe`;
this.addCustomEventListener(ep, CartesiaTranscriptionEvents.Transcription,
this._onTranscription.bind(this, cs, ep));
this.addCustomEventListener(
ep, CartesiaTranscriptionEvents.Connect, this._onVendorConnect.bind(this, cs, ep));
this.addCustomEventListener(ep, CartesiaTranscriptionEvents.Error, this._onVendorError.bind(this, cs, ep));
this.addCustomEventListener(ep, CartesiaTranscriptionEvents.ConnectFailure,
this._onVendorConnectFailure.bind(this, cs, ep));
break;
case 'speechmatics': case 'speechmatics':
this.bugname = `${this.bugname_prefix}speechmatics_transcribe`; this.bugname = `${this.bugname_prefix}speechmatics_transcribe`;
this.addCustomEventListener( this.addCustomEventListener(

View File

@@ -14,6 +14,7 @@ const {
TranscribeStatus, TranscribeStatus,
AssemblyAiTranscriptionEvents, AssemblyAiTranscriptionEvents,
VoxistTranscriptionEvents, VoxistTranscriptionEvents,
CartesiaTranscriptionEvents,
OpenAITranscriptionEvents, OpenAITranscriptionEvents,
VerbioTranscriptionEvents, VerbioTranscriptionEvents,
SpeechmaticsTranscriptionEvents SpeechmaticsTranscriptionEvents
@@ -312,6 +313,17 @@ class TaskTranscribe extends SttTask {
this._onVendorConnectFailure.bind(this, cs, ep, channel)); this._onVendorConnectFailure.bind(this, cs, ep, channel));
break; break;
case 'cartesia':
this.bugname = `${this.bugname_prefix}cartesia_transcribe`;
this.addCustomEventListener(ep, CartesiaTranscriptionEvents.Transcription,
this._onTranscription.bind(this, cs, ep, channel));
this.addCustomEventListener(ep,
CartesiaTranscriptionEvents.Connect, this._onVendorConnect.bind(this, cs, ep));
this.addCustomEventListener(ep, CartesiaTranscriptionEvents.Error, this._onVendorError.bind(this, cs, ep));
this.addCustomEventListener(ep, CartesiaTranscriptionEvents.ConnectFailure,
this._onVendorConnectFailure.bind(this, cs, ep, channel));
break;
case 'speechmatics': case 'speechmatics':
this.bugname = `${this.bugname_prefix}speechmatics_transcribe`; this.bugname = `${this.bugname_prefix}speechmatics_transcribe`;
this.addCustomEventListener( this.addCustomEventListener(

View File

@@ -167,6 +167,12 @@
"ConnectFailure": "voxist_transcribe::connect_failed", "ConnectFailure": "voxist_transcribe::connect_failed",
"Connect": "voxist_transcribe::connect" "Connect": "voxist_transcribe::connect"
}, },
"CartesiaTranscriptionEvents": {
"Transcription": "cartesia_transcribe::transcription",
"Error": "cartesia_transcribe::error",
"ConnectFailure": "cartesia_transcribe::connect_failed",
"Connect": "cartesia_transcribe::connect"
},
"VadDetection": { "VadDetection": {
"Detection": "vad_detect:detection" "Detection": "vad_detect:detection"
}, },

View File

@@ -110,6 +110,7 @@ const speechMapper = (cred) => {
const o = JSON.parse(decrypt(credential)); const o = JSON.parse(decrypt(credential));
obj.api_key = o.api_key; obj.api_key = o.api_key;
obj.model_id = o.model_id; obj.model_id = o.model_id;
obj.stt_model_id = o.stt_model_id;
obj.embedding = o.embedding; obj.embedding = o.embedding;
obj.options = o.options; obj.options = o.options;
} }

View File

@@ -110,6 +110,10 @@ const stickyVars = {
voxist: [ voxist: [
'VOXIST_API_KEY', 'VOXIST_API_KEY',
], ],
cartesia: [
'CARTESIA_API_KEY',
'CARTESIA_MODEL_ID'
],
speechmatics: [ speechmatics: [
'SPEECHMATICS_API_KEY', 'SPEECHMATICS_API_KEY',
'SPEECHMATICS_HOST', 'SPEECHMATICS_HOST',
@@ -555,6 +559,25 @@ const normalizeVoxist = (evt, channel, language) => {
}; };
}; };
const normalizeCartesia = (evt, channel, language) => {
const copy = JSON.parse(JSON.stringify(evt));
return {
language_code: language,
channel_tag: channel,
is_final: evt.is_final,
alternatives: [
{
confidence: 1.00,
transcript: evt.text,
}
],
vendor: {
name: 'cartesia',
evt: copy
}
};
};
const normalizeSpeechmatics = (evt, channel, language) => { const normalizeSpeechmatics = (evt, channel, language) => {
const copy = JSON.parse(JSON.stringify(evt)); const copy = JSON.parse(JSON.stringify(evt));
const is_final = evt.message === 'AddTranscript'; const is_final = evt.message === 'AddTranscript';
@@ -636,6 +659,8 @@ module.exports = (logger) => {
return normalizeAssemblyAi(evt, channel, language, shortUtterance); return normalizeAssemblyAi(evt, channel, language, shortUtterance);
case 'voxist': case 'voxist':
return normalizeVoxist(evt, channel, language); return normalizeVoxist(evt, channel, language);
case 'cartesia':
return normalizeCartesia(evt, channel, language);
case 'verbio': case 'verbio':
return normalizeVerbio(evt, channel, language); return normalizeVerbio(evt, channel, language);
case 'speechmatics': case 'speechmatics':
@@ -1008,6 +1033,16 @@ module.exports = (logger) => {
{VOXIST_API_KEY: sttCredentials.api_key}, {VOXIST_API_KEY: sttCredentials.api_key},
}; };
} }
else if ('cartesia' === vendor) {
opts = {
...opts,
...(sttCredentials.api_key &&
{CARTESIA_API_KEY: sttCredentials.api_key}),
...(sttCredentials.stt_model_id && {
CARTESIA_MODEL_ID: sttCredentials.stt_model_id
})
};
}
else if ('openai' === vendor) { else if ('openai' === vendor) {
const {openaiOptions = {}} = rOpts; const {openaiOptions = {}} = rOpts;
const model = openaiOptions.model || rOpts.model || sttCredentials.model_id || 'whisper-1'; const model = openaiOptions.model || rOpts.model || sttCredentials.model_id || 'whisper-1';