Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
enable espeak options
  • Loading branch information
kripken committed Aug 2, 2011
1 parent 8f64634 commit 3e2a4c1
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 57 deletions.
35 changes: 31 additions & 4 deletions README.markdown
Expand Up @@ -27,18 +27,45 @@ Very simple! Do this:

`speak('hello world!')`

See demo.html for an example use.
See demo.min.html for a simple 'hello world', and demo.full.html for
a more detailed example.


Options
-------

You can also specify some options with calling speak(), by doing

`speak('hello world', { option1: value1, option2: value2 .. })`

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)
* wordgap: Additional gap between words in 10 ms units (default: 0)

For example

`speak('hello world', { pitch: 100 })`

will talk in a very high-pitched voice.


Building
--------

Run emscripten.sh inside src/. Note that you need to change the paths there.
A prebuilt version is already included, in the file speak.js. But if you want
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.full.html is the same as demo.html but uses speak.full.js. It is useful
for testing.
demo.full.html uses speak.full.js (the unminified version) while demo.min.js
uses speak.js (the minified version).

17 changes: 11 additions & 6 deletions demo.full.html
@@ -1,22 +1,27 @@
<html>
<title>Text-to-Speech on the Web</title>
<title>speak.js: Text-to-Speech on the Web</title>
<head>
<script>
// This demo is licensed under the GNU GPL.
</script>
<script src="speak.full.js"></script>
</head>
<body>
<h1>Text-To-Speech on the Web</h1>

<form onsubmit="speak(text.value); return false">
Text: <input type="text" name="text" size=50 value="Never gonna give, you, up."><input type="submit" value="Go!">
<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">
<input type="submit" value="Go!">
</form>
<hr>
<p>
This demo is 100% clientside JavaScript. It uses <a href="http://espeak.sourceforge.net/">eSpeak</a>, an open source
speech synthesizer, which was compiled from C++ to JavaScript using <a href="http://emscripten.org">Emscripten</a>.
Source code for this demo can be found <a href="espeak_src.tar.bz2">here</a>.
Source code for this demo can be found <a href="https://github.com/kripken/speak.js">here</a>.
</p>

<p>
Expand Down
40 changes: 0 additions & 40 deletions demo.html

This file was deleted.

10 changes: 10 additions & 0 deletions demo.min.html
@@ -0,0 +1,10 @@
<html>
<head>
<script src="speak.js"></script>
</head>
<body>
<button onclick="speak('hello world')">Talk</button>
<div id="audio"></div>
</body>
</html>

20 changes: 16 additions & 4 deletions speak.full.js
Expand Up @@ -6,7 +6,6 @@ var speak = (function() {
var print = console.log;

var Module = {
arguments: ['-w', 'wav.wav', '-v', 'en/en-us', '--path=/espeak'],
noInitialRun: true
};

Expand Down Expand Up @@ -18940,7 +18939,7 @@ var _llvm_dbg_declare; // stub for _llvm_dbg_declare

var _stdout=0;

var _stderr=0;var FS={"root":{"read":true,"write":false,"isFolder":true,"isDevice":false,"timestamp":"2011-08-02T18:43:27.128Z","inodeNumber":1,"contents":{}},"currentPath":"/","nextInode":2,"cmask":511,"streams":[null],"ignorePermissions":true, absolutePath: function (relative, base) {
var _stderr=0;var FS={"root":{"read":true,"write":false,"isFolder":true,"isDevice":false,"timestamp":"2011-08-02T20:49:28.477Z","inodeNumber":1,"contents":{}},"currentPath":"/","nextInode":2,"cmask":511,"streams":[null],"ignorePermissions":true, absolutePath: function (relative, base) {
if (typeof relative !== 'string') return null;
if (base === undefined) base = FS.currentPath;
if (relative && relative[0] == '/') base = '';
Expand Down Expand Up @@ -120057,8 +120056,21 @@ if (!Module['noInitialRun']) {

FS.root.write = true;

function speak(text) {
Module.arguments.push(text);
function speak(text, args) {
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
];

run();
Module.arguments.pop();

Expand Down
17 changes: 15 additions & 2 deletions src/post.js
Expand Up @@ -9,8 +9,21 @@

FS.root.write = true;

function speak(text) {
Module.arguments.push(text);
function speak(text, args) {
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
];

run();
Module.arguments.pop();

Expand Down
1 change: 0 additions & 1 deletion src/pre.js
Expand Up @@ -6,7 +6,6 @@ var speak = (function() {
var print = console.log;

var Module = {
arguments: ['-w', 'wav.wav', '-v', 'en/en-us', '--path=/espeak'],
noInitialRun: true
};

0 comments on commit 3e2a4c1

Please sign in to comment.