Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
update build system to latest emscripten, in preparation for further …
…optimization
  • Loading branch information
kripken committed Jan 6, 2012
1 parent 54037b7 commit 52eb2a6
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 100,543 deletions.
9 changes: 1 addition & 8 deletions README.markdown
Expand Up @@ -63,13 +63,6 @@ to tinker with the source code though, you might want to build it yourself.
To do so, run emscripten.sh inside src/. Note that you need to change the paths
there.

That will generate speak.full.js, which is the unminified version. It is
recommended to minify that (for example, using the closure compiler). speak.js
in this repo is minified.

demo.html uses speak.js (the minified version) while helloworld.js
uses speak.full.js (the unminified version - useful during development).


Language Support
----------------
Expand All @@ -78,7 +71,7 @@ eSpeak supports multiple languages so speak.js can too. To do this, you
need to build a custom version of speak.js:

* Bundle the proper language files. For french, you need fr_dict and voices/fr.
See commented-out code in emscripten.sh.
See commented-out code in emscripten.sh and bundle.py
* Expose those files to the emulated filesystem, in post.js. See commented-out
code in there as well.
* Run emscripten.sh to build.
Expand Down
3 changes: 1 addition & 2 deletions demo.html
Expand Up @@ -29,9 +29,8 @@ <h2>Text-To-Speech on the Web</h2>
<ul>
<li><b>Typed arrays</b>. The eSpeak code is not portable to the extent that would be necessary to avoid using typed arrays.
(It should however be possible to rewrite small bits of eSpeak to fix that.)
Typed arrays are present in Firefox and Chrome, but not IE, Safari or Opera.</li>
Typed arrays are present in Firefox and Chrome, and hopefully by the time you read this in IE, Safari and Opera.</li>
</ul>
Note that recent versions of these browsers are needed in most cases.
</p>

<div id="audio"></div>
Expand Down
2 changes: 1 addition & 1 deletion helloworld.html
@@ -1,6 +1,6 @@
<html>
<head>
<script src="speak.full.js"></script>
<script src="speak.js"></script>
</head>
<body>
<button onclick="speak('hello world')">Talk</button>
Expand Down
100,495 changes: 0 additions & 100,495 deletions speak.full.js

This file was deleted.

31 changes: 31 additions & 0 deletions src/bundle.py
@@ -0,0 +1,31 @@
import os, sys
from subprocess import Popen, PIPE, STDOUT

def process(filename):
base_dir = '..'

files = ''

for filey in ['config', 'phontab', 'phonindex', 'phondata', 'intonations', 'en_dict']: # fr_dict # Needed for French
f = Popen(['python', '/home/alon/Dev/emscripten/tools/file2json.py', os.path.join(base_dir, 'espeak-data', filey), filey], stdout=PIPE).communicate()
files += f[0]

f = Popen(['python', '/home/alon/Dev/emscripten/tools/file2json.py', os.path.join(base_dir, 'espeak-data/voices/en/en-us'), 'en_us'], stdout=PIPE).communicate()
files += f[0]

# Needed for French
f = Popen(['python', '/home/alon/Dev/emscripten/tools/file2json.py', os.path.join(base_dir, 'espeak-data/voices/fr'), 'fr'], stdout=PIPE).communicate()
files += f[0]

src = open(filename).read()
pre = open('pre.js').read()
post = open('post.js').read()

out = open(filename, 'w')
out.write(pre.replace('{{{ FILES }}}', files))
out.write(src)
out.write(post)
out.close()

process(sys.argv[1])

30 changes: 17 additions & 13 deletions src/emscripten.sh
@@ -1,31 +1,35 @@
# Note: emmaken.py and other scripts mentioned here are part of Emscripten,
# available at https://github.com/kripken/emscripten
# (change the paths here to match where you set that up in your system).

export EMSCRIPTEN=/home/alon/Dev/emscripten

echo "make"
make distclean
make clean
rm libespeak.*
rm speak speak.bc speak.o
RANLIB=/home/alon/Dev/emscripten/tools/emmaken.py AR=/home/alon/Dev/emscripten/tools/emmaken.py CXX=/home/alon/Dev/emscripten/tools/emmaken.py CC=/home/alon/Dev/emscripten/tools/emmaken.py CXXFLAGS="-DNEED_WCHAR_FUNCTIONS" make
CXXFLAGS="-DNEED_WCHAR_FUNCTIONS" $EMSCRIPTEN/emmake make -j 4

echo "dis"
~/Dev/llvm/cbuild/bin/llvm-dis -show-annotations speak.bc -o=speak.ll
~/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"
python /home/alon/Dev/emscripten/emscripten.py -O -s SKIP_STACK_IN_SMALL=1 -s SAFE_HEAP=0 -s USE_TYPED_ARRAYS=2 -s ASSERTIONS=0 -s OPTIMIZE=1 -s RELOOP=1 speak.ll > espeak.raw.js
echo "bundling"
cat pre.js > ../speak.full.js
for filey in config phontab phonindex phondata intonations en_dict # fr_dict # Needed for French
do
python ~/Dev/emscripten/tools/file2json.py ../espeak-data/$filey $filey >> ../speak.full.js
done
python ~/Dev/emscripten/tools/file2json.py ../espeak-data/voices/en/en-us en_us >> ../speak.full.js
#python ~/Dev/emscripten/tools/file2json.py ../espeak-data/voices/fr fr >> ../speak.full.js # Needed for French
cat espeak.raw.js >> ../speak.full.js
cat post.js >> ../speak.full.js
$EMSCRIPTEN/emcc -O2 --js-transform "python bundle.py" speak.ll -o speak.raw.js
cat shell_pre.js > ../speak.js
cat speak.raw.js >> ../speak.js
cat shell_post.js >> ../speak.js








#~/Dev/mozilla-central/js/src/js -m speak.full.js -w wav.wav --path="/home/alon/Dev/espeak-1.45.04-source" "hello world"
Expand Down
33 changes: 18 additions & 15 deletions src/post.js
@@ -1,20 +1,23 @@

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.ignorePermissions = true;

//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', 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/en', true, false);
FS.createDataFile('/espeak/espeak-data/voices/en', 'en-us', en_us, 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.root.write = true;
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.ignorePermissions = false;

function speak(text, args) {
args = args || {};
Module.arguments = [
'-w', 'wav.wav',
Expand Down Expand Up @@ -58,13 +61,13 @@
return ret;
}

for (var i = 0; i < wav.length; i++)
for (var i = 0; i < wav.length; i++) {
wav[i] = unSign(wav[i], 8);
}

document.getElementById("audio").innerHTML=("<audio id=\"player\" src=\"data:audio/x-wav;base64,"+encode64(wav)+"\">");
document.getElementById("player").play();
}

return speak;
})();
this['speak'] = speak; // for closure compiler

14 changes: 5 additions & 9 deletions src/pre.js
@@ -1,13 +1,9 @@

var speak = (function() {
{{{ FILES }}}

// eSpeak and other code here are under the GNU GPL.
function speak(text, args) {

if (!this['print']) {
print = console.log;
}

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

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

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

0 comments on commit 52eb2a6

Please sign in to comment.