@ztimson/utils 0.28.10 → 0.28.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/dist/index.cjs +7 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +7 -9
- package/dist/index.mjs.map +1 -1
- package/dist/tts.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2535,7 +2535,7 @@ class TTS {
|
|
|
2535
2535
|
static QUALITY_PATTERNS = ["Google", "Microsoft", "Samantha", "Premium", "Natural", "Neural"];
|
|
2536
2536
|
_currentUtterance = null;
|
|
2537
2537
|
_voicesLoaded;
|
|
2538
|
-
|
|
2538
|
+
_stoppedUtterances = /* @__PURE__ */ new WeakSet();
|
|
2539
2539
|
_rate = 1;
|
|
2540
2540
|
get rate() {
|
|
2541
2541
|
return this._rate;
|
|
@@ -2629,26 +2629,24 @@ class TTS {
|
|
|
2629
2629
|
await this._voicesLoaded;
|
|
2630
2630
|
return new Promise((resolve, reject) => {
|
|
2631
2631
|
this._currentUtterance = this.createUtterance(text);
|
|
2632
|
-
this._currentUtterance
|
|
2632
|
+
const utterance = this._currentUtterance;
|
|
2633
|
+
utterance.onend = () => {
|
|
2633
2634
|
this._currentUtterance = null;
|
|
2634
2635
|
resolve();
|
|
2635
2636
|
};
|
|
2636
|
-
|
|
2637
|
+
utterance.onerror = (error) => {
|
|
2637
2638
|
this._currentUtterance = null;
|
|
2638
|
-
if (this.
|
|
2639
|
+
if (this._stoppedUtterances.has(utterance) && error.error === "interrupted") resolve();
|
|
2639
2640
|
else reject(error);
|
|
2640
2641
|
};
|
|
2641
|
-
window.speechSynthesis.speak(
|
|
2642
|
+
window.speechSynthesis.speak(utterance);
|
|
2642
2643
|
});
|
|
2643
2644
|
}
|
|
2644
2645
|
/** Stops all TTS */
|
|
2645
2646
|
stop() {
|
|
2646
|
-
this.
|
|
2647
|
+
if (this._currentUtterance) this._stoppedUtterances.add(this._currentUtterance);
|
|
2647
2648
|
window.speechSynthesis.cancel();
|
|
2648
2649
|
this._currentUtterance = null;
|
|
2649
|
-
setTimeout(() => {
|
|
2650
|
-
this._isStopping = false;
|
|
2651
|
-
}, 0);
|
|
2652
2650
|
}
|
|
2653
2651
|
/**
|
|
2654
2652
|
* Initialize a stream that chunks text into sentences and speak them.
|