@jambonz/speech-utils 0.1.8 → 0.1.11

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/config.js CHANGED
@@ -1,5 +1,6 @@
1
1
  const JAMBONES_TTS_TRIM_SILENCE = process.env.JAMBONES_TTS_TRIM_SILENCE;
2
2
  const JAMBONES_DISABLE_TTS_STREAMING = process.env.JAMBONES_DISABLE_TTS_STREAMING;
3
+ const JAMBONES_DISABLE_AZURE_TTS_STREAMING = process.env.JAMBONES_DISABLE_AZURE_TTS_STREAMING;
3
4
 
4
5
  const JAMBONES_HTTP_PROXY_IP = process.env.JAMBONES_HTTP_PROXY_IP;
5
6
  const JAMBONES_HTTP_PROXY_PORT = process.env.JAMBONES_HTTP_PROXY_PORT;
@@ -13,6 +14,7 @@ const HTTP_TIMEOUT = 5000;
13
14
  module.exports = {
14
15
  JAMBONES_TTS_TRIM_SILENCE,
15
16
  JAMBONES_DISABLE_TTS_STREAMING,
17
+ JAMBONES_DISABLE_AZURE_TTS_STREAMING,
16
18
  JAMBONES_HTTP_PROXY_IP,
17
19
  JAMBONES_HTTP_PROXY_PORT,
18
20
  JAMBONES_TTS_CACHE_DURATION_MINS,
@@ -5,16 +5,16 @@ const EXPIRY = 3600;
5
5
 
6
6
  async function getAwsAuthToken(
7
7
  logger, createHash, retrieveHash,
8
- awsAccessKeyId, awsSecretAccessKey, awsRegion, roleArn = null) {
8
+ {accessKeyId, secretAccessKey, region, roleArn}) {
9
9
  logger = logger || noopLogger;
10
10
  try {
11
- const key = makeAwsKey(roleArn || awsAccessKeyId);
11
+ const key = makeAwsKey(roleArn || accessKeyId);
12
12
  const obj = await retrieveHash(key);
13
13
  if (obj) return {...obj, servedFromCache: true};
14
14
 
15
15
  let data;
16
16
  if (roleArn) {
17
- const stsClient = new STSClient({ region: awsRegion});
17
+ const stsClient = new STSClient({ region });
18
18
  const roleToAssume = { RoleArn: roleArn, RoleSessionName: 'Jambonz_Speech', DurationSeconds: EXPIRY};
19
19
  const command = new AssumeRoleCommand(roleToAssume);
20
20
 
@@ -22,10 +22,10 @@ async function getAwsAuthToken(
22
22
  } else {
23
23
  /* access token not found in cache, so generate it using STS */
24
24
  const stsClient = new STSClient({
25
- region: awsRegion,
25
+ region,
26
26
  credentials: {
27
- accessKeyId: awsAccessKeyId,
28
- secretAccessKey: awsSecretAccessKey,
27
+ accessKeyId,
28
+ secretAccessKey,
29
29
  }
30
30
  });
31
31
  const command = new GetSessionTokenCommand({DurationSeconds: EXPIRY});
@@ -107,7 +107,12 @@ const getAwsVoices = async(_client, createHash, retrieveHash, logger, credential
107
107
  } else if (roleArn) {
108
108
  client = new PollyClient({
109
109
  region,
110
- credentials: await getAwsAuthToken(logger, createHash, retrieveHash, null, null, region, roleArn),
110
+ credentials: await getAwsAuthToken(
111
+ logger, createHash, retrieveHash,
112
+ {
113
+ region,
114
+ roleArn
115
+ }),
111
116
  });
112
117
  } else {
113
118
  client = new PollyClient({region});
@@ -40,6 +40,7 @@ const {AudioEncoding} = require('../stubs/riva/proto/riva_audio_pb');
40
40
  const debug = require('debug')('jambonz:realtimedb-helpers');
41
41
  const {
42
42
  JAMBONES_DISABLE_TTS_STREAMING,
43
+ JAMBONES_DISABLE_AZURE_TTS_STREAMING,
43
44
  JAMBONES_HTTP_PROXY_IP,
44
45
  JAMBONES_HTTP_PROXY_PORT,
45
46
  JAMBONES_TTS_CACHE_DURATION_MINS,
@@ -280,7 +281,12 @@ const synthPolly = async(createHash, retrieveHash, logger,
280
281
  } else if (roleArn) {
281
282
  polly = new PollyClient({
282
283
  region,
283
- credentials: await getAwsAuthToken(logger, createHash, retrieveHash, null, null, region, roleArn),
284
+ credentials: await getAwsAuthToken(
285
+ logger, createHash, retrieveHash,
286
+ {
287
+ region,
288
+ roleArn
289
+ }),
284
290
  });
285
291
  } else {
286
292
  // AWS RoleArn assigned to Instance profile
@@ -443,7 +449,8 @@ const synthMicrosoft = async(logger, {
443
449
  content = `<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="https://www.w3.org/2001/mstts" xml:lang="${language}"><voice name="${voice}">${words}</voice></speak>`;
444
450
  logger.info({content}, 'synthMicrosoft');
445
451
  }
446
- if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
452
+ if (!JAMBONES_DISABLE_TTS_STREAMING && !JAMBONES_DISABLE_AZURE_TTS_STREAMING &&
453
+ !renderForCaching && !disableTtsStreaming) {
447
454
  let params = '';
448
455
  params += `{api_key=${apiKey}`;
449
456
  params += `,language=${language}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jambonz/speech-utils",
3
- "version": "0.1.8",
3
+ "version": "0.1.11",
4
4
  "description": "TTS-related speech utilities for jambonz",
5
5
  "main": "index.js",
6
6
  "author": "Dave Horton",
package/test/aws.js CHANGED
@@ -19,12 +19,20 @@ test('AWS - create and cache auth token', async(t) => {
19
19
  return;
20
20
  }
21
21
  try {
22
- let obj = await getAwsAuthToken(process.env.AWS_ACCESS_KEY_ID, process.env.AWS_SECRET_ACCESS_KEY, process.env.AWS_REGION);
22
+ let obj = await getAwsAuthToken({
23
+ accessKeyId: process.env.AWS_ACCESS_KEY_ID,
24
+ secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
25
+ region: process.env.AWS_REGION
26
+ });
23
27
  //console.log({obj}, 'received auth token from AWS');
24
28
  t.ok(obj.securityToken && !obj.servedFromCache, 'successfullY generated auth token from AWS');
25
29
 
26
30
  await sleep(250);
27
- obj = await getAwsAuthToken(process.env.AWS_ACCESS_KEY_ID, process.env.AWS_SECRET_ACCESS_KEY, process.env.AWS_REGION);
31
+ obj = await getAwsAuthToken({
32
+ accessKeyId: process.env.AWS_ACCESS_KEY_ID,
33
+ secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
34
+ region: process.env.AWS_REGION
35
+ });
28
36
  //console.log({obj}, 'received auth token from AWS - second request');
29
37
  t.ok(obj.securityToken && obj.servedFromCache, 'successfully received access token from cache');
30
38