-
-
Save camiloaa/ece4f18a2db61764d63c to your computer and use it in GitHub Desktop.
Duolingo Google TTS
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
//==UserScript== | |
//@name LingoGoogleTTS | |
//@version 1.2 | |
//@description Use Google TTS for Duolingo | |
//@match https://www.duolingo.com/* | |
//@match http://www.duolingo.com/* | |
//@grant none | |
//==/UserScript== | |
function googleTTSLang(targetLang) { | |
if (targetLang == "dn") { return "nl"; } | |
if (targetLang == "zs") { return "zh"; } | |
return targetLang; | |
} | |
(function($) { | |
if (typeof duo != 'undefined' && typeof $.tts_super == 'undefined') { | |
var ttsBase = duo.tts_base_url, ttsPath = duo.tts_path; | |
$.fn.tts_super = $.fn.tts; | |
$.fn.tts = function(d) { | |
var language = d.language; | |
var gRand = function () { | |
return Math.floor(Math.random() * 1000000) + '|' + | |
Math.floor(Math.random() * 1000000) }; | |
duo.tts_base_url = "http://translate.google.com/translate_tts?ie=UTF-8&"; | |
if (d.tts_type === "sentence" && typeof d.sentence !== 'undefined') { | |
var quoted_text = encodeURIComponent(d.sentence.replace("/"," ")); | |
d.language = googleTTSLang(d.language); | |
duo.tts_path = 'tl=' + d.language + '&q=' + quoted_text + | |
"&total=1&textlen=" + quoted_text.length + | |
"&tk=" + gRand() + "&client=t"; | |
console.log("Requesting "+duo.tts_path); | |
} else { | |
// Use default for tokens (single words) | |
duo.tts_base_url = ttsBase; | |
duo.tts_path = ttsPath; | |
} | |
return this.each(function() { | |
$(this).tts_super(d); | |
}); | |
} | |
} | |
}(jQuery)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment