one
Version:
One is a React framework for web, iOS, and Android apps.
102 lines (99 loc) • 3.75 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all) __defProp(target, name, {
get: all[name],
enumerable: true
});
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: () => from[key],
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var index_native_exports = {};
__export(index_native_exports, { SpeechSynthesis: () => SpeechSynthesis });
module.exports = __toCommonJS(index_native_exports);
var import_react_native_nitro_modules = require("react-native-nitro-modules");
var import_nativeError = require("../nativeError.native.js");
var import_validate = require("./validate.native.js");
var hybrid;
function native() {
hybrid !== null && hybrid !== void 0 ? hybrid : hybrid = import_react_native_nitro_modules.NitroModules.createHybridObject("OneSpeechSynthesis");
return hybrid;
}
function readMaxInputLength() {
if (!import_react_native_nitro_modules.NitroModules.hasHybridObject("OneSpeechSynthesis")) return 0;
return native().maxInputLength;
}
function dispatch(options, event) {
switch (event.type) {
case "start":
var _options_onStart;
options === null || options === void 0 ? void 0 : (_options_onStart = options.onStart) === null || _options_onStart === void 0 ? void 0 : _options_onStart.call(options);
break;
case "done":
var _options_onDone;
options === null || options === void 0 ? void 0 : (_options_onDone = options.onDone) === null || _options_onDone === void 0 ? void 0 : _options_onDone.call(options);
break;
case "stopped":
var _options_onStopped;
options === null || options === void 0 ? void 0 : (_options_onStopped = options.onStopped) === null || _options_onStopped === void 0 ? void 0 : _options_onStopped.call(options);
break;
case "error":
var _event_message;
var _options_onError;
options === null || options === void 0 ? void 0 : (_options_onError = options.onError) === null || _options_onError === void 0 ? void 0 : _options_onError.call(options, new Error((_event_message = event.message) !== null && _event_message !== void 0 ? _event_message : "SpeechSynthesis.speak: synthesis failed"));
break;
}
}
function speak(text, options) {
(0, import_validate.assertSpeakText)(text);
(0, import_validate.assertSpeakOptions)(options);
var { onStart, onDone, onStopped, onError, ...utterance } = options !== null && options !== void 0 ? options : {};
var callbacks = {
onStart,
onDone,
onStopped,
onError
};
native().speak({
text,
...utterance
}, function(event) {
return dispatch(callbacks, event);
});
}
function stop() {
return native().stop().catch(import_nativeError.rethrowNativeError);
}
function pause() {
return native().pause().catch(import_nativeError.rethrowNativeError);
}
function resume() {
return native().resume().catch(import_nativeError.rethrowNativeError);
}
function isSpeaking() {
return native().isSpeaking().catch(import_nativeError.rethrowNativeError);
}
function getAvailableVoices() {
return native().getAvailableVoices().catch(import_nativeError.rethrowNativeError);
}
var SpeechSynthesis = Object.freeze({
maxInputLength: readMaxInputLength(),
speak,
stop,
pause,
resume,
isSpeaking,
getAvailableVoices
});
//# sourceMappingURL=index.native.js.map