tsbase
Version:
Base class libraries for TypeScript
22 lines • 860 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SpeechSynthesizer = void 0;
class SpeechSynthesizer {
constructor(ss = globalThis.speechSynthesis) {
this.ss = ss;
if (!ss) {
throw new Error('Speech synthesis is unavailable on this device.');
}
}
async Speak(phrase, voice, utteranceFactory = (phrase) => new SpeechSynthesisUtterance(phrase)) {
return new Promise((resolve) => {
const utterance = typeof phrase === 'string' ?
utteranceFactory(phrase) : phrase;
utterance.voice = utterance.voice || voice || this.ss.getVoices()[0];
utterance.onend = () => resolve();
this.ss.speak(utterance);
});
}
}
exports.SpeechSynthesizer = SpeechSynthesizer;
//# sourceMappingURL=SpeechSynthesizer.js.map