diff --git a/lib/add-file-to-cache.js b/lib/add-file-to-cache.js index 55c2736..44040fd 100644 --- a/lib/add-file-to-cache.js +++ b/lib/add-file-to-cache.js @@ -25,7 +25,7 @@ function getExtensionAndSampleRate(path) { } async function addFileToCache(client, logger, path, - {account_sid, vendor, language, voice, deploymentId, engine, text}) { + {account_sid, vendor, language, voice, deploymentId, engine, model, text}) { let key; logger = logger || noopLogger; @@ -36,6 +36,7 @@ async function addFileToCache(client, logger, path, language: language || '', voice: voice || deploymentId, engine, + model, text, }); const [extension, sampleRate] = getExtensionAndSampleRate(path); diff --git a/lib/purge-tts-cache.js b/lib/purge-tts-cache.js index 1b26ab6..86ba974 100644 --- a/lib/purge-tts-cache.js +++ b/lib/purge-tts-cache.js @@ -12,7 +12,7 @@ const debug = require('debug')('jambonz:realtimedb-helpers'); * @returns {object} result - {error, purgedCount} */ async function purgeTtsCache(client, logger, {all, account_sid, vendor, - language, voice, deploymentId, engine, text} = {all: true}) { + language, voice, deploymentId, engine, model, text} = {all: true}) { logger = logger || noopLogger; let purgedCount = 0, error; @@ -33,6 +33,7 @@ async function purgeTtsCache(client, logger, {all, account_sid, vendor, language: language || '', voice: voice || deploymentId, engine, + model, text, }); purgedCount = await client.del(key); diff --git a/lib/synth-audio.js b/lib/synth-audio.js index 72381a0..a8214f3 100644 --- a/lib/synth-audio.js +++ b/lib/synth-audio.js @@ -169,6 +169,8 @@ async function synthAudio(client, createHash, retrieveHash, logger, stats, { acc language: language || '', voice: voice || deploymentId, engine, + // model or model_id is used to identify the tts cache. + model: model || credentials.model_id, text }); diff --git a/lib/utils.js b/lib/utils.js index a901d68..81047b5 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -17,9 +17,16 @@ const debug = require('debug')('jambonz:realtimedb-helpers'); //const nuanceClientMap = new Map(); function makeSynthKey({ - account_sid = '', vendor, language, voice, engine = '', text}) { + account_sid = '', + vendor, + language, + voice, + engine = '', + model = '', + text +}) { const hash = crypto.createHash('sha1'); - hash.update(`${language}:${vendor}:${voice}:${engine}:${text}`); + hash.update(`${language}:${vendor}:${voice}:${engine}:${model}:${text}`); const hexHashKey = hash.digest('hex'); const accountKey = account_sid ? `:${account_sid}` : ''; const key = `tts${accountKey}:${hexHashKey}`; diff --git a/test/synth.js b/test/synth.js index 4e10893..bea43df 100644 --- a/test/synth.js +++ b/test/synth.js @@ -5,7 +5,7 @@ const fs = require('fs'); const {makeSynthKey} = require('../lib/utils'); const logger = require('pino')(); const bent = require('bent'); -const getJSON = bent('json') +const getJSON = bent('json'); process.on('unhandledRejection', (reason, p) => { console.log('Unhandled Rejection at: Promise', p, 'reason:', reason); @@ -853,11 +853,11 @@ test('TTS Cache tests', async(t) => { // save some random tts keys to cache const minRecords = 8; for (const i in Array(minRecords).fill(0)) { - await client.set(makeSynthKey({vendor: i, language: i, voice: i, engine: i, text: i}), i); + await client.set(makeSynthKey({vendor: i, language: i, voice: i, engine: i, model: i, text: i}), i); } const count = await getTtsSize(); t.ok(count >= minRecords, 'getTtsSize worked.'); - + const {purgedCount} = await purgeTtsCache(); t.ok(purgedCount >= minRecords, `successfully purged at least ${minRecords} tts records from cache`);