one
Version:
One is a React framework for web, iOS, and Android apps.
41 lines (39 loc) • 1.65 kB
JavaScript
function assertSpeakText(text) {
if (typeof text !== "string" || text.length === 0) {
throw new Error("SpeechSynthesis.speak: text must be a non-empty string");
}
}
function assertSpeakOptions(options) {
if (options === void 0) return;
if (typeof options !== "object" || options === null || Array.isArray(options)) {
throw new Error("SpeechSynthesis.speak: options must be an object");
}
const { language, pitch, rate, voice, volume, onStart, onDone, onStopped, onError } = options;
if (language !== void 0 && typeof language !== "string") {
throw new Error("SpeechSynthesis.speak: language must be a BCP-47 string");
}
if (pitch !== void 0 && (typeof pitch !== "number" || !Number.isFinite(pitch))) {
throw new Error("SpeechSynthesis.speak: pitch must be a finite number");
}
if (rate !== void 0 && (typeof rate !== "number" || !Number.isFinite(rate))) {
throw new Error("SpeechSynthesis.speak: rate must be a finite number");
}
if (voice !== void 0 && typeof voice !== "string") {
throw new Error("SpeechSynthesis.speak: voice must be a string");
}
if (volume !== void 0 && (typeof volume !== "number" || !Number.isFinite(volume) || volume < 0 || volume > 1)) {
throw new Error("SpeechSynthesis.speak: volume must be a number between 0 and 1");
}
for (const [name, callback] of [
["onStart", onStart],
["onDone", onDone],
["onStopped", onStopped],
["onError", onError]
]) {
if (callback !== void 0 && typeof callback !== "function") {
throw new Error(`SpeechSynthesis.speak: ${name} must be a function`);
}
}
}
export { assertSpeakOptions, assertSpeakText };
//# sourceMappingURL=validate.mjs.map