diff --git a/lib/add-file-to-cache.js b/lib/add-file-to-cache.js index 44040fd..f1b0a20 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, model, text}) { + {account_sid, vendor, language, voice, deploymentId, engine, model, text, instructions}) { let key; logger = logger || noopLogger; @@ -38,6 +38,7 @@ async function addFileToCache(client, logger, path, engine, model, text, + instructions }); const [extension, sampleRate] = getExtensionAndSampleRate(path); const audioBuffer = await fs.readFile(path); diff --git a/lib/purge-tts-cache.js b/lib/purge-tts-cache.js index 86ba974..bafb5dd 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, model, text} = {all: true}) { + language, voice, deploymentId, engine, model, text, instructions} = {all: true}) { logger = logger || noopLogger; let purgedCount = 0, error; @@ -35,6 +35,7 @@ async function purgeTtsCache(client, logger, {all, account_sid, vendor, engine, model, text, + instructions }); purgedCount = await client.del(key); if (purgedCount === 0) error = 'Specified item not found'; diff --git a/lib/synth-audio.js b/lib/synth-audio.js index 4e72328..69159cc 100644 --- a/lib/synth-audio.js +++ b/lib/synth-audio.js @@ -171,7 +171,8 @@ async function synthAudio(client, createHash, retrieveHash, logger, stats, { acc engine, // model or model_id is used to identify the tts cache. model: model || credentials.model_id, - text + text, + instructions }); debug(`synth key is ${key}`); diff --git a/lib/utils.js b/lib/utils.js index 81047b5..d973637 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -23,10 +23,11 @@ function makeSynthKey({ voice, engine = '', model = '', - text + text, + instructions = '', }) { const hash = crypto.createHash('sha1'); - hash.update(`${language}:${vendor}:${voice}:${engine}:${model}:${text}`); + hash.update(`${language}:${vendor}:${voice}:${engine}:${model}:${text}:${instructions}`); 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 811639b..4ca2944 100644 --- a/test/synth.js +++ b/test/synth.js @@ -887,7 +887,8 @@ 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, model: i, text: i}), i); + await client.set(makeSynthKey({vendor: i, language: i, voice: i, engine: i, model: i, text: i, + instructions: i}), i); } const count = await getTtsSize(); t.ok(count >= minRecords, 'getTtsSize worked.'); @@ -906,7 +907,7 @@ test('TTS Cache tests', async(t) => { try { // save some random tts keys to cache for (const i in Array(10).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, text: i, instructions: i}), i); } // save a specific key to tts cache const opts = {vendor: 'aws', language: 'en-US', voice: 'MALE', engine: 'Engine', text: 'Hello World!'}; @@ -944,10 +945,10 @@ test('TTS Cache tests', async(t) => { const account_sid = "12412512_cabc_5aff" const account_sid2 = "22412512_cabc_5aff" for (const i in Array(minRecords).fill(0)) { - await client.set(makeSynthKey({account_sid, vendor: i, language: i, voice: i, engine: i, text: i}), i); + await client.set(makeSynthKey({account_sid, vendor: i, language: i, voice: i, engine: i, text: i, instructions: i}), i); } for (const i in Array(minRecords).fill(0)) { - await client.set(makeSynthKey({account_sid: account_sid2, vendor: i, language: i, voice: i, engine: i, text: i}), i); + await client.set(makeSynthKey({account_sid: account_sid2, vendor: i, language: i, voice: i, engine: i, text: i, instructions: i}), i); } const {purgedCount} = await purgeTtsCache({account_sid}); t.equal(purgedCount, minRecords, `successfully purged at least ${minRecords} tts records from cache for account_sid:${account_sid}`);