Created
March 14, 2015 16:36
-
-
Save skmp/03859e4120d9508d8ec3 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
/* | |
To use, go the memrize course editor, open the record form for an item, press F12 / right click -> developer tools, copy paste this into the console and press enter. | |
Demo: https://www.youtube.com/watch?v=DICc-CHzGdg | |
Have fun and use responsibly. | |
NB. if the load on the tts server becomes too high, I'll take it down. | |
Host your own, https://github.com/skmp/numbers/blob/master/tts.php ... | |
*/ | |
/* | |
sonid15 is german | |
Voices | |
- Andreas | |
- Julia | |
- Klaus | |
- Sarah | |
*/ | |
sonid = "sonid15"; | |
sonid_name = "Andreas"; | |
is_recording = false; | |
finished_recording = false; | |
played_once = false; | |
current_text = ''; | |
var map = { | |
a: "a", | |
be: "b", | |
ce: "c", | |
de: "d", | |
e: "e", | |
ef: "f", | |
ge: "g", | |
ha: "h", | |
i: "i", | |
jit: "j", | |
ka: "k", | |
ei: "i", | |
em: "m", | |
en: "n", | |
o: "o", | |
pe: "p", | |
ku: "q", | |
er: "r", | |
es: "s", | |
te: "t", | |
u: "u", | |
vau: "v", | |
we: "w", | |
ix: "x", | |
ypsilon: "y", | |
"ä": "ä", | |
"ö": "ö", | |
"ü": "ü" | |
}; | |
t = setInterval(function() { | |
if ($('.recorder-time:visible').length && !is_recording && !$('.recorder-container .loading-spinner:visible, .recorder-container .ico-green:visible').length) { | |
if (!played_once) { | |
console.log("Recording started"); | |
is_recording = true; | |
finished_recording = false; | |
played_once = true; | |
$(".injected_audio")[0].play(); | |
} | |
} else { | |
is_recording = false; | |
if ($('.recorder-pronounce-me strong').text() != current_text && $(".btn.recorder-btn.record:visible").length && !$('.recorder-container .loading-spinner:visible').length) { | |
current_text = $('.recorder-pronounce-me strong').text(); | |
var text = map[$.trim(current_text)]||$.trim(current_text); | |
console.log("Requesting text", text); | |
$.get("http://numbers.nihil.cc/tts.php", { q: text, s:sonid, v:sonid_name }).done(function(res) { | |
var mp3 = res.data; | |
$(".injected_audio").remove(); | |
console.log("injecting audio tag", mp3); | |
$("<audio>").attr("src", mp3).attr("class", "injected_audio").appendTo("body").on("pause", function(e) { | |
$(".btn.recorder-btn.stop").mousedown(); | |
console.log("Stopping recording"); | |
finished_recording = true; | |
}); | |
$(".btn.recorder-btn.record").click(); | |
console.log("Starting recording"); | |
}); | |
} else if ($('.btn.next-recording:visible').length && !$('.recorder-container .loading-spinner:visible').length) { | |
if (finished_recording) { | |
$('object').remove() | |
console.log("Moving on to next text"); | |
finished_recording = false; | |
played_once = false; | |
$('.btn.next-recording').hide(); | |
$('.btn.next-recording').mousedown(); | |
} | |
} | |
} | |
}, 100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment