@jambonz/speech-utils 0.0.32 → 0.0.33

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.
@@ -84,7 +84,7 @@ async function synthAudio(client, logger, stats, { account_sid,
84
84
  logger = logger || noopLogger;
85
85
 
86
86
  assert.ok(['google', 'aws', 'polly', 'microsoft',
87
- 'wellsaid', 'nuance', 'nvidia', 'ibm', 'elevenlabs', 'whisper'].includes(vendor) ||
87
+ 'wellsaid', 'nuance', 'nvidia', 'ibm', 'elevenlabs', 'whisper', 'deepgram'].includes(vendor) ||
88
88
  vendor.startsWith('custom'),
89
89
  `synthAudio supported vendors are google, aws, microsoft, nuance, nvidia and wellsaid, not ${vendor}`);
90
90
  if ('google' === vendor) {
@@ -199,6 +199,9 @@ async function synthAudio(client, logger, stats, { account_sid,
199
199
  case 'whisper':
200
200
  audioBuffer = await synthWhisper(logger, {credentials, stats, voice, text});
201
201
  break;
202
+ case 'deepgram':
203
+ audioBuffer = await synthDeepgram(logger, {credentials, stats, model, text});
204
+ break;
202
205
  case vendor.startsWith('custom') ? vendor : 'cant_match_value':
203
206
  ({ audioBuffer, filePath } = await synthCustomVendor(logger,
204
207
  {credentials, stats, language, voice, text, filePath}));
@@ -640,8 +643,27 @@ const synthWhisper = async(logger, {credentials, stats, voice, text}) => {
640
643
  stats.increment('tts.count', ['vendor:openai', 'accepted:no']);
641
644
  throw err;
642
645
  }
643
- }
644
- ;
646
+ };
647
+
648
+ const synthDeepgram = async(logger, {credentials, stats, model, text}) => {
649
+ const {api_key} = credentials;
650
+ try {
651
+ const post = bent('https://api.beta.deepgram.com', 'POST', 'buffer', {
652
+ 'Authorization': `Token ${api_key}`,
653
+ 'Accept': 'audio/mpeg',
654
+ 'Content-Type': 'application/json'
655
+ });
656
+ const mp3 = await post(`/v1/speak?model=${model}`, {
657
+ text
658
+ });
659
+ return mp3;
660
+ } catch (err) {
661
+ logger.info({err}, 'synth Deepgram returned error');
662
+ stats.increment('tts.count', ['vendor:deepgram', 'accepted:no']);
663
+ throw err;
664
+ }
665
+ };
666
+
645
667
  const getFileExtFromMime = (mime) => {
646
668
  switch (mime) {
647
669
  case 'audio/wav':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jambonz/speech-utils",
3
- "version": "0.0.32",
3
+ "version": "0.0.33",
4
4
  "description": "TTS-related speech utilities for jambonz",
5
5
  "main": "index.js",
6
6
  "author": "Dave Horton",
package/test/synth.js CHANGED
@@ -514,6 +514,33 @@ test('whisper speech synth tests', async(t) => {
514
514
  client.quit();
515
515
  })
516
516
 
517
+ test('Deepgram speech synth tests', async(t) => {
518
+ const fn = require('..');
519
+ const {synthAudio, client} = fn(opts, logger);
520
+
521
+ if (!process.env.DEEPGRAM_API_KEY) {
522
+ t.pass('skipping Deepgram speech synth tests since DEEPGRAM_API_KEY');
523
+ return t.end();
524
+ }
525
+ const text = 'Hi there and welcome to jambones!';
526
+ try {
527
+ let opts = await synthAudio(stats, {
528
+ vendor: 'deepgram',
529
+ credentials: {
530
+ api_key: process.env.DEEPGRAM_API_KEY
531
+ },
532
+ model: 'alpha-asteria-en-v2',
533
+ text,
534
+ });
535
+ t.ok(!opts.servedFromCache, `successfully synthesized deepgram audio to ${opts.filePath}`);
536
+
537
+ } catch (err) {
538
+ console.error(JSON.stringify(err));
539
+ t.end(err);
540
+ }
541
+ client.quit();
542
+ })
543
+
517
544
  test('TTS Cache tests', async(t) => {
518
545
  const fn = require('..');
519
546
  const {purgeTtsCache, getTtsSize, client} = fn(opts, logger);