meSpeak.js

Text-To-Speech on the Web

Text: Amplitude: Pitch: Speed: Word gap:
Voice:

About

meSpeak.js (modulary enhanced speak.js) is a 100% client-side JavaScript text-to-speech library based on the speak.js project (see below).
meSpeak.js adds support for Webkit and Safari and introduces loadable voice modules. Also there is no more need for an embedding HTML-element.
Separating the code of the library from config-data and voice definitions should help future optimizations of the core part of speak.js.
All separated data has been compressed to base64-encoded strings from the original binary files to save some bandwidth (compared to JS-arrays of raw 8-bit data).
Browser requirements: Firefox, Chrome, Webkit, and Safari
meSpeak.js 2011 by N.Landsteiner, mass:werk – media environments; http://www.masswerk.at/mespeak/

Usage

meSpeak.loadConfig("mespeak_config.json"); meSpeak.loadVoice('en-us.json'); meSpeak.speak('hello world'); meSpeak.speak('hello world', { option1: value1, option2: value2 .. }); options: * 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 (default: last voice loaded or defaultVoice, see below) * wordgap: Additional gap between words in 10 ms units (default: 0) if (meSpeak.isVoiceLoaded('de') meSpeak.setDefaultVoice('de'); // note: the default voice is always the the last voice loaded meSpeak.loadVoice('fr.json', userCallback); // userCallback is an optional callback-handler. The callback will receive two arguments: // * a boolean flag for success // * either the id of the voice, or a reason for errors ('network error', 'data error', 'file error') alert(meSpeak.getDefaultVoice()) // 'fr' if (meSpeak.isConfigLoaded()) meSpeak.speak('Configuration data has been loaded.'); // note: any calls to speak() will be deferred, if no valid config-data has been loaded yet.

Voices currently available

JSON File Formats

1) Config-data: "mespeak_config.json":
The config-file includes all data to configure the tone (e.g.: male or female) of the electronic voice.

{ "config": "<base64-encoded octet stream>", "phontab": "<base64-encoded octet stream>", "phonindex": "<base64-encoded octet stream>", "phondata": "<base64-encoded octet stream>", "intonations": "<base64-encoded octet stream>" }

Finally the JSON object may include an optional voice-object (see below), that will be set up together with the config-data:

{ ... "voice": { <voice-data> } }

2) Voice-data: "voice.json":
A voice-file includes the ids of the voice and the dictionary used by this voice, and the binary data of theses two files.

{ "voice_id": "<voice-identifier>", "dict_id": "<dict-identifier>", "dict": "<base64-encoded octet stream>", "voice": "<base64-encoded octet stream>" }

Both config-data and voice-data may be loaded and switched on the fly to (re-)configure meSpeak.js.

Deferred Calls

In case that speak() is called before configuration and/or voice data has been loaded, the call will be deferred and executed after set up.
See this page for an example. You may reset the queue manually by calling

meSpeak.resetQueue();

Source

Download (all code under GPL): mespeak.zip
(Last update: 2011-12-12 14:00 GMT)


About speak.js

speak.js is 100% clientside JavaScript. It uses eSpeak, an open source speech synthesizer, which was compiled from C++ to JavaScript using Emscripten. The project page and source code for this demo can be found here.

Browser requirements:

Note that recent versions of these browsers are needed in most cases.