support gladia stt (#503)

* support gladia stt

* wip

* update verb specification
This commit is contained in:
Hoan Luu Huu
2025-10-20 15:47:17 +07:00
committed by GitHub
parent 0f1f5e9b73
commit 42f4318a17
6 changed files with 261 additions and 6 deletions
+73
View File
@@ -6,6 +6,7 @@ const { SpeechClient } = require('@soniox/soniox-node');
const fs = require('fs');
const { AssemblyAI } = require('assemblyai');
const Houndify = require('houndify');
const { GladiaClient } = require('@gladiaio/sdk');
const {decrypt, obscureKey} = require('./encrypt-decrypt');
const { RealtimeSession } = require('speechmatics');
@@ -50,6 +51,7 @@ const SttHoundifyLanguagesVoices = require('./speech-data/stt-houndify');
const SttVoxistLanguagesVoices = require('./speech-data/stt-voxist');
const SttVerbioLanguagesVoices = require('./speech-data/stt-verbio');
const SttOpenaiLanguagesVoices = require('./speech-data/stt-openai');
const SttGladiaLanguagesVoices = require('./speech-data/stt-gladia');
const SttModelOpenai = require('./speech-data/stt-model-openai');
@@ -170,6 +172,65 @@ const testGoogleStt = async(logger, credentials) => {
}
};
const testGladiaStt = async(logger, credentials) => {
const {api_key} = credentials;
try {
const gladiaClient = new GladiaClient({
apiKey: api_key,
});
const gladiaConfig = {
model: 'solaria-1',
encoding: 'wav/pcm',
sample_rate: 16000,
bit_depth: 16,
channels: 1,
language_config: {
languages: ['en'],
code_switching: false,
},
};
// Start the live session
const liveSession = gladiaClient.liveV2().startSession(gladiaConfig);
// Read the test audio file
const audioBuffer = fs.readFileSync(`${__dirname}/../../data/test_audio.wav`);
// Wait for final transcript
return new Promise((resolve, reject) => {
liveSession.on('message', (message) => {
if (message.type === 'transcript' && message.data.is_final) {
logger.debug(`${message.data.id}: ${message.data.utterance.text}`);
liveSession.stopRecording();
resolve(message.data.utterance.text);
}
});
liveSession.on('error', (error) => {
logger.error({error}, 'Gladia Live STT error');
reject(error);
});
// Send audio in chunks
const chunkSize = 1024;
for (let i = 0; i < audioBuffer.length; i += chunkSize) {
const chunk = audioBuffer.slice(i, i + chunkSize);
liveSession.sendAudio(chunk);
}
// Stop recording after sending all audio
liveSession.stopRecording();
// Set a timeout to prevent hanging
setTimeout(() => {
reject(new Error('Gladia STT test timeout'));
}, 30000); // 30 second timeout
});
} catch (error) {
logger.error({error}, 'Failed to create Gladia Live STT session');
throw error;
}
};
const testDeepgramStt = async(logger, credentials) => {
const {api_key, deepgram_stt_uri, deepgram_stt_use_tls} = credentials;
const deepgram = new Deepgram(api_key, deepgram_stt_uri, deepgram_stt_uri && deepgram_stt_use_tls);
@@ -758,6 +819,10 @@ function decryptCredential(obj, credential, logger, isObscureKey = true) {
const o = JSON.parse(decrypt(credential));
obj.api_key = isObscureKey ? obscureKey(o.api_key) : o.api_key;
}
else if ('gladia' === obj.vendor) {
const o = JSON.parse(decrypt(credential));
obj.api_key = isObscureKey ? obscureKey(o.api_key) : o.api_key;
}
else if ('ibm' === obj.vendor) {
const o = JSON.parse(decrypt(credential));
obj.tts_api_key = isObscureKey ? obscureKey(o.tts_api_key) : o.tts_api_key;
@@ -881,6 +946,8 @@ async function getLanguagesAndVoicesForVendor(logger, vendor, credential, getTts
return await getLanguagesVoicesForNuane(credential, getTtsVoices, logger);
case 'deepgram':
return await getLanguagesVoicesForDeepgram(credential, getTtsVoices, logger);
case 'gladia':
return await getLanguagesVoicesForGladia(credential, getTtsVoices, logger);
case 'ibm':
return await getLanguagesVoicesForIbm(credential, getTtsVoices, logger);
case 'nvidia':
@@ -1052,6 +1119,11 @@ async function getLanguagesVoicesForDeepgram(credential, getTtsVoices, logger) {
TtsModelDeepgram, sttModelDeepgram.sort((a, b) => a.name.localeCompare(b.name)));
}
async function getLanguagesVoicesForGladia(credential, getTtsVoices, logger) {
return tranform(undefined, SttGladiaLanguagesVoices.sort((a, b) => a.name.localeCompare(b.name)),
undefined, undefined);
}
async function getLanguagesVoicesForIbm(credential, getTtsVoices, logger) {
if (credential) {
try {
@@ -1706,6 +1778,7 @@ module.exports = {
testNuanceTts,
testNuanceStt,
testDeepgramStt,
testGladiaStt,
testIbmTts,
testIbmStt,
testSonioxStt,