2025-08-26 12:10:18 -04:00
|
|
|
const { logger } = require('@librechat/data-schemas');
|
|
|
|
|
const { getAppConfig } = require('~/server/services/Config');
|
2024-07-05 17:13:34 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This function retrieves the speechTab settings from the custom configuration
|
|
|
|
|
* It first fetches the custom configuration
|
|
|
|
|
* Then, it checks if the custom configuration and the speechTab schema exist
|
|
|
|
|
* If they do, it sends the speechTab settings as a JSON response
|
|
|
|
|
* If they don't, it throws an error
|
|
|
|
|
*
|
|
|
|
|
* @param {Object} req - The request object
|
|
|
|
|
* @param {Object} res - The response object
|
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
|
* @throws {Error} - If the custom configuration or the speechTab schema is missing, an error is thrown
|
|
|
|
|
*/
|
|
|
|
|
async function getCustomConfigSpeech(req, res) {
|
|
|
|
|
try {
|
2025-08-26 12:10:18 -04:00
|
|
|
const appConfig = await getAppConfig({
|
|
|
|
|
role: req.user?.role,
|
|
|
|
|
});
|
2024-08-27 06:09:04 -04:00
|
|
|
|
2025-08-26 12:10:18 -04:00
|
|
|
if (!appConfig) {
|
2024-08-27 06:09:04 -04:00
|
|
|
return res.status(200).send({
|
|
|
|
|
message: 'not_found',
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-26 12:10:18 -04:00
|
|
|
const sttExternal = !!appConfig.speech?.stt;
|
|
|
|
|
const ttsExternal = !!appConfig.speech?.tts;
|
2024-07-17 16:08:43 +02:00
|
|
|
let settings = {
|
|
|
|
|
sttExternal,
|
|
|
|
|
ttsExternal,
|
|
|
|
|
};
|
2024-07-05 17:13:34 +03:00
|
|
|
|
2025-08-26 12:10:18 -04:00
|
|
|
if (!appConfig.speech?.speechTab) {
|
2024-07-17 16:08:43 +02:00
|
|
|
return res.status(200).send(settings);
|
2024-07-05 17:13:34 +03:00
|
|
|
}
|
|
|
|
|
|
2025-08-26 12:10:18 -04:00
|
|
|
const speechTab = appConfig.speech.speechTab;
|
2024-07-05 17:13:34 +03:00
|
|
|
|
2024-07-17 16:08:43 +02:00
|
|
|
if (speechTab.advancedMode !== undefined) {
|
|
|
|
|
settings.advancedMode = speechTab.advancedMode;
|
2024-07-05 17:13:34 +03:00
|
|
|
}
|
2024-07-10 22:38:36 +02:00
|
|
|
|
2025-10-28 09:36:03 -04:00
|
|
|
if (speechTab.speechToText !== undefined) {
|
|
|
|
|
if (typeof speechTab.speechToText === 'boolean') {
|
|
|
|
|
settings.speechToText = speechTab.speechToText;
|
|
|
|
|
} else {
|
|
|
|
|
for (const key in speechTab.speechToText) {
|
|
|
|
|
if (speechTab.speechToText[key] !== undefined) {
|
|
|
|
|
settings[key] = speechTab.speechToText[key];
|
|
|
|
|
}
|
2024-07-05 17:13:34 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-10 22:38:36 +02:00
|
|
|
|
2025-10-28 09:36:03 -04:00
|
|
|
if (speechTab.textToSpeech !== undefined) {
|
|
|
|
|
if (typeof speechTab.textToSpeech === 'boolean') {
|
|
|
|
|
settings.textToSpeech = speechTab.textToSpeech;
|
|
|
|
|
} else {
|
|
|
|
|
for (const key in speechTab.textToSpeech) {
|
|
|
|
|
if (speechTab.textToSpeech[key] !== undefined) {
|
|
|
|
|
settings[key] = speechTab.textToSpeech[key];
|
|
|
|
|
}
|
2024-07-05 17:13:34 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-10 22:38:36 +02:00
|
|
|
return res.status(200).send(settings);
|
2024-07-05 17:13:34 +03:00
|
|
|
} catch (error) {
|
2024-08-27 06:09:04 -04:00
|
|
|
logger.error('Failed to get custom config speech settings:', error);
|
2024-07-17 16:08:43 +02:00
|
|
|
res.status(500).send('Internal Server Error');
|
2024-07-05 17:13:34 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = getCustomConfigSpeech;
|