8000 update build system to latest emscripten, in preparation for further … · kripken/speak.js@52eb2a6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 52eb2a6

Browse files
committed
update build system to latest emscripten, in preparation for further optimization
1 parent 54037b7 commit 52eb2a6

File tree

10 files changed

+80
-100543
lines changed

10 files changed

+80
-100543
lines changed

README.markdown

Lines changed: 1 addition & 8 deletions
10BC0
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,6 @@ to tinker with the source code though, you might want to build it yourself.
6363
To do so, run emscripten.sh inside src/. Note that you need to change the paths
6464
there.
6565

66-
That will generate speak.full.js, which is the unminified version. It is
67-
recommended to minify that (for example, using the closure compiler). speak.js
68-
in this repo is minified.
69-
70-
demo.html uses speak.js (the minified version) while helloworld.js
71-
uses speak.full.js (the unminified version - useful during development).
72-
7366

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

8073
* Bundle the proper language files. For french, you need fr_dict and voices/fr.
81-
See commented-out code in emscripten.sh.
74+
See commented-out code in emscripten.sh and bundle.py
8275
* Expose those files to the emulated filesystem, in post.js. See commented-out
8376
code in there as well.
8477
* Run emscripten.sh to build.

demo.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ <h2>Text-To-Speech on the Web</h2>
2929
<ul>
3030
<li><b>Typed arrays</b>. The eSpeak code is not portable to the extent that would be necessary to avoid using typed arrays.
3131
(It should however be possible to rewrite small bits of eSpeak to fix that.)
32-
Typed arrays are present in Firefox and Chrome, but not IE, Safari or Opera.</li>
32+
Typed arrays are present in Firefox and Chrome, and hopefully by the time you read this in IE, Safari and Opera.</li>
3333
</ul>
34-
Note that recent versions of these browsers are needed in most cases.
3534
</p>
3635

3736
<div id="audio"></div>

helloworld.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<html>
22
<head>
3-
<script src="speak.full.js"></script>
3+
<script src="speak.js"></script>
44
</head>
55
<body>
66
<button onclick="speak('hello world')">Talk</button>

speak.full.js

Lines changed: 0 additions & 100495 deletions
This file was deleted.

src/bundle.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import os, sys
2+
from subprocess import Popen, PIPE, STDOUT
3+
4+
def process(filename):
5+
base_dir = '..'
6+
7+
files = ''
8+
9+
for filey in ['config', 'phontab', 'phonindex', 'phondata', 'intonations', 'en_dict']: # fr_dict # Needed for French
10+
f = Popen(['python', '/home/alon/Dev/emscripten/tools/file2json.py', os.path.join(base_dir, 'espeak-data', filey), filey], stdout=PIPE).communicate()
11+
files += f[0]
12+
13+
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()
14+
files += f[0]
15+
16+
# Needed for French
17+
f = Popen(['python', '/home/alon/Dev/emscripten/tools/file2json.py', os.path.join(base_dir, 'espeak-data/voices/fr'), 'fr'], stdout=PIPE).communicate()
18+
files += f[0]
19+
20+
src = open(filename).read()
21+
pre = open('pre.js').read()
22+
post = open('post.js').read()
23+
24+
out = open(filename, 'w')
25+
out.write(pre.replace('{{{ FILES }}}', files))
26+
out.write(src)
27+
out.write(post)
28+
out.close()
29+
30+
process(sys.argv[1])
31+

src/emscripten.sh

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,35 @@
11
# Note: emmaken.py and other scripts mentioned here are part of Emscripten,
22
# available at https://github.com/kripken/emscripten
33
# (change the paths here to match where you set that up in your system).
4+
5+
export EMSCRIPTEN=/home/alon/Dev/emscripten
6+
47
echo "make"
58
make distclean
69
make clean
710
rm libespeak.*
811
rm speak speak.bc speak.o
9-
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
12+
CXXFLAGS="-DNEED_WCHAR_FUNCTIONS" $EMSCRIPTEN/emmake make -j 4
13+
1014
echo "dis"
11-
~/Dev/llvm/cbuild/bin/llvm-dis -show-annotations speak.bc -o=speak.ll
15+
~/Dev/llvm/cbuild/bin/llvm-dis -show-annotations speak -o=speak.ll
1216
#echo "autodebug"
1317
#mv speak.ll speak.orig.ll
1418
#python ~/Dev/emscripten/tools/autodebugger.py speak.orig.ll speak.ll
1519
#mv speak.bc speak.orig.bc
1620
#~/Dev/llvm/cbuild/bin/llvm-as speak.ll -o=speak.bc
21+
1722
echo "emscripten"
18-
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
19-
echo "bundling"
20-
cat pre.js > ../speak.full.js
21-
for filey in config phontab phonindex phondata intonations en_dict # fr_dict # Needed for French
22-
do
23-
python ~/Dev/emscripten/tools/file2json.py ../espeak-data/$filey $filey >> ../speak.full.js
24-
done
25-
python ~/Dev/emscripten/tools/file2json.py ../espeak-data/voices/en/en-us en_us >> ../speak.full.js
26-
#python ~/Dev/emscripten/tools/file2json.py ../espeak-data/voices/fr fr >> ../speak.full.js # Needed for French
27-
cat espeak.raw.js >> ../speak.full.js
28-
cat post.js >> ../speak.full.js
23+
$EMSCRIPTEN/emcc -O2 --js-transform "python bundle.py" speak.ll -o speak.raw.js
24+
cat shell_pre.js > ../speak.js
25+
cat speak.raw.js >> ../speak.js
26+
cat shell_post.js >> ../speak.js
27+
28+
29+
30+
31+
32+
2933

3034

3135
#~/Dev/mozilla-central/js/src/js -m speak.full.js -w wav.wav --path="/home/alon/Dev/espeak-1.45.04-source" "hello world"

src/post.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11

2-
FS.createPath('/', 'espeak/espeak-data', true, false);
3-
[['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
4-
var id = pair[0];
5-
var data = pair[1];
6-
FS.createDataFile('/espeak/espeak-data', id, data, true, false);
7-
});
2+
FS.ignorePermissions = true;
83

9-
//FS.createPath('/', 'espeak/espeak-data/voices', true, false); // Needed for French
10-
//FS.createDataFile('/espeak/espeak-data/voices', 'fr', fr, true, false); // Needed for French
4+
FS.createPath('/', 'espeak/espeak-data', true, false);
5+
[['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
6+
var id = pair[0];
7+
var data = pair[1];
8+
FS.createDataFile('/espeak/espeak-data', id, data, true, false);
9+
});
1110

12-
FS.createPath('/', 'espeak/espeak-data/voices/en', true, false);
13-
FS.createDataFile('/espeak/espeak-data/voices/en', 'en-us', en_us, true, false);
11+
//FS.createPath('/', 'espeak/espeak-data/voices', true, false); // Needed for French
12+
//FS.createDataFile('/espeak/espeak-data/voices', 'fr', fr, true, false); // Needed for French
1413

15-
FS.root.write = true;
14+
FS.createPath('/', 'espeak/espeak-data/voices/en', true, false);
15+
FS.createDataFile('/espeak/espeak-data/voices/en', 'en-us', en_us, true, false);
16+
17+
FS.root.write = true;
18+
19+
FS.ignorePermissions = false;
1620

17-
function speak(text, args) {
1821
args = args || {};
1922
Module.arguments = [
2023
'-w', 'wav.wav',
@@ -58,13 +61,13 @@
5861
return ret;
5962
}
6063

61-
for (var i = 0; i < wav.length; i++)
64+
for (var i = 0; i < wav.length; i++) {
6265
wav[i] = unSign(wav[i], 8);
66+
}
6367

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

68-
return speak;
69-
})();
72+
this['speak'] = speak; // for closure compiler
7073

src/pre.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11

2-
var speak = (function() {
2+
{{{ FILES }}}
33

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

6-
if (!this['print']) {
7-
print = console.log;
8-
}
9-
10-
var Module = {
11-
noInitialRun: true
12-
};
6+
var Module = {
7+
noInitialRun: true
8+
};
139

src/shell_post.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
return this.speak;
2+
}).call({});
3+

src/shell_pre.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
var speak = (function() {
2+
// eSpeak and other code here are under the GNU GPL.
3+

0 commit comments

Comments
 (0)
0