@jambonz/speech-utils 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/add-file-to-cache.js +2 -1
- package/lib/purge-tts-cache.js +2 -1
- package/lib/synth-audio.js +2 -0
- package/lib/utils.js +9 -2
- package/package.json +1 -1
- package/test/synth.js +3 -3
package/lib/add-file-to-cache.js
CHANGED
|
@@ -25,7 +25,7 @@ function getExtensionAndSampleRate(path) {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
async function addFileToCache(client, logger, path,
|
|
28
|
-
{account_sid, vendor, language, voice, deploymentId, engine, text}) {
|
|
28
|
+
{account_sid, vendor, language, voice, deploymentId, engine, model, text}) {
|
|
29
29
|
let key;
|
|
30
30
|
logger = logger || noopLogger;
|
|
31
31
|
|
|
@@ -36,6 +36,7 @@ async function addFileToCache(client, logger, path,
|
|
|
36
36
|
language: language || '',
|
|
37
37
|
voice: voice || deploymentId,
|
|
38
38
|
engine,
|
|
39
|
+
model,
|
|
39
40
|
text,
|
|
40
41
|
});
|
|
41
42
|
const [extension, sampleRate] = getExtensionAndSampleRate(path);
|
package/lib/purge-tts-cache.js
CHANGED
|
@@ -12,7 +12,7 @@ const debug = require('debug')('jambonz:realtimedb-helpers');
|
|
|
12
12
|
* @returns {object} result - {error, purgedCount}
|
|
13
13
|
*/
|
|
14
14
|
async function purgeTtsCache(client, logger, {all, account_sid, vendor,
|
|
15
|
-
language, voice, deploymentId, engine, text} = {all: true}) {
|
|
15
|
+
language, voice, deploymentId, engine, model, text} = {all: true}) {
|
|
16
16
|
logger = logger || noopLogger;
|
|
17
17
|
|
|
18
18
|
let purgedCount = 0, error;
|
|
@@ -33,6 +33,7 @@ async function purgeTtsCache(client, logger, {all, account_sid, vendor,
|
|
|
33
33
|
language: language || '',
|
|
34
34
|
voice: voice || deploymentId,
|
|
35
35
|
engine,
|
|
36
|
+
model,
|
|
36
37
|
text,
|
|
37
38
|
});
|
|
38
39
|
purgedCount = await client.del(key);
|
package/lib/synth-audio.js
CHANGED
|
@@ -169,6 +169,8 @@ async function synthAudio(client, createHash, retrieveHash, logger, stats, { acc
|
|
|
169
169
|
language: language || '',
|
|
170
170
|
voice: voice || deploymentId,
|
|
171
171
|
engine,
|
|
172
|
+
// model or model_id is used to identify the tts cache.
|
|
173
|
+
model: model || credentials.model_id,
|
|
172
174
|
text
|
|
173
175
|
});
|
|
174
176
|
|
package/lib/utils.js
CHANGED
|
@@ -17,9 +17,16 @@ const debug = require('debug')('jambonz:realtimedb-helpers');
|
|
|
17
17
|
//const nuanceClientMap = new Map();
|
|
18
18
|
|
|
19
19
|
function makeSynthKey({
|
|
20
|
-
account_sid = '',
|
|
20
|
+
account_sid = '',
|
|
21
|
+
vendor,
|
|
22
|
+
language,
|
|
23
|
+
voice,
|
|
24
|
+
engine = '',
|
|
25
|
+
model = '',
|
|
26
|
+
text
|
|
27
|
+
}) {
|
|
21
28
|
const hash = crypto.createHash('sha1');
|
|
22
|
-
hash.update(`${language}:${vendor}:${voice}:${engine}:${text}`);
|
|
29
|
+
hash.update(`${language}:${vendor}:${voice}:${engine}:${model}:${text}`);
|
|
23
30
|
const hexHashKey = hash.digest('hex');
|
|
24
31
|
const accountKey = account_sid ? `:${account_sid}` : '';
|
|
25
32
|
const key = `tts${accountKey}:${hexHashKey}`;
|
package/package.json
CHANGED
package/test/synth.js
CHANGED
|
@@ -5,7 +5,7 @@ const fs = require('fs');
|
|
|
5
5
|
const {makeSynthKey} = require('../lib/utils');
|
|
6
6
|
const logger = require('pino')();
|
|
7
7
|
const bent = require('bent');
|
|
8
|
-
const getJSON = bent('json')
|
|
8
|
+
const getJSON = bent('json');
|
|
9
9
|
|
|
10
10
|
process.on('unhandledRejection', (reason, p) => {
|
|
11
11
|
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
|
|
@@ -853,11 +853,11 @@ test('TTS Cache tests', async(t) => {
|
|
|
853
853
|
// save some random tts keys to cache
|
|
854
854
|
const minRecords = 8;
|
|
855
855
|
for (const i in Array(minRecords).fill(0)) {
|
|
856
|
-
await client.set(makeSynthKey({vendor: i, language: i, voice: i, engine: i, text: i}), i);
|
|
856
|
+
await client.set(makeSynthKey({vendor: i, language: i, voice: i, engine: i, model: i, text: i}), i);
|
|
857
857
|
}
|
|
858
858
|
const count = await getTtsSize();
|
|
859
859
|
t.ok(count >= minRecords, 'getTtsSize worked.');
|
|
860
|
-
|
|
860
|
+
|
|
861
861
|
const {purgedCount} = await purgeTtsCache();
|
|
862
862
|
t.ok(purgedCount >= minRecords, `successfully purged at least ${minRecords} tts records from cache`);
|
|
863
863
|
|