public

  • Download Gist
google-translate-drums.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
(function() {
// Notes from http://news.ycombinator.com/item?id=1952531
var notes = {
"suspended cymbal":"zk",
"snare":"bschk",
"brush":"pv",
"bass":"bk",
"flam1":"tk",
"roll tap":"vk",
"flam2":"kt",
"flam tap":"kttp",
"hi hat tap":"krp",
"short roll":"pv",
"better hi hat":"th",
"instant rimshot":"thp, ds"
};
 
function writeNote(event) {
song.value += event.target.note + " ";
}
function clear() {
song.value = "";
}
 
function play() {
var audio = new Audio("http://translate.google.com/translate_tts?q=" + encodeURI(song.value) + "&tl=de");
audio.play();
}
function appendButton(attributes, container) {
var button = document.createElement("input");
button.type = "button";
for (var name in attributes) {
button[name] = attributes[name];
}
container.appendChild(button);
}
 
var container = document.createElement("div");
var controls = document.createElement("div");
var song = document.createElement("input");
song.type = "text";
song.size = 150;
container.appendChild(song);
container.appendChild(controls);
document.body.appendChild(container);
 
for (var name in notes) {
if (notes.hasOwnProperty(name)) {
appendButton({
value: name,
note: notes[name],
onclick: writeNote
}, controls);
}
}
appendButton({
value: "play",
onclick: play
}, controls);
})();
how-to.txt
1 2 3 4 5 6 7 8 9 10 11
Bookmarklet:
 
javascript:(function(){document.body.appendChild(document.createElement("script")).src="http://bit.ly/googlebeat"})()
 
Instructions:
 
1. Load Google Translate: http://translate.google.com
 
2. Load the bookmarklet in the above comment in the URL bar.
 
3. Click the new buttons at the bottom of the page.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.