2024-11-04 12:59:04 -05:00
|
|
|
const { getCustomConfig } = require('~/server/services/Config');
|
2024-08-27 06:09:04 -04:00
|
|
|
const { logger } = require('~/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 {
|
|
|
|
|
const customConfig = await getCustomConfig();
|
2024-08-27 06:09:04 -04:00
|
|
|
|
|
|
|
|
if (!customConfig) {
|
|
|
|
|
return res.status(200).send({
|
|
|
|
|
message: 'not_found',
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-17 16:08:43 +02:00
|
|
|
const sttExternal = !!customConfig.speech?.stt;
|
|
|
|
|
const ttsExternal = !!customConfig.speech?.tts;
|
|
|
|
|
let settings = {
|
|
|
|
|
sttExternal,
|
|
|
|
|
ttsExternal,
|
|
|
|
|
};
|
2024-07-05 17:13:34 +03:00
|
|
|
|
2024-08-27 06:09:04 -04:00
|
|
|
if (!customConfig.speech?.speechTab) {
|
2024-07-17 16:08:43 +02:00
|
|
|
return res.status(200).send(settings);
|
2024-07-05 17:13:34 +03:00
|
|
|
}
|
|
|
|
|
|
2024-07-17 16:08:43 +02:00
|
|
|
const speechTab = customConfig.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
|
|
|
|
2024-07-17 16:08:43 +02:00
|
|
|
if (speechTab.speechToText) {
|
|
|
|
|
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
|
|
|
|
2024-07-17 16:08:43 +02:00
|
|
|
if (speechTab.textToSpeech) {
|
|
|
|
|
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;
|