beautiful-react-hooks
Version:
A collection of beautiful (and hopefully useful) React hooks to speed-up your components and hooks development
25 lines (24 loc) • 1.01 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = require("react");
/**
* At the moment, the `window.speechSynthesis.getVoices` function returns all the available system voices, but since
* it does it asynchronously the returning value is an empty array until a second call is performed.
*
* Check: https://w3c.github.io/speech-api/speechapi-errata.html.
*/
var asyncGetSystemVoices = function () { return new Promise(function (resolve) {
window.speechSynthesis.onvoiceschanged = function () { return resolve(window.speechSynthesis.getVoices()); };
window.speechSynthesis.getVoices();
}); };
/**
* A side effect to retrieve all the available system voices using the Web_Speech_API
*/
var useSystemVoices = function () {
var _a = (0, react_1.useState)([]), voices = _a[0], setVoices = _a[1];
(0, react_1.useEffect)(function () {
asyncGetSystemVoices().then(setVoices);
}, []);
return voices;
};
exports.default = useSystemVoices;