@creativeorange/azure-text-to-speech 1.2.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -8428,7 +8428,7 @@ class SpeechToText {
8428
8428
  }
8429
8429
  }
8430
8430
  class TextToSpeech {
8431
- constructor(key, region, voice, rate = 0, pitch = 0) {
8431
+ constructor(key, region, voice, rate = 0, pitch = 0, url = "") {
8432
8432
  __publicField(this, "key");
8433
8433
  __publicField(this, "region");
8434
8434
  __publicField(this, "voice");
@@ -8449,12 +8449,14 @@ class TextToSpeech {
8449
8449
  __publicField(this, "currentWord", "");
8450
8450
  __publicField(this, "currentOffset", 0);
8451
8451
  __publicField(this, "wordBoundaryOffset", 0);
8452
- __publicField(this, "privTextOffset", 0);
8452
+ __publicField(this, "prevTextOffset", 0);
8453
+ __publicField(this, "url", "");
8453
8454
  this.key = key;
8454
8455
  this.region = region;
8455
8456
  this.voice = voice;
8456
8457
  this.rate = rate;
8457
8458
  this.pitch = pitch;
8459
+ this.url = url;
8458
8460
  }
8459
8461
  async start() {
8460
8462
  await this.registerBindings(document);
@@ -8621,7 +8623,7 @@ class TextToSpeech {
8621
8623
  }
8622
8624
  this.player = void 0;
8623
8625
  this.highlightDiv = void 0;
8624
- this.privTextOffset = 0;
8626
+ this.prevTextOffset = 0;
8625
8627
  }
8626
8628
  async startSynthesizer(node, attr) {
8627
8629
  this.speechConfig = SpeechConfig.fromSubscription(this.key, this.region);
@@ -8681,13 +8683,13 @@ class TextToSpeech {
8681
8683
  if (~[".", ",", "!", "?", "*", "(", ")", "&", "\\", "/", "^", "[", "]", "<", ">", ":"].indexOf(wordBoundary.text)) {
8682
8684
  wordBoundary = (_a = this.previousWordBoundary) != null ? _a : void 0;
8683
8685
  }
8684
- if (wordBoundary === void 0 || this.privTextOffset > wordBoundary.privTextOffset) {
8686
+ if (wordBoundary === void 0 || this.prevTextOffset > wordBoundary.prevTextOffset) {
8685
8687
  this.highlightDiv.innerHTML = this.originalHighlightDivInnerHTML;
8686
8688
  } else {
8687
8689
  if (!this.wordEncounters[wordBoundary.text]) {
8688
8690
  this.wordEncounters[wordBoundary.text] = 0;
8689
8691
  }
8690
- this.privTextOffset = wordBoundary.privTextOffset;
8692
+ this.prevTextOffset = wordBoundary.prevTextOffset;
8691
8693
  if (this.currentWord !== wordBoundary.text || this.wordBoundaryOffset !== wordBoundary.textOffset) {
8692
8694
  this.currentOffset = this.getPosition(
8693
8695
  this.originalHighlightDivInnerHTML,
@@ -8726,17 +8728,17 @@ class TextToSpeech {
8726
8728
  return newOffset;
8727
8729
  }
8728
8730
  buildSSML(text) {
8729
- return `<speak xmlns="http://www.w3.org/2001/10/synthesis"
8731
+ let ssml = `<speak xmlns="http://www.w3.org/2001/10/synthesis"
8730
8732
  xmlns:mstts="http://www.w3.org/2001/mstts"
8731
8733
  xmlns:emo="http://www.w3.org/2009/10/emotionml"
8732
8734
  version="1.0"
8733
8735
  xml:lang="en-US">
8734
- <voice name="${this.voice}">
8735
- <prosody rate="${this.rate}%" pitch="${this.pitch}%">
8736
- ${text}
8737
- </prosody>
8738
- </voice>
8739
- </speak>`;
8736
+ <voice name="${this.voice}">`;
8737
+ if (this.url !== "") {
8738
+ ssml += `<lexicon uri="${this.url}"/>`;
8739
+ }
8740
+ ssml += `<prosody rate="${this.rate}%" pitch="${this.pitch}%">${text}</prosody></voice></speak>`;
8741
+ return ssml;
8740
8742
  }
8741
8743
  }
8742
8744
  export { SpeechToText, TextToSpeech };