Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fixes for closure
  • Loading branch information
kripken committed Jan 13, 2012
1 parent 52eb2a6 commit 8db94e6
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 68 deletions.
3 changes: 1 addition & 2 deletions src/emscripten.sh
Expand Up @@ -13,11 +13,10 @@ CXXFLAGS="-DNEED_WCHAR_FUNCTIONS" $EMSCRIPTEN/emmake make -j 4

echo "dis"
~/Dev/llvm/cbuild/bin/llvm-dis -show-annotations speak -o=speak.ll

#echo "autodebug"
#mv speak.ll speak.orig.ll
#python ~/Dev/emscripten/tools/autodebugger.py speak.orig.ll speak.ll
#mv speak.bc speak.orig.bc
#~/Dev/llvm/cbuild/bin/llvm-as speak.ll -o=speak.bc

echo "emscripten"
$EMSCRIPTEN/emcc -O2 --js-transform "python bundle.py" speak.ll -o speak.raw.js
Expand Down
109 changes: 53 additions & 56 deletions src/post.js
@@ -1,73 +1,70 @@

FS.ignorePermissions = true;
FS.ignorePermissions = true;

FS.createPath('/', 'espeak/espeak-data', true, false);
[['config', config], ['phontab', phontab], ['phonindex', phonindex], ['phondata', phondata], ['intonations', intonations], ['en_dict', en_dict] /*, ['fr_dict', fr_dict] */].forEach(function(pair) { // commented-out code here is needed for French
var id = pair[0];
var data = pair[1];
FS.createDataFile('/espeak/espeak-data', id, data, true, false);
});
FS.createPath('/', 'espeak/espeak-data', true, false);
[['config', config], ['phontab', phontab], ['phonindex', phonindex], ['phondata', phondata], ['intonations', intonations], ['en_dict', en_dict] /*, ['fr_dict', fr_dict] */].forEach(function(pair) { // commented-out code here is needed for French
var id = pair[0];
var data = pair[1];
FS.createDataFile('/espeak/espeak-data', id, data, true, false);
});

//FS.createPath('/', 'espeak/espeak-data/voices', true, false); // Needed for French
//FS.createDataFile('/espeak/espeak-data/voices', 'fr', fr, true, false); // Needed for French
//FS.createPath('/', 'espeak/espeak-data/voices', true, false); // Needed for French
//FS.createDataFile('/espeak/espeak-data/voices', 'fr', fr, true, false); // Needed for French

FS.createPath('/', 'espeak/espeak-data/voices/en', true, false);
FS.createDataFile('/espeak/espeak-data/voices/en', 'en-us', en_us, true, false);
FS.createPath('/', 'espeak/espeak-data/voices/en', true, false);
FS.createDataFile('/espeak/espeak-data/voices/en', 'en-us', en_us, true, false);

FS.root.write = true;
FS.root.write = true;

FS.ignorePermissions = false;
FS.ignorePermissions = false;

args = args || {};
Module.arguments = [
'-w', 'wav.wav',
// options
'-a', args.amplitude ? String(args.amplitude) : '100',
'-g', args.wordgap ? String(args.wordgap) : '0', // XXX
'-p', args.pitch ? String(args.pitch) : '50',
'-s', args.speed ? String(args.speed) : '175',
'-v', args.voice ? String(args.voice) : 'en/en-us',
// end options
'--path=/espeak',
text
];
var args = this['args'] || {};
Module.arguments = [
'-w', 'wav.wav',
// options
'-a', args['amplitude'] ? String(args['amplitude']) : '100',
'-g', args['wordgap'] ? String(args['wordgap']) : '0', // XXX
'-p', args['pitch'] ? String(args['pitch']) : '50',
'-s', args['speed'] ? String(args['speed']) : '175',
'-v', args['voice'] ? String(args['voice']) : 'en/en-us',
// end options
'--path=/espeak',
this['text']
];

run();
run();

var wav = FS.root.contents['wav.wav'].contents;
var wav = FS.root.contents['wav.wav'].contents;

function encode64(data) {
var BASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
var PAD = '=';
var ret = '';
var leftchar = 0;
var leftbits = 0;
for (var i = 0; i < data.length; i++) {
leftchar = (leftchar << 8) | data[i];
leftbits += 8;
while (leftbits >= 6) {
var curr = (leftchar >> (leftbits-6)) & 0x3f;
leftbits -= 6;
ret += BASE[curr];
}
function encode64(data) {
var BASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
var PAD = '=';
var ret = '';
var leftchar = 0;
var leftbits = 0;
for (var i = 0; i < data.length; i++) {
leftchar = (leftchar << 8) | data[i];
leftbits += 8;
while (leftbits >= 6) {
var curr = (leftchar >> (leftbits-6)) & 0x3f;
leftbits -= 6;
ret += BASE[curr];
}
if (leftbits == 2) {
ret += BASE[(leftchar&3) << 4];
ret += PAD + PAD;
} else if (leftbits == 4) {
ret += BASE[(leftchar&0xf) << 2];
ret += PAD;
}
return ret;
}

for (var i = 0; i < wav.length; i++) {
wav[i] = unSign(wav[i], 8);
if (leftbits == 2) {
ret += BASE[(leftchar&3) << 4];
ret += PAD + PAD;
} else if (leftbits == 4) {
ret += BASE[(leftchar&0xf) << 2];
ret += PAD;
}
return ret;
}

document.getElementById("audio").innerHTML=("<audio id=\"player\" src=\"data:audio/x-wav;base64,"+encode64(wav)+"\">");
document.getElementById("player").play();
for (var i = 0; i < wav.length; i++) {
wav[i] = unSign(wav[i], 8);
}

this['speak'] = speak; // for closure compiler
document.getElementById("audio").innerHTML=("<audio id=\"player\" src=\"data:audio/x-wav;base64,"+encode64(wav)+"\">");
document.getElementById("player").play();

9 changes: 3 additions & 6 deletions src/pre.js
@@ -1,9 +1,6 @@

{{{ FILES }}}

function speak(text, args) {
var Module = {};
Module['noInitialRun'] = true;

var Module = {
noInitialRun: true
};
{{{ FILES }}}

4 changes: 2 additions & 2 deletions src/shell_post.js
@@ -1,3 +1,3 @@
return this.speak;
}).call({});
}).call({ text: text, args: args });
}

5 changes: 3 additions & 2 deletions src/shell_pre.js
@@ -1,3 +1,4 @@
var speak = (function() {
// eSpeak and other code here are under the GNU GPL.
// eSpeak and other code here are under the GNU GPL.
function speak(text, args) {
(function() {

0 comments on commit 8db94e6

Please sign in to comment.