@jambonz/speech-utils 0.0.5 → 0.0.7

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.
@@ -1,5 +1,5 @@
1
1
  const assert = require('assert');
2
- const {noopLogger, createNuanceClient} = require('./utils');
2
+ const {noopLogger, createNuanceClient, createKryptonClient} = require('./utils');
3
3
  const getNuanceAccessToken = require('./get-nuance-access-token');
4
4
  const {GetVoicesRequest, Voice} = require('../stubs/nuance/synthesizer_pb');
5
5
  const TextToSpeechV1 = require('ibm-watson/text-to-speech/v1');
@@ -21,15 +21,20 @@ const getIbmVoices = async(client, logger, credentials) => {
21
21
  };
22
22
 
23
23
  const getNuanceVoices = async(client, logger, credentials) => {
24
- const {client_id: clientId, secret: secret} = credentials;
24
+ const {client_id: clientId, secret: secret, nuance_tts_uri} = credentials;
25
25
 
26
26
  return new Promise(async(resolve, reject) => {
27
27
  /* get a nuance access token */
28
28
  let token, nuanceClient;
29
29
  try {
30
- const access_token = await getNuanceAccessToken(client, logger, clientId, secret, 'tts');
31
- token = access_token.access_token;
32
- nuanceClient = await createNuanceClient(token);
30
+ if (nuance_tts_uri) {
31
+ nuanceClient = await createKryptonClient(nuance_tts_uri);
32
+ }
33
+ else {
34
+ const access_token = await getNuanceAccessToken(client, logger, clientId, secret, 'tts');
35
+ token = access_token.access_token;
36
+ nuanceClient = await createNuanceClient(token);
37
+ }
33
38
  } catch (err) {
34
39
  logger.error({err}, 'getTtsVoices: error retrieving access token');
35
40
  return reject(err);
@@ -16,7 +16,7 @@ const {
16
16
  CancellationDetails,
17
17
  SpeechSynthesisOutputFormat
18
18
  } = sdk;
19
- const {makeSynthKey, createNuanceClient, noopLogger, createRivaClient} = require('./utils');
19
+ const {makeSynthKey, createNuanceClient, createKryptonClient, createRivaClient, noopLogger} = require('./utils');
20
20
  const getNuanceAccessToken = require('./get-nuance-access-token');
21
21
  const {
22
22
  SynthesisRequest,
@@ -75,8 +75,10 @@ async function synthAudio(client, logger, stats, { account_sid,
75
75
  }
76
76
  else if ('nuance' === vendor) {
77
77
  assert.ok(voice, 'synthAudio requires voice when nuance is used');
78
- assert.ok(credentials.client_id, 'synthAudio requires client_id in credentials when nuance is used');
79
- assert.ok(credentials.secret, 'synthAudio requires client_id in credentials when nuance is used');
78
+ if (!credentials.nuance_tts_uri) {
79
+ assert.ok(credentials.client_id, 'synthAudio requires client_id in credentials when nuance is used');
80
+ assert.ok(credentials.secret, 'synthAudio requires client_id in credentials when nuance is used');
81
+ }
80
82
  }
81
83
  else if ('nvidia' === vendor) {
82
84
  assert.ok(voice, 'synthAudio requires voice when nvidia is used');
@@ -184,7 +186,14 @@ async function synthAudio(client, logger, stats, { account_sid,
184
186
 
185
187
  const synthPolly = async(logger, {credentials, stats, language, voice, engine, text}) => {
186
188
  try {
187
- const polly = new PollyClient({...credentials});
189
+ const {region, accessKeyId, secretAccessKey} = credentials;
190
+ const polly = new PollyClient({
191
+ region,
192
+ credentials: {
193
+ accessKeyId,
194
+ secretAccessKey
195
+ }
196
+ });
188
197
  const opts = {
189
198
  Engine: engine,
190
199
  OutputFormat: 'mp3',
@@ -364,10 +373,16 @@ const synthWellSaid = async(logger, {credentials, stats, language, voice, gender
364
373
  };
365
374
 
366
375
  const synthNuance = async(client, logger, {credentials, stats, voice, model, text}) => {
367
- /* get a nuance access token */
368
- const {client_id, secret} = credentials;
369
- const {access_token} = await getNuanceAccessToken(client, logger, client_id, secret, 'tts');
370
- const nuanceClient = await createNuanceClient(access_token);
376
+ let nuanceClient;
377
+ const {client_id, secret, nuance_tts_uri} = credentials;
378
+ if (nuance_tts_uri) {
379
+ nuanceClient = await createKryptonClient(nuance_tts_uri);
380
+ }
381
+ else {
382
+ /* get a nuance access token */
383
+ const {access_token} = await getNuanceAccessToken(client, logger, client_id, secret, 'tts');
384
+ nuanceClient = await createNuanceClient(access_token);
385
+ }
371
386
 
372
387
  const v = new Voice();
373
388
  const p = new AudioParameters();
package/lib/utils.js CHANGED
@@ -77,6 +77,11 @@ const getNuanceAccessToken = async(clientId, secret, scope = 'asr tts') => {
77
77
  return json.access_token;
78
78
  };
79
79
 
80
+ const createKryptonClient = async(uri) => {
81
+ const client = new SynthesizerClient(uri, grpc.credentials.createInsecure());
82
+ return client;
83
+ };
84
+
80
85
  const createNuanceClient = async(access_token) => {
81
86
 
82
87
  //if (nuanceClientMap.has(access_token)) return nuanceClientMap.get(access_token);
@@ -108,6 +113,7 @@ module.exports = {
108
113
  makeIbmKey,
109
114
  getNuanceAccessToken,
110
115
  createNuanceClient,
116
+ createKryptonClient,
111
117
  createRivaClient,
112
118
  makeBasicAuthHeader,
113
119
  NUANCE_AUTH_ENDPOINT,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jambonz/speech-utils",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "TTS-related speech utilities for jambonz",
5
5
  "main": "index.js",
6
6
  "author": "Dave Horton",
package/test/nuance.js CHANGED
@@ -12,12 +12,12 @@ const stats = {
12
12
  histogram: () => {}
13
13
  };
14
14
 
15
- test('Nuance tests', async(t) => {
15
+ test('Nuance hosted tests', async(t) => {
16
16
  const fn = require('..');
17
17
  const {client, getTtsVoices} = fn(opts, logger);
18
18
 
19
19
  if (!process.env.NUANCE_CLIENT_ID || !process.env.NUANCE_SECRET ) {
20
- t.pass('skipping Nuance test since no Nuance client_id and secret provided');
20
+ t.pass('skipping Nuance hosted test since no Nuance client_id and secret provided');
21
21
  t.end();
22
22
  client.quit();
23
23
  return;
@@ -31,8 +31,39 @@ test('Nuance tests', async(t) => {
31
31
  }
32
32
  };
33
33
  let voices = await getTtsVoices(opts);
34
- //console.log(`received ${voices.length} voices from Nuance`);
35
- //console.log(JSON.stringify(voices));
34
+ t.ok(voices.length > 0 && voices[0].language,
35
+ `GetVoices: successfully retrieved ${voices.length} voices from Nuance`);
36
+
37
+ await client.flushallAsync();
38
+
39
+ t.end();
40
+
41
+ }
42
+ catch (err) {
43
+ console.error(err);
44
+ t.end(err);
45
+ }
46
+ client.quit();
47
+ });
48
+
49
+ test('Nuance on-prem tests', async(t) => {
50
+ const fn = require('..');
51
+ const {client, getTtsVoices} = fn(opts, logger);
52
+
53
+ if (!process.env.NUANCE_TTS_URI ) {
54
+ t.pass('skipping Nuance on-prem test since no Nuance uri provided');
55
+ t.end();
56
+ client.quit();
57
+ return;
58
+ }
59
+ try {
60
+ const opts = {
61
+ vendor: 'nuance',
62
+ credentials: {
63
+ nuance_tts_uri: process.env.NUANCE_TTS_URI
64
+ }
65
+ };
66
+ let voices = await getTtsVoices(opts);
36
67
  t.ok(voices.length > 0 && voices[0].language,
37
68
  `GetVoices: successfully retrieved ${voices.length} voices from Nuance`);
38
69
 
package/test/synth.js CHANGED
@@ -212,7 +212,7 @@ test('Azure custom voice speech synth tests', async(t) => {
212
212
  client.quit();
213
213
  });
214
214
 
215
- test('Nuance speech synth tests', async(t) => {
215
+ test('Nuance hosted speech synth tests', async(t) => {
216
216
  const fn = require('..');
217
217
  const {synthAudio, client} = fn(opts, logger);
218
218
 
@@ -251,6 +251,43 @@ test('Nuance speech synth tests', async(t) => {
251
251
  client.quit();
252
252
  });
253
253
 
254
+ test('Nuance on-prem speech synth tests', async(t) => {
255
+ const fn = require('..');
256
+ const {synthAudio, client} = fn(opts, logger);
257
+
258
+ if (!process.env.NUANCE_TTS_URI) {
259
+ t.pass('skipping Nuance on prem speech synth tests since NUANCE_TTS_URI not provided');
260
+ return t.end();
261
+ }
262
+ try {
263
+ let opts = await synthAudio(stats, {
264
+ vendor: 'nuance',
265
+ credentials: {
266
+ nuance_tts_uri: process.env.NUANCE_TTS_URI
267
+ },
268
+ language: 'en-US',
269
+ voice: 'Evan',
270
+ text: 'This is a test of on-prem. This is only a test',
271
+ });
272
+ t.ok(!opts.servedFromCache, `successfully synthesized nuance audio to ${opts.filePath}`);
273
+
274
+ opts = await synthAudio(stats, {
275
+ vendor: 'nuance',
276
+ credentials: {
277
+ nuance_tts_uri: process.env.NUANCE_TTS_URI
278
+ },
279
+ language: 'en-US',
280
+ voice: 'Evan',
281
+ text: 'This is a test of on-prem. This is only a test',
282
+ });
283
+ t.ok(opts.servedFromCache, `successfully retrieved nuance audio from cache ${opts.filePath}`);
284
+ } catch (err) {
285
+ console.error(err);
286
+ t.end(err);
287
+ }
288
+ client.quit();
289
+ });
290
+
254
291
  test('Nvidia speech synth tests', async(t) => {
255
292
  const fn = require('..');
256
293
  const {synthAudio, client} = fn(opts, logger);