@jambonz/speech-utils 0.0.21 → 0.0.23

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}));
@@ -253,7 +257,8 @@ const synthGoogle = async(logger, {credentials, stats, language, voice, gender,
253
257
  const client = new ttsGoogle.TextToSpeechClient(credentials);
254
258
  const opts = {
255
259
  voice: {
256
- name: voice,
260
+ ...(typeof voice === 'string' && {name: voice}),
261
+ ...(typeof voice === 'object' && {custom_voice: voice}),
257
262
  languageCode: language,
258
263
  ssmlGender: gender || 'SSML_VOICE_GENDER_UNSPECIFIED'
259
264
  },
@@ -568,6 +573,29 @@ const synthCustomVendor = async(logger, {credentials, stats, language, voice, te
568
573
  }
569
574
  };
570
575
 
576
+ const synthElevenlabs = async(logger, {credentials, stats, language, voice, text}) => {
577
+ const {api_key, model_id} = credentials;
578
+ try {
579
+ const post = bent('https://api.elevenlabs.io', 'POST', 'buffer', {
580
+ 'xi-api-key': api_key,
581
+ 'Accept': 'audio/mpeg',
582
+ 'Content-Type': 'application/json'
583
+ });
584
+ const mp3 = await post(`/v1/text-to-speech/${voice}`, {
585
+ text,
586
+ model_id,
587
+ voice_settings: {
588
+ stability: 0.5,
589
+ similarity_boost: 0.5
590
+ }
591
+ });
592
+ return mp3;
593
+ } catch (err) {
594
+ logger.info({err}, 'synthEvenlabs returned error');
595
+ throw err;
596
+ }
597
+ };
598
+
571
599
  const getFileExtFromMime = (mime) => {
572
600
  switch (mime) {
573
601
  case 'audio/wav':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jambonz/speech-utils",
3
- "version": "0.0.21",
3
+ "version": "0.0.23",
4
4
  "description": "TTS-related speech utilities for jambonz",
5
5
  "main": "index.js",
6
6
  "author": "Dave Horton",
package/test/synth.js CHANGED
@@ -79,6 +79,40 @@ test('Google speech synth tests', async(t) => {
79
79
  client.quit();
80
80
  });
81
81
 
82
+ test('Google speech Custom voice synth tests', async(t) => {
83
+ const fn = require('..');
84
+ const {synthAudio, client} = fn(opts, logger);
85
+
86
+ if (!process.env.GCP_CUSTOM_VOICE_FILE && !process.env.GCP_CUSTOM_VOICE_JSON_KEY || !process.env.GCP_CUSTOM_VOICE_MODEL) {
87
+ t.pass('skipping google speech synth tests since neither GCP_CUSTOM_VOICE_FILE nor GCP_CUSTOM_VOICE_JSON_KEY provided, GCP_CUSTOM_VOICE_MODEL is not provided');
88
+ return t.end();
89
+ }
90
+ try {
91
+ const str = process.env.GCP_CUSTOM_VOICE_JSON_KEY || fs.readFileSync(process.env.GCP_CUSTOM_VOICE_FILE);
92
+ const creds = JSON.parse(str);
93
+ let opts = await synthAudio(stats, {
94
+ vendor: 'google',
95
+ credentials: {
96
+ credentials: {
97
+ client_email: creds.client_email,
98
+ private_key: creds.private_key,
99
+ },
100
+ },
101
+ language: 'en-AU',
102
+ text: 'This is a test. This is only a test',
103
+ voice: {
104
+ reportedUsage:"REALTIME",
105
+ model: process.env.GCP_CUSTOM_VOICE_MODEL
106
+ }
107
+ });
108
+ t.ok(!opts.servedFromCache, `successfully synthesized google custom voice audio to ${opts.filePath}`);
109
+ } catch (err) {
110
+ console.error(err);
111
+ t.end(err);
112
+ }
113
+ client.quit();
114
+ });
115
+
82
116
  test('AWS speech synth tests', async(t) => {
83
117
  const fn = require('..');
84
118
  const {synthAudio, client} = fn(opts, logger);
@@ -411,6 +445,35 @@ test('Custom Vendor speech synth tests', async(t) => {
411
445
  client.quit();
412
446
  });
413
447
 
448
+ test('Elevenlabs speech synth tests', async(t) => {
449
+ const fn = require('..');
450
+ const {synthAudio, client} = fn(opts, logger);
451
+
452
+ if (!process.env.ELEVENLABS_API_KEY || !process.env.ELEVENLABS_VOICE_ID || !process.env.ELEVENLABS_MODEL_ID) {
453
+ t.pass('skipping IBM Watson speech synth tests since IBM_TTS_API_KEY or IBM_TTS_API_KEY not provided');
454
+ return t.end();
455
+ }
456
+ const text = 'Hi there and welcome to jambones!';
457
+ try {
458
+ let opts = await synthAudio(stats, {
459
+ vendor: 'elevenlabs',
460
+ credentials: {
461
+ api_key: process.env.ELEVENLABS_API_KEY,
462
+ model_id: process.env.ELEVENLABS_MODEL_ID
463
+ },
464
+ language: 'en-US',
465
+ voice: process.env.ELEVENLABS_VOICE_ID,
466
+ text,
467
+ });
468
+ t.ok(!opts.servedFromCache, `successfully synthesized eleven audio to ${opts.filePath}`);
469
+
470
+ } catch (err) {
471
+ console.error(JSON.stringify(err));
472
+ t.end(err);
473
+ }
474
+ client.quit();
475
+ })
476
+
414
477
  test('TTS Cache tests', async(t) => {
415
478
  const fn = require('..');
416
479
  const {purgeTtsCache, getTtsSize, client} = fn(opts, logger);