@jambonz/speech-utils 0.0.28 → 0.0.30

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.
@@ -27,7 +27,7 @@ async function getAwsAuthToken(
27
27
  const credentials = {
28
28
  accessKeyId: data.Credentials.AccessKeyId,
29
29
  secretAccessKey: data.Credentials.SecretAccessKey,
30
- sessionToken: data.Credentials.SessionToken
30
+ securityToken: data.Credentials.SessionToken
31
31
  };
32
32
 
33
33
  /* expire 10 minutes before the hour, so we don't lose the use of it during a call */
@@ -76,7 +76,7 @@ const trimTrailingSilence = (buffer) => {
76
76
  * the synthesized audio, and a variable indicating whether it was served from cache
77
77
  */
78
78
  async function synthAudio(client, logger, stats, { account_sid,
79
- vendor, language, voice, gender, text, engine, salt, model, credentials, deploymentId, disableTtsCache
79
+ vendor, language, voice, gender, text, engine, salt, model, credentials, deploymentId, disableTtsCache, options
80
80
  }) {
81
81
  let audioBuffer;
82
82
  let servedFromCache = false;
@@ -194,7 +194,7 @@ async function synthAudio(client, logger, stats, { account_sid,
194
194
  audioBuffer = await synthWellSaid(logger, {credentials, stats, language, voice, text, filePath});
195
195
  break;
196
196
  case 'elevenlabs':
197
- audioBuffer = await synthElevenlabs(logger, {credentials, stats, language, voice, text, filePath});
197
+ audioBuffer = await synthElevenlabs(logger, {credentials, options, stats, language, voice, text, filePath});
198
198
  break;
199
199
  case 'whisper':
200
200
  audioBuffer = await synthWhisper(logger, {credentials, stats, voice, text});
@@ -585,21 +585,25 @@ const synthCustomVendor = async(logger, {credentials, stats, language, voice, te
585
585
  }
586
586
  };
587
587
 
588
- const synthElevenlabs = async(logger, {credentials, stats, language, voice, text}) => {
589
- const {api_key, model_id} = credentials;
588
+ const synthElevenlabs = async(logger, {credentials, options, stats, language, voice, text}) => {
589
+ const {api_key, model_id, options: credOpts} = credentials;
590
+ const opts = !!options && Object.keys(options).length !== 0 ? options : JSON.parse(credOpts || '{}');
591
+ const optimize_streaming_latency = opts.optimize_streaming_latency ?
592
+ `?optimize_streaming_latency=${opts.optimize_streaming_latency}` : '';
590
593
  try {
591
594
  const post = bent('https://api.elevenlabs.io', 'POST', 'buffer', {
592
595
  'xi-api-key': api_key,
593
596
  'Accept': 'audio/mpeg',
594
597
  'Content-Type': 'application/json'
595
598
  });
596
- const mp3 = await post(`/v1/text-to-speech/${voice}`, {
599
+ const mp3 = await post(`/v1/text-to-speech/${voice}${optimize_streaming_latency}`, {
597
600
  text,
598
601
  model_id,
599
602
  voice_settings: {
600
603
  stability: 0.5,
601
604
  similarity_boost: 0.5
602
- }
605
+ },
606
+ ...opts
603
607
  });
604
608
  return mp3;
605
609
  } catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jambonz/speech-utils",
3
- "version": "0.0.28",
3
+ "version": "0.0.30",
4
4
  "description": "TTS-related speech utilities for jambonz",
5
5
  "main": "index.js",
6
6
  "author": "Dave Horton",
package/test/aws.js CHANGED
@@ -21,12 +21,12 @@ test('AWS - create and cache auth token', async(t) => {
21
21
  try {
22
22
  let obj = await getAwsAuthToken(process.env.AWS_ACCESS_KEY_ID, process.env.AWS_SECRET_ACCESS_KEY, process.env.AWS_REGION);
23
23
  //console.log({obj}, 'received auth token from AWS');
24
- t.ok(obj.sessionToken && !obj.servedFromCache, 'successfullY generated auth token from AWS');
24
+ t.ok(obj.securityToken && !obj.servedFromCache, 'successfullY generated auth token from AWS');
25
25
 
26
26
  await sleep(250);
27
27
  obj = await getAwsAuthToken(process.env.AWS_ACCESS_KEY_ID, process.env.AWS_SECRET_ACCESS_KEY, process.env.AWS_REGION);
28
28
  //console.log({obj}, 'received auth token from AWS - second request');
29
- t.ok(obj.sessionToken && obj.servedFromCache, 'successfully received access token from cache');
29
+ t.ok(obj.securityToken && obj.servedFromCache, 'successfully received access token from cache');
30
30
 
31
31
  await client.flushall();
32
32
  t.end();
package/test/synth.js CHANGED
@@ -459,7 +459,16 @@ test('Elevenlabs speech synth tests', async(t) => {
459
459
  vendor: 'elevenlabs',
460
460
  credentials: {
461
461
  api_key: process.env.ELEVENLABS_API_KEY,
462
- model_id: process.env.ELEVENLABS_MODEL_ID
462
+ model_id: process.env.ELEVENLABS_MODEL_ID,
463
+ options: JSON.stringify({
464
+ optimize_streaming_latency: 1,
465
+ voice_settings: {
466
+ similarity_boost: 1,
467
+ stability: 0.8,
468
+ style: 1,
469
+ use_speaker_boost: true
470
+ }
471
+ })
463
472
  },
464
473
  language: 'en-US',
465
474
  voice: process.env.ELEVENLABS_VOICE_ID,