mirror of
https://github.com/jambonz/speech-utils.git
synced 2025-12-19 03:37:49 +00:00
tts key should include model
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -169,6 +169,7 @@ async function synthAudio(client, createHash, retrieveHash, logger, stats, { acc
|
||||
language: language || '',
|
||||
voice: voice || deploymentId,
|
||||
engine,
|
||||
model,
|
||||
text
|
||||
});
|
||||
|
||||
|
||||
11
lib/utils.js
11
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}`;
|
||||
|
||||
@@ -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`);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user