LibreChat/api/server/services/Files/Audio/getVoices.js
Danny Avila c342e2345b
Some checks are pending
Docker Dev Branch Images Build / build (Dockerfile, lc-dev, node) (push) Waiting to run
Docker Dev Branch Images Build / build (Dockerfile.multi, lc-dev-api, api-build) (push) Waiting to run
GitNexus Index / index (push) Waiting to run
GitNexus Index / post-index (push) Blocked by required conditions
🪪 fix: Resolve Group-Scoped Config Overrides (#13176)
* fix: resolve group-scoped config overrides

* test: fix endpoint config request mock typing

* fix: keep remote agent preauth config tenant-scoped

* test: align config scoping expectations

* test: reproduce group endpoint override resolution
2026-05-18 10:16:20 -04:00

56 lines
1.6 KiB
JavaScript

const { TTSProviders } = require('librechat-data-provider');
const { getAppConfig } = require('~/server/services/Config');
const { getProvider } = require('./TTSService');
/**
* This function retrieves the available voices for the current TTS provider
* It first fetches the TTS configuration and determines the provider
* Then, based on the provider, it sends the corresponding voices as a JSON response
*
* @param {Object} req - The request object
* @param {Object} res - The response object
* @returns {Promise<void>}
* @throws {Error} - If the provider is not 'openai' or 'elevenlabs', an error is thrown
*/
async function getVoices(req, res) {
try {
const appConfig =
req.config ??
(await getAppConfig({
role: req.user?.role,
userId: req.user?.id,
tenantId: req.user?.tenantId,
}));
const ttsSchema = appConfig?.speech?.tts;
if (!ttsSchema) {
throw new Error('Configuration or TTS schema is missing');
}
const provider = await getProvider(appConfig);
let voices;
switch (provider) {
case TTSProviders.OPENAI:
voices = ttsSchema.openai?.voices;
break;
case TTSProviders.AZURE_OPENAI:
voices = ttsSchema.azureOpenAI?.voices;
break;
case TTSProviders.ELEVENLABS:
voices = ttsSchema.elevenlabs?.voices;
break;
case TTSProviders.LOCALAI:
voices = ttsSchema.localai?.voices;
break;
default:
throw new Error('Invalid provider');
}
res.json(voices);
} catch (error) {
res.status(500).json({ error: `Failed to get voices: ${error.message}` });
}
}
module.exports = getVoices;