Last active
December 18, 2018 07:19
-
-
Save utiuti/4a422e884b651e4c7fcbce26eba34b07 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The function below was developed late last year by @stybbe, published in | |
// Screeps Slack's #share-thy-code channel. No license was applied; all | |
// rights remain with the author. Minor fixes were made by @SemperRabbit | |
// to get it working again. | |
// NOTE: that this code works in chrome and firefox (albiet quietly | |
// in firefox) but not the steam client. | |
global.defaultVoice = "Deutsch Female"; // can be changed | |
// see https://responsivevoice.org/text-to-speech-languages/ | |
// for options | |
global.voiceConsole = function voiceConsole(text) { | |
console.log(`<span style="color:green; font-style: italic;">${text}</span> | |
<script> | |
if (!window.speakText){ | |
window.speakText = function(gameTime, text) { | |
var id = gameTime + "-" + text; | |
if(!window.voiceHash){ | |
window.voiceHash={}; | |
} | |
if (!window.voiceHash[id]){ | |
window.voiceHash[id]=true; | |
responsiveVoice.setDefaultVoice("${defaultVoice}"); | |
responsiveVoice.speak(text); | |
} | |
} | |
} | |
if (document.getElementById("responsiveVoice")){ | |
window.speakText("${Game.time}", "${text}"); | |
}else{ | |
var script = document.createElement("script"); | |
script.type = "text/javascript"; | |
script.id = "responsiveVoice"; | |
script.onload = function() { | |
responsiveVoice.setDefaultVoice("${defaultVoice}"); | |
console.log("responsiveVoice has initialized"); | |
window.speakText("${Game.time}", "${text}"); | |
}; | |
script.src = "https://code.responsivevoice.org/responsivevoice.js"; | |
document.getElementsByTagName("head")[0].appendChild(script); | |
setTimeout("responsiveVoice.init()", 1000); | |
} | |
</script>` | |
.replace(/(\r\n|\n|\r)\t+|(\r\n|\n|\r) +|(\r\n|\n|\r)/gm, "")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment