react-say-fork
Version:
# Goal and TODOs * Add Typescript support * Make compononents style-customizable
32 lines (31 loc) • 1.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
function createNativeUtterance({ speechSynthesis, SpeechSynthesisUtterance }, { lang, onBoundary, pitch, rate, text, voice, volume }) {
const utterance = new SpeechSynthesisUtterance(text);
let targetVoice;
if (typeof voice === 'function') {
targetVoice = voice.call(speechSynthesis, speechSynthesis.getVoices());
}
else {
const { voiceURI } = voice || {};
targetVoice =
voiceURI &&
[].find.call([].slice.call(speechSynthesis.getVoices()), (v) => v.voiceURI === voiceURI);
}
utterance.lang = lang || '';
if (pitch || pitch === 0) {
utterance.pitch = pitch;
}
if (rate || rate === 0) {
utterance.rate = rate;
}
if (targetVoice) {
utterance.voice = targetVoice;
}
if (volume || volume === 0) {
utterance.volume = volume;
}
onBoundary && (utterance === null || utterance === void 0 ? void 0 : utterance.addEventListener('boundary', onBoundary));
return utterance;
}
exports.default = createNativeUtterance;