@jambonz/speech-utils 0.0.20 → 0.0.22

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.
@@ -82,7 +82,8 @@ async function synthAudio(client, logger, stats, { account_sid,
82
82
  let rtt;
83
83
  logger = logger || noopLogger;
84
84
 
85
- assert.ok(['google', 'aws', 'polly', 'microsoft', 'wellsaid', 'nuance', 'nvidia', 'ibm'].includes(vendor) ||
85
+ assert.ok(['google', 'aws', 'polly', 'microsoft',
86
+ 'wellsaid', 'nuance', 'nvidia', 'ibm', 'elevenlabs'].includes(vendor) ||
86
87
  vendor.startsWith('custom'),
87
88
  `synthAudio supported vendors are google, aws, microsoft, nuance, nvidia and wellsaid, not ${vendor}`);
88
89
  if ('google' === vendor) {
@@ -183,6 +184,9 @@ async function synthAudio(client, logger, stats, { account_sid,
183
184
  case 'wellsaid':
184
185
  audioBuffer = await synthWellSaid(logger, {credentials, stats, language, voice, text, filePath});
185
186
  break;
187
+ case 'elevenlabs':
188
+ audioBuffer = await synthElevenlabs(logger, {credentials, stats, language, voice, text, filePath});
189
+ break;
186
190
  case vendor.startsWith('custom') ? vendor : 'cant_match_value':
187
191
  ({ audioBuffer, filePath } = await synthCustomVendor(logger,
188
192
  {credentials, stats, language, voice, text, filePath}));
@@ -331,8 +335,9 @@ async function _synthOnPremMicrosoft(logger, {
331
335
  }
332
336
 
333
337
  try {
338
+ const trimSilence = filePath.endsWith('.r8');
334
339
  const post = bent('POST', 'buffer', {
335
- 'X-Microsoft-OutputFormat': 'audio-16khz-128kbitrate-mono-mp3',
340
+ 'X-Microsoft-OutputFormat': trimSilence ? 'raw-8khz-16bit-mono-pcm' : 'audio-16khz-32kbitrate-mono-mp3',
336
341
  'Content-Type': 'application/ssml+xml',
337
342
  'User-Agent': 'Jambonz'
338
343
  });
@@ -567,6 +572,29 @@ const synthCustomVendor = async(logger, {credentials, stats, language, voice, te
567
572
  }
568
573
  };
569
574
 
575
+ const synthElevenlabs = async(logger, {credentials, stats, language, voice, text}) => {
576
+ const {api_key, model_id} = credentials;
577
+ try {
578
+ const post = bent('https://api.elevenlabs.io', 'POST', 'buffer', {
579
+ 'xi-api-key': api_key,
580
+ 'Accept': 'audio/mpeg',
581
+ 'Content-Type': 'application/json'
582
+ });
583
+ const mp3 = await post(`/v1/text-to-speech/${voice}`, {
584
+ text,
585
+ model_id,
586
+ voice_settings: {
587
+ stability: 0.5,
588
+ similarity_boost: 0.5
589
+ }
590
+ });
591
+ return mp3;
592
+ } catch (err) {
593
+ logger.info({err}, 'synthEvenlabs returned error');
594
+ throw err;
595
+ }
596
+ };
597
+
570
598
  const getFileExtFromMime = (mime) => {
571
599
  switch (mime) {
572
600
  case 'audio/wav':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jambonz/speech-utils",
3
- "version": "0.0.20",
3
+ "version": "0.0.22",
4
4
  "description": "TTS-related speech utilities for jambonz",
5
5
  "main": "index.js",
6
6
  "author": "Dave Horton",
package/test/synth.js CHANGED
@@ -411,6 +411,35 @@ test('Custom Vendor speech synth tests', async(t) => {
411
411
  client.quit();
412
412
  });
413
413
 
414
+ test('Elevenlabs speech synth tests', async(t) => {
415
+ const fn = require('..');
416
+ const {synthAudio, client} = fn(opts, logger);
417
+
418
+ if (!process.env.ELEVENLABS_API_KEY || !process.env.ELEVENLABS_VOICE_ID || !process.env.ELEVENLABS_MODEL_ID) {
419
+ t.pass('skipping IBM Watson speech synth tests since IBM_TTS_API_KEY or IBM_TTS_API_KEY not provided');
420
+ return t.end();
421
+ }
422
+ const text = 'Hi there and welcome to jambones!';
423
+ try {
424
+ let opts = await synthAudio(stats, {
425
+ vendor: 'elevenlabs',
426
+ credentials: {
427
+ api_key: process.env.ELEVENLABS_API_KEY,
428
+ model_id: process.env.ELEVENLABS_MODEL_ID
429
+ },
430
+ language: 'en-US',
431
+ voice: process.env.ELEVENLABS_VOICE_ID,
432
+ text,
433
+ });
434
+ t.ok(!opts.servedFromCache, `successfully synthesized eleven audio to ${opts.filePath}`);
435
+
436
+ } catch (err) {
437
+ console.error(JSON.stringify(err));
438
+ t.end(err);
439
+ }
440
+ client.quit();
441
+ })
442
+
414
443
  test('TTS Cache tests', async(t) => {
415
444
  const fn = require('..');
416
445
  const {purgeTtsCache, getTtsSize, client} = fn(opts, logger);