Skip to content

Instantly share code, notes, and snippets.

@ticky
Forked from wesbos/lol.js
Last active February 16, 2016 23:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ticky/dc586f28eea14247178c to your computer and use it in GitHub Desktop.
Save ticky/dc586f28eea14247178c to your computer and use it in GitHub Desktop.
// paste in your console
(function() {
// if `onvoiceschanged` begins undefined, we need to call this manually, apparently?
var wasUndefined = speechSynthesis.onvoiceschanged === undefined;
speechSynthesis.onvoiceschanged = function() {
var sandbox = document.createElement('iframe');
sandbox.style.visibility = 'hidden';
sandbox.style.display = 'block';
document.body.appendChild(sandbox);
sandbox.contentDocument.open();
sandbox.contentDocument.write('<!DOCTYPE html><html><head><title>-</title></head><body><body></html>');
sandbox.contentDocument.close();
var nativeKeys = Object.keys(sandbox.contentWindow);
var ourKeys = Object.keys(window);
var diffedKeys = ourKeys.filter(function(key) {return nativeKeys.indexOf(key) === -1});
console.log(diffedKeys);
document.body.removeChild(sandbox);
var msg = new SpeechSynthesisUtterance();
msg.voice = this.getVoices().filter(function(v) {return v.name == 'Cellos'})[0];
msg.text = diffedKeys.join(' ');
this.speak(msg);
};
if (wasUndefined) {
speechSynthesis.onvoiceschanged.call(speechSynthesis);
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment