UNPKG

tsbase

Version:

Base class libraries for TypeScript

31 lines 1.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SpeechSynthesizer = void 0; var tslib_1 = require("tslib"); var SpeechSynthesizer = /** @class */ (function () { function SpeechSynthesizer(ss) { if (ss === void 0) { ss = globalThis.speechSynthesis; } this.ss = ss; if (!ss) { throw new Error('Speech synthesis is unavailable on this device.'); } } SpeechSynthesizer.prototype.Speak = function (phrase, voice, utteranceFactory) { if (utteranceFactory === void 0) { utteranceFactory = function (phrase) { return new SpeechSynthesisUtterance(phrase); }; } return tslib_1.__awaiter(this, void 0, void 0, function () { var _this = this; return tslib_1.__generator(this, function (_a) { return [2 /*return*/, new Promise(function (resolve) { var utterance = typeof phrase === 'string' ? utteranceFactory(phrase) : phrase; utterance.voice = utterance.voice || voice || _this.ss.getVoices()[0]; utterance.onend = function () { return resolve(); }; _this.ss.speak(utterance); })]; }); }); }; return SpeechSynthesizer; }()); exports.SpeechSynthesizer = SpeechSynthesizer; //# sourceMappingURL=SpeechSynthesizer.js.map