mirror of
https://github.com/jambonz/speech-utils.git
synced 2025-12-19 03:37:49 +00:00
42 lines
1.6 KiB
JavaScript
42 lines
1.6 KiB
JavaScript
const {noopLogger} = require('./lib/utils');
|
|
const Redis = require('ioredis');
|
|
|
|
module.exports = (opts, logger) => {
|
|
logger = logger || noopLogger;
|
|
const connectionOpts = {...opts};
|
|
// Support legacy app
|
|
if (process.env.JAMBONES_REDIS_USERNAME && process.env.JAMBONES_REDIS_PASSWORD) {
|
|
if (Array.isArray(connectionOpts)) {
|
|
for (const o of opts) {
|
|
o.username = process.env.JAMBONES_REDIS_USERNAME;
|
|
o.password = process.env.JAMBONES_REDIS_PASSWORD;
|
|
}
|
|
} else {
|
|
connectionOpts.username = process.env.JAMBONES_REDIS_USERNAME;
|
|
connectionOpts.password = process.env.JAMBONES_REDIS_PASSWORD;
|
|
}
|
|
}
|
|
|
|
const client = new Redis(connectionOpts);
|
|
['ready', 'connect', 'reconnecting', 'error', 'end', 'warning']
|
|
.forEach((event) => {
|
|
client.on(event, (...args) => {
|
|
if ('error' === event) {
|
|
if (process.env.NODE_ENV === 'test' && args[0]?.code === 'ECONNREFUSED') return;
|
|
logger.error({...args}, '@jambonz/realtimedb-helpers - redis error');
|
|
}
|
|
else logger.debug({args}, `redis event ${event}`);
|
|
});
|
|
});
|
|
|
|
return {
|
|
client,
|
|
getTtsSize: require('./lib/get-tts-size').bind(null, client, logger),
|
|
purgeTtsCache: require('./lib/purge-tts-cache').bind(null, client, logger),
|
|
synthAudio: require('./lib/synth-audio').bind(null, client, logger),
|
|
getNuanceAccessToken: require('./lib/get-nuance-access-token').bind(null, client, logger),
|
|
getIbmAccessToken: require('./lib/get-ibm-access-token').bind(null, client, logger),
|
|
getTtsVoices: require('./lib/get-tts-voices').bind(null, client, logger),
|
|
};
|
|
};
|