support elevenlabs stt

This commit is contained in:
Hoan HL
2025-11-18 16:06:09 +07:00
parent 486428727a
commit 1629f52962
7 changed files with 208 additions and 23 deletions
+43 -2
View File
@@ -9,6 +9,7 @@ const Houndify = require('houndify');
const { GladiaClient } = require('@gladiaio/sdk');
const {decrypt, obscureKey} = require('./encrypt-decrypt');
const { RealtimeSession } = require('speechmatics');
const {ElevenLabsClient} = require('@elevenlabs/elevenlabs-js');
const TtsGoogleLanguagesVoices = require('./speech-data/tts-google');
const TtsAwsLanguagesVoices = require('./speech-data/tts-aws');
@@ -52,11 +53,13 @@ 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 SttElevenlabsLanguagesVoices = require('./speech-data/stt-elevenlabs');
const SttModelOpenai = require('./speech-data/stt-model-openai');
const sttModelDeepgram = require('./speech-data/stt-model-deepgram');
const sttModelCartesia = require('./speech-data/stt-model-cartesia');
const sttModelElevenlabs = require('./speech-data/stt-model-elevenlabs');
function capitalizeFirst(str) {
if (!str) return str;
@@ -402,6 +405,42 @@ const testElevenlabs = async(logger, credentials) => {
return response.body;
};
const testElevenlabsStt = async(logger, credentials) => {
const {api_key, stt_model_id} = credentials;
// Validate API key
if (!api_key) {
throw new Error('ElevenLabs API key is required');
}
const client = new ElevenLabsClient({
environment: 'https://api.elevenlabs.io',
apiKey: api_key
});
return new Promise(async(resolve, reject) => {
try {
const audioBuffer = fs.readFileSync(`${__dirname}/../../data/test_audio.wav`);
const result = await client.speechToText.convert({
file: audioBuffer,
modelId: stt_model_id
});
// Check if we got a valid response with text
if (result && result.text && result.text.length > 0) {
logger.debug({result}, 'ElevenLabs STT successful');
resolve(result);
} else {
reject(new Error('no transcript returned from ElevenLabs STT'));
}
} catch (error) {
logger.info({error}, 'failed to get ElevenLabs STT transcript');
reject(error);
}
});
};
const testPlayHT = async(logger, synthAudio, credentials) => {
try {
await synthAudio(
@@ -849,6 +888,7 @@ function decryptCredential(obj, credential, logger, isObscureKey = true) {
obj.model_id = o.model_id;
obj.api_uri = o.api_uri;
obj.options = o.options;
obj.stt_model_id = o.stt_model_id;
} else if ('playht' === obj.vendor) {
const o = JSON.parse(decrypt(credential));
obj.api_key = isObscureKey ? obscureKey(o.api_key) : o.api_key;
@@ -1218,13 +1258,13 @@ async function getLanguagesVoicesForElevenlabs(credential) {
language.voices = voices;
}
}
return tranform(languages, undefined, models);
return tranform(languages, SttElevenlabsLanguagesVoices, models, sttModelElevenlabs);
} else {
const voices = TtsElevenlabsLanguagesVoices[0].voices;
for (const language of TtsElevenlabsLanguagesVoices) {
language.voices = voices;
}
return tranform(TtsElevenlabsLanguagesVoices, undefined, TtsModelElevenLabs);
return tranform(TtsElevenlabsLanguagesVoices, SttElevenlabsLanguagesVoices, TtsModelElevenLabs, sttModelElevenlabs);
}
}
@@ -1783,6 +1823,7 @@ module.exports = {
testIbmStt,
testSonioxStt,
testElevenlabs,
testElevenlabsStt,
testPlayHT,
testRimelabs,
testInworld,