Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
support for other languages
  • Loading branch information
kripken committed Aug 3, 2011
1 parent 7d68aeb commit 37e76b0
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -6,4 +6,5 @@
*.ll
src/speak
src/espeak
*.diff

23 changes: 21 additions & 2 deletions README.markdown
Expand Up @@ -43,8 +43,9 @@ available options are:
* amplitude: How loud the voice will be (default: 100)
* pitch: The voice pitch (default: 50)
* speed: The speed at which to talk (words per minute) (default: 175)
* voice: Which voice to use (requires you to bundle it - currently you
wil need to build speak.js yourself for that) (default: en/en-us)
* voice: Which voice to use (for a non-default voice, requires you to
build speak.js to include the proper data. See Language Support
below) (default: en/en-us)
* wordgap: Additional gap between words in 10 ms units (default: 0)

For example
Expand All @@ -69,3 +70,21 @@ 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
----------------

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.
* Expose those files to the emulated filesystem, in post.js. See commented-out
code in there as well.
* Run emscripten.sh to build.

You then need to call speak() with the `voice` option that tells it to use the
right voice for your language. For example, for French this should work:

`speak('boulanger', { voice: 'fr' })`

16 changes: 10 additions & 6 deletions demo.html
Expand Up @@ -9,12 +9,16 @@
<body>
<h1>speak.js</h1>
<h2>Text-To-Speech on the Web</h2>
<form onsubmit="speak(text.value, { amplitude: amplitude.value, wordgap: workdgap.value, pitch: pitch.value, speed: speed.value }); return false">
Text: <input type="text" name="text" size=50 value="Never gonna give, you, up.">
Amplitude: <input type="text" name="amplitude" size=5 value="100">
Pitch: <input type="text" name="pitch" size=5 value="50">
Speed: <input type="text" name="speed" size=5 value="175">
Word gap: <input type="text" name="workdgap" size=5 value="0">
<form onsubmit="speak(text.value, { amplitude: amplitude.value, wordgap: workdgap.value, pitch: pitch.value, speed: speed.value /*, voice: language.value */ }); return false">
Text: <input type="text" name="text" size=50 value="Never gonna give, you, up."><br>
<!--Language: <select name="language">
<option value="en/en-us">English (US)</option>
<option value="fr">French</option>
</select><br>-->
Amplitude: <input type="text" name="amplitude" size=5 value="100"><br>
Pitch: <input type="text" name="pitch" size=5 value="50"><br>
Speed: <input type="text" name="speed" size=5 value="175"><br>
Word gap: <input type="text" name="workdgap" size=5 value="0"><br>
<input type="submit" value="Go!">
</form>
<hr>
Expand Down
3 changes: 2 additions & 1 deletion src/emscripten.sh
Expand Up @@ -6,11 +6,12 @@ echo "emscripten"
python /home/alon/Dev/emscripten/emscripten.py -O -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 phontab phonindex phondata intonations en_dict
for filey in 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
#~/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
5 changes: 4 additions & 1 deletion src/post.js
@@ -1,11 +1,14 @@

FS.createPath('/', 'espeak/espeak-data', true, false);
[['phontab', phontab], ['phonindex', phonindex], ['phondata', phondata], ['intonations', intonations], ['en_dict', en_dict]].forEach(function(pair) {
[['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/en', true, false);
FS.createDataFile('/espeak/espeak-data/voices/en', 'en-us', en_us, true, false);

Expand Down

0 comments on commit 37e76b0

Please sign in to comment.