@jambonz/speech-utils 0.2.10 → 0.2.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
@@ -2,6 +2,7 @@ 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
3
  const JAMBONES_DISABLE_AZURE_TTS_STREAMING = process.env.JAMBONES_DISABLE_AZURE_TTS_STREAMING;
4
4
  const JAMBONES_EAGERLY_PRE_CACHE_AUDIO = process.env.JAMBONES_EAGERLY_PRE_CACHE_AUDIO;
5
+ const JAMBONES_AZURE_ENABLE_SSML = process.env.JAMBONES_AZURE_ENABLE_SSML;
5
6
 
6
7
  const JAMBONES_HTTP_PROXY_IP = process.env.JAMBONES_HTTP_PROXY_IP;
7
8
  const JAMBONES_HTTP_PROXY_PORT = process.env.JAMBONES_HTTP_PROXY_PORT;
@@ -21,5 +22,6 @@ module.exports = {
21
22
  JAMBONES_TTS_CACHE_DURATION_MINS,
22
23
  JAMBONES_EAGERLY_PRE_CACHE_AUDIO,
23
24
  TMP_FOLDER,
24
- HTTP_TIMEOUT
25
+ HTTP_TIMEOUT,
26
+ JAMBONES_AZURE_ENABLE_SSML
25
27
  };
@@ -47,6 +47,7 @@ const {
47
47
  JAMBONES_HTTP_PROXY_PORT,
48
48
  JAMBONES_TTS_CACHE_DURATION_MINS,
49
49
  JAMBONES_TTS_TRIM_SILENCE,
50
+ JAMBONES_AZURE_ENABLE_SSML
50
51
  } = require('./config');
51
52
  const EXPIRES = JAMBONES_TTS_CACHE_DURATION_MINS;
52
53
  const OpenAI = require('openai');
@@ -466,7 +467,6 @@ async function _synthOnPremMicrosoft(logger, {
466
467
  }) {
467
468
  const {use_custom_tts, custom_tts_endpoint_url, api_key} = credentials;
468
469
  let content = text;
469
-
470
470
  if (use_custom_tts && !content.startsWith('<speak')) {
471
471
  /**
472
472
  * Note: it seems that to use custom voice ssml is required with the voice attribute
@@ -479,9 +479,13 @@ async function _synthOnPremMicrosoft(logger, {
479
479
  /* microsoft enforces some properties and uses voice xml element so if the user did not supply do it for them */
480
480
  const words = content.slice(7, -8).trim().replace(/(\r\n|\n|\r)/gm, ' ');
481
481
  // eslint-disable-next-line max-len
482
- 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>`;
482
+ content = `<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="https://www.w3.org/2001/mstts" xml:lang="${language}"><lang xml:lang="${language}"><voice name="${voice}">${words}</voice></lang></speak>`;
483
483
  logger.info({content}, 'synthMicrosoft');
484
484
  }
485
+ else if (JAMBONES_AZURE_ENABLE_SSML) {
486
+ // eslint-disable-next-line max-len
487
+ 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}"><lang xml:lang="${language}">${text}</lang></voice></speak>`;
488
+ }
485
489
 
486
490
  try {
487
491
  const trimSilence = JAMBONES_TTS_TRIM_SILENCE;
@@ -518,19 +522,23 @@ const synthMicrosoft = async(logger, {
518
522
  let content = text;
519
523
  if (use_custom_tts && !content.startsWith('<speak')) {
520
524
  /**
521
- * Note: it seems that to use custom voice ssml is required with the voice attribute
522
- * Otherwise sending plain text we get "Voice does not match"
523
- */
525
+ * Note: it seems that to use custom voice ssml is required with the voice attribute
526
+ * Otherwise sending plain text we get "Voice does not match"
527
+ */
524
528
  content = `<speak>${text}</speak>`;
525
529
  }
526
530
 
527
531
  if (content.startsWith('<speak>')) {
528
- /* microsoft enforces some properties and uses voice xml element so if the user did not supply do it for them */
532
+ /* microsoft enforces some properties and uses voice xml element so if the user did not supply do it for them */
529
533
  const words = content.slice(7, -8).trim().replace(/(\r\n|\n|\r)/gm, ' ');
530
534
  // eslint-disable-next-line max-len
531
- 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>`;
535
+ content = `<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="https://www.w3.org/2001/mstts" xml:lang="${language}"><lang xml:lang="${language}"><voice name="${voice}">${words}</voice></lang></speak>`;
532
536
  logger.info({content}, 'synthMicrosoft');
533
537
  }
538
+ else if (JAMBONES_AZURE_ENABLE_SSML) {
539
+ // eslint-disable-next-line max-len
540
+ 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}"><lang xml:lang="${language}">${text}</lang></voice></speak>`;
541
+ }
534
542
  if (!JAMBONES_DISABLE_TTS_STREAMING && !JAMBONES_DISABLE_AZURE_TTS_STREAMING &&
535
543
  !renderForCaching && !disableTtsStreaming) {
536
544
  let params = '';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jambonz/speech-utils",
3
- "version": "0.2.10",
3
+ "version": "0.2.11",
4
4
  "description": "TTS-related speech utilities for jambonz",
5
5
  "main": "index.js",
6
6
  "author": "Dave Horton",