Skip to content

Instantly share code, notes, and snippets.

@danharper danharper/voices.js
Last active Oct 7, 2016

Embed
What would you like to do?
cycle every SpeechSynthesis voice
// would've been awesome if `speechSynthesis.speak` returned a promise which resolves on finish.. :(
const sleep = ms => new Promise(r => setTimeout(r, ms))
async function go(msg) {
for (let v of speechSynthesis.getVoices()) {
speechSynthesis.speak(u = new SpeechSynthesisUtterance(msg), u.voice = v, u)
await sleep(1000)
}
}
go('Hello World')
@danharper

This comment has been minimized.

Copy link
Owner Author

commented Oct 7, 2016

Or, transpiled:

let go = (() => {
  var _ref = _asyncToGenerator(function* (msg) {
    for (let v of speechSynthesis.getVoices()) {
      speechSynthesis.speak(u = new SpeechSynthesisUtterance(msg), u.voice = v, u);
      yield sleep(1000);
    }
  });

  return function go(_x) {
    return _ref.apply(this, arguments);
  };
})();

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

const sleep = ms => new Promise(r => setTimeout(r, ms));

go('Hello World');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.