UNPKG

one

Version:

One is a React framework for web, iOS, and Android apps.

79 lines (76 loc) • 2.62 kB
import { NitroModules } from "react-native-nitro-modules"; import { rethrowNativeError } from "../nativeError.native.js"; import { assertSpeakOptions, assertSpeakText } from "./validate.native.js"; var hybrid; function native() { hybrid !== null && hybrid !== void 0 ? hybrid : hybrid = NitroModules.createHybridObject("OneSpeechSynthesis"); return hybrid; } function readMaxInputLength() { if (!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) { assertSpeakText(text); 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(rethrowNativeError); } function pause() { return native().pause().catch(rethrowNativeError); } function resume() { return native().resume().catch(rethrowNativeError); } function isSpeaking() { return native().isSpeaking().catch(rethrowNativeError); } function getAvailableVoices() { return native().getAvailableVoices().catch(rethrowNativeError); } var SpeechSynthesis = Object.freeze({ maxInputLength: readMaxInputLength(), speak, stop, pause, resume, isSpeaking, getAvailableVoices }); export { SpeechSynthesis }; //# sourceMappingURL=index.native.js.map