• Stars
    star
    1,279
  • Rank 36,807 (Top 0.8 %)
  • Language
    C++
  • License
    GNU General Publi...
  • Created over 13 years ago
  • Updated almost 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Text-to-Speech in JavaScript using eSpeak

speak.js

A port of the eSpeak speech synthesizer from C++ to JavaScript using Emscripten.

Enables text-to-speech on the web using only JavaScript and HTML5.

Usage

Very simple! Do this:

  • Include the script in your html header,

    <script src="speakClient.js"></script>

    (and make sure you have speakClient.js available, as well as speakWorker.js and speakGenerator.js)

  • Add a div with an audio element called 'audio' in your html body,

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

  • Call speak() to say stuff in JavaScript

    speak('hello world!')

See helloworld.html for a simple 'hello world', and demo.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 (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)
  • noWorker: Do not use a web worker (see below in 'Architecture')

For example

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

will talk in a very high-pitched voice.

Architecture

speakClient.js is the file that you interact with. It defines speak(), and will load speakWorker.js in a web worker. speakWorker wraps around speakGenerator.js, which does the actual work of converting a string into a WAV file. The WAV data is returned to speak(), which then plays it in an HTML Audio element.

You can also use speak.js without a web worker. In that case, you don't need speakWorker.js, but you do need to load speakGenerator.js along with speakClient.js in your HTML page. speak(), if called with noWorker set to true in the options object, will directly call the WAV generation code in speakGenerator.js instead of forwarding the call to a worker which would have done the same.

Building

A prebuilt version is already included. 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.

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 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.

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' })`

More Repositories

1

ammo.js

Direct port of the Bullet physics engine to JavaScript using Emscripten
C++
4,147
star
2

BananaBread

BananaBread is a C++ 3D game engine that runs on the web using JavaScript+WebGL+HTML
C++
1,375
star
3

box2d.js

Port of Box2D to JavaScript using Emscripten
C
1,316
star
4

llvm.js

LLVM compiled to JavaScript using Emscripten
JavaScript
455
star
5

webgl-worker

JavaScript
231
star
6

xml.js

Port of libxml to JavaScript using Emscripten
JavaScript
174
star
7

zee.js

zlib compiled to JavaScript using Emscripten
C
97
star
8

j2k.js

Port of OpenJPEG, an open-source JPEG2000 codec, to JavaScript using Emscripten
C
82
star
9

intensityengine

[Not active!] An open source platform for 3D games and virtual worlds
C++
58
star
10

lzma.js

An LZMA implementation in JavaScript, compiled from lzip
C++
56
star
11

meandmyshadow.web

C
51
star
12

Massive

The asm.js benchmark
JavaScript
47
star
13

gmp.js

A port of the GNU Multiple-Precision Library (GMP), a library for arbitrary precision arithmetic, to JavaScript using Emscripten
C
44
star
14

mloc_emscripten_talk

JavaScript
41
star
15

clangor

clang ported to js
C++
41
star
16

worker-ui

Discussions and experiments with splitting UI rendering off the main thread on the web, using workers
34
star
17

boon

Freedoom + PrBoom: Open source Doom in HTML5
C++
33
star
18

Relooper

this repo is deprecated, see the binaryen repo
C++
21
star
19

build-suite

Pre-built WASM builds
JavaScript
19
star
20

bullet

C++
18
star
21

cashew

asm.js parser in C++
C++
18
star
22

syntensity

Experimental port of Sauerbraten/Syntensity to the web, using Emscripten
C++
17
star
23

talks

JavaScript
16
star
24

llvm-js

C++
16
star
25

clang-js

C++
14
star
26

cxx_demangle

C++ name demangling
JavaScript
14
star
27

misc-js-benchmarks

Miscellaneous JavaScript Benchmarks, of Dubious Value
JavaScript
13
star
28

emscripten-site

Emscripten website
HTML
11
star
29

demo-bananabread

BananaBread demo
JavaScript
10
star
30

musl-emscripten

C
10
star
31

binaryen-webpack-plugin

Binaryen plugin for webpack: shrinks wasm files
Python
8
star
32

webgl-2d-screen

JavaScript
7
star
33

embenchen

Emscripten benchmark suite
JavaScript
6
star
34

xz-lzma.js

C
3
star
35

simulations

Python
2
star
36

almond

C
2
star
37

tps_report_cloud_archiver

JavaScript
2
star
38

blog

SCSS
2
star
39

minir

C++
1
star
40

embooken

1
star
41

llvm-js-2

Trying to coax the Cpu0 backend to output JS
C++
1
star