Last active
August 6, 2021 22:23
-
-
Save florabtw/eeea9956cb2bc3b290e5 to your computer and use it in GitHub Desktop.
Run with `node Translate.js hello`
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
// TKK = hours since epoch | |
var window = { | |
TKK: parseInt(new Date().getTime() / 1000 / 60 / 60) | |
}; | |
var t = "a"; | |
var dd = "."; | |
var Vb = "+-a^+6"; | |
var Tb = "+"; | |
var Ub = "+-3^+b+-f"; | |
var RL = function(a, b) { | |
for (var c = 0; c < b.length - 2; c += 3) { | |
var d = b.charAt(c + 2) | |
, d = d >= t ? d.charCodeAt(0) - 87 : Number(d) | |
, d = b.charAt(c + 1) == Tb ? a >>> d : a << d; | |
a = b.charAt(c) == Tb ? a + d & 4294967295 : a ^ d | |
} | |
return a; | |
} | |
var TL = function(a) { | |
var b = Number(window['TKK']); | |
for (d = [], e = 0, f = 0; f < a.length; f++) { | |
var g = a.charCodeAt(f); | |
if (128 > g) { | |
d[e++] = g; | |
} else { | |
if (2048 > g) { | |
d[e++] = g >> 6 | 192; | |
} else { | |
if ( 55296 == (g & 64512) && f + 1 < a.length && 56320 == (a.charCodeAt(f + 1) & 64512) ) { | |
g = 65536 + ((g & 1023) << 10) + (a.charCodeAt(++f) & 1023); | |
d[e++] = g >> 18 | 240; | |
d[e++] = g >> 12 & 63 | 128; | |
} else { | |
d[e++] = g >> 12 | 224; | |
} | |
d[e++] = g >> 6 & 63 | 128; | |
} | |
d[e++] = g & 63 | 128; | |
} | |
} | |
a = b || 0; | |
for (e = 0; e < d.length; e++) { | |
a += d[e]; | |
a = RL(a, Vb); | |
} | |
a = RL(a, Ub); | |
0 > a && (a = (a & 2147483647) + 2147483648); | |
a %= 1E6; | |
return a.toString() + dd + (a ^ b) | |
} | |
var url = "http://translate.google.com/translate_tts?ie=UTF-8&client=t&tl=en" | |
url += "&q=" + process.argv[2] | |
url += "&tk=" + TL(process.argv[2]) | |
var http = require('http'); | |
var fs = require('fs'); | |
var file = fs.createWriteStream(process.argv[2] + '.mp3'); | |
http.get(url, function(res) { | |
res.pipe(file); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not working anymore, just getting an empty mp3 file :(