meSpeak.js (( • ))

Text-To-Speech on the Web

Text:

Options: Amplitude: Pitch: Speed: Word gap: Variant:

Voice:


First things first: Where can I download this? — See the download-link below.

About

meSpeak.js (modulary enhanced speak.js) is a 100% client-side JavaScript text-to-speech library based on the speak.js project, a port of the eSpeak speech synthesizer from C++ to JavaScript using Emscripten.
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 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). 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/Opera, Webkit, and Safari (MSIE11 is expected to be compliant).

meSpeak.js 2011-2020 by Norbert Landsteiner, mass:werk – media environments; https://www.masswerk.at/mespeak/

GNU General Public License
The eSpeak text-to-speech project is licensed under version 3 of the GNU General Public License.
Since meSpeak.js incorporates eSpeak, the same license (GPL v.3) applies.

Important Changes:

v 2.0 Major Upadate — Introducing a web worker for rendering the audio concurrently (outside the UI thread), reduced file size, basic audio filtering and stereo panning, and a new, simplified loading scheme for loading voice/language definitions.
v 2.0.1 Added meSpeak.getAudioAnalyser(), because, why not?
v 2.0.2 Disabled workers on mobile diveses.
v 2.0.3 Changed implementation of meSpeak.getAudioAnalyser().
v 2.0.4 Added a simple mobile unlocker (initial touchstart event handler).
(v. 2.0.5 Added the original eSpeak license statement.)
v 2.0.6 Added a workaround an issue with some browsers after the 80th call.
v 2.0.7 Added audio unlocking for Safari desktop browsers.

Some real world examples (at masswerk.at):
• Explore client-side speech I/O with E.L.I.Z.A. Talking
• Celebrating meSpeak.js v.1.5: JavaScript Doing The JavaScript Rap (featuring MC meSpeak) (a heavy performance test)
• Celebrating meSpeak.js v.2.0: MeSpeak.js Stereo Panning Demo (reading a dialog by distributed roles)
Audio Anaylser Demo, a simple oscilloscope display for meSpeak.js.

New in MeSpeak 2.0

Usage

meSpeak.loadVoice('voices/en/en-us.json'); or just meSpeak.loadVoice('en/en-us'); meSpeak.speak('hello world'); meSpeak.speak('hello world', { option1: value1, option2: value2 .. }); meSpeak.speak('hello world', { option1: value1, option2: value2 .. }, myCallback); var id = meSpeak.speak('hello world'); meSpeak.stop(id); meSpeak.speak( text [, { option1: value1, option2: value2 .. } [, callback ]] ); text: The string of text to be spoken. The text may contain line-breaks ("\n") and special characters. Default text-encoding is UTF-8 (see the option "utf16" for other). options (eSpeak command-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) * variant: One of the variants to be found in the eSpeak-directory "~/espeak-data/voices/!v" Variants add some effects to the normally plain voice, e.g. notably a female tone. Valid values are: "f1", "f2", "f3", "f4", "f5" for female voices "m1", "m2", "m3", "m4", "m5", "m6, "m7" for male voices "croak", "klatt", "klatt2", "klatt3", "whisper", "whisperf" for other effects. (Using eSpeak, these would be appended to the "-v" option by "+" and the value.) Note: Try "f2" or "f5" for a female voice. * linebreak: (Number) Line-break length, default value: 0. * capitals: (Number) Indicate words which begin with capital letters. 1: Use a click sound to indicate when a word starts with a capital letter, or double click if word is all capitals. 2: Speak the word "capital" before a word which begins with a capital letter. Other values: Increases the pitch for words which begin with a capital letter. The greater the value, the greater the increase in pitch. (eg.: 20) * punct: (Boolean or String) Speaks the names of punctuation characters when they are encountered in the text. If a string of characters is supplied, then only those listed punctuation characters are spoken, eg. { "punct": ".,;?" }. * nostop: (Boolean) Removes the end-of-sentence pause which normally occurs at the end of the text. * utf16: (Boolean) Indicates that the input is UTF-16, default: UTF-8. * ssml: (Boolean) Indicates that the text contains SSML (Speech Synthesis Markup Language) tags or other XML tags. (A small set of HTML is supported too.) further options (meSpeak.js specific): * volume: Volume relative to the global volume (number, 0..1, default: 1) Note: the relative volume has no effect on the export using option 'rawdata'. * log: (Boolean) Logs the compiled eSpeak-command to the JS-console. * pan: (Number) Stereo panning, -1 >= pan <= 1 -1 represents the extreme left 1 represents the extreme right 0 center (no effect) This option is available only with clients supporting the Web Audio API. * rawdata: Do not play, return audio data (wav) in callback. (A callback, see below, has to be specified in order to retrieve the data stream.) The type of the returned data is derived from the value (case-insensitive) of 'rawdata': - 'base64': returns a base64-encoded string. - 'mime': returns a base64-encoded data-url (including the MIME-header). (synonyms: 'data-url', 'data-uri', 'dataurl', 'datauri') - 'array': returns a plain Array object with uint 8 bit data. - default (any other value): returns the generated wav-file as an ArrayBuffer (8-bit unsigned). Note: The value of 'rawdata' must evaluate to boolean 'true' in order to be recognized. callback: An optional callback function to be called after the sound output ended. function myCallback(success, id [, stream]) { ... } * success (Boolean): flag indicating the success of the operation * id (Number): 32-bit id, defaults to 0 * stream (*): data stream of the wav-file in the format specified by the "rawdata" option. Defaults to ArrayBuffer (uint8). If the resulting sound is stopped by meSpeak.stop(), the success-flag will be set to false. (A callbak may be also specified as a property of the options object. If both are present, the callback argument takes precedence.) Returns: * a 32bit integer ID greater than 0 (or 0 on failure). The ID may be used to stop this sound by calling meSpeak.stop(<id>). meSpeak.loadVoice('voices/fr.json', userCallback); meSpeak.loadVoice('en/en-us', 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') Note: Starting with meSpeak.js 2.0, voices are loaded relative to meSpeak.js. Also, if you just specify a voice-id, meSpeak.js will now try to load a respective voice from a directory "voices" in the same directory as the script. e.g., loadVoice('fr') will load '/path/to/mespeak/voices/fr.json', loadVoice('en/en-us') will load 'path/to/mespeak/voices/en/en-us.json'. A newly loaded voice will always become the new default voice: meSpeak.loadVoice('fr'); alert(meSpeak.getDefaultVoice()); // 'fr' meSpeak.setDefaultVoice('de'); Sets the default voice to the voice with the voice with the id specified. (Note: If not explicitly set the default voice is always the the last voice loaded.) if (meSpeak.isVoiceLoaded('de')) meSpeak.setDefaultVoice('de'); Check, if a voice has been successfully loaded. meSpeak.loadConfig() meSpeak.isConfigLoaded() Legacy methods. A standard configuration is now included in meSpeak.js. meSpeak.loadConfig() does nothing meSpeak.isConfigLoaded() returns always true However, you can still load a custom configuration using meSpeak.loadCustomConfig(url, callback) As with vocies, config-files will be loaded relative to the mespeak.js script. An optional callback will have two arguments, a boolean success flag and a message string reporting any reasons for failing the operation. A custom congiguration may include just some of the eSpeak config-files. Any files found, will overwrite the standard configurations. meSpeak.setVolume(0.5); meSpeak.setVolume( volume [, id-list] ); Sets a volume level (0 <= v <= 1) * if called with a single argument, the method sets the global playback-volume, any sounds currently playing will be updated immediately with respect to their relative volume (if specified). * if called with more than a single argument, the method will set and adjust the relative volume of the sound(s) with corresponding ID(s). Returns: the volume provided. alert(meSpeak.getVolume()); // 0.5 meSpeak.getVolume( [id] ); Returns a volume level (0 <= v <= 1) * if called without an argument, the method returns the global playback-volume. * if called with an argument, the method will return the relative volume of the sound with the ID corresponding to the first argument. if no sound with a corresponding ID is found, the method will return 'undefined'. var browserCanPlayWavFiles = meSpeak.canPlay(); // test for compatibility meSpeak.play( stream [, relativeVolume [, callback[, id[, pan]]]] ); Play (cached) audio streams (using any of the export formats, ArrayBuffer, array, base64, dta-URL) Arguments: stream: A stream in any of the formats returned by meSpeak.play() with the "rawdata"-option. volume: (optional) Volume relative to the global volume (number, 0..1, default: 1) callback: (optional) A callback function to be called after the sound output ended. The callback will be called with a single boolean argument indicating success. If the sound is stopped by meSpeak.stop(), the success-flag will be set to false. (See also: meSpeak.speak().) id: (optional, Number) An id to be used (default 0 => ignored.) meSpeak.play(myAudio, 1, null, mySoundId); meSpeak.stop(mySoundId); pan: (optional, Number) Stereo panning. (left) -1 >= pan <= 1 (right) Mind that this works only with clients supporting the Web Audio API. Returns: A 32bit integer ID greater than 0 (or 0 on failure). The ID may be used to stop this sound by calling meSpeak.stop(<id>). // exaple for caching and playing back audio streams var audiostreams = []; meSpeak.speak('hello world', { 'rawdata': true }, function(success, id, stream) { // data is ArrayBuffer of 8-bit uint audiostreams.push(stream); }); meSpeak.speak('hello again', { 'rawdata': 'array' }, function(success, id, stream) { // data is Array of 8-bit uint Numbers audiostreams.push(stream); }); meSpeak.speak('hello again', { 'rawdata': 'base64' }, function(success, id, stream) { // data is a string containing the base64-encoded wav-file audiostreams.push(stream); }); meSpeak.speak('hello yet again', { 'rawdata': 'data-url' }, function(success, id, stream) { // data is a data-URL with MIME-header "data:audio/x-wav;base64" audiostreams.push(stream); }); meSpeak.play(audiostreams[0]); // using global volume meSpeak.play(audiostreams[1], 0.75); // 75% of global volume meSpeak.play(audiostreams[2], 0, null, 0, -1); // play if from the left meSpeak.play(audiostreams[3], 0, 0, 0, 0.25); // play it from a querter to the right meSpeak.stop( [<id-list>] ); Stops the sound(s) specified by the id-list. If called without an argument, all sounds currently playing, processed, or queued are stopped. Any callback(s) associated to the sound(s) will return false as the success-flag. Arguments: id-list: Any number of IDs returned by a call to meSpeak.speak() or meSpeak.play(). Returns: The number (integer) of sounds actually stopped. meSpeak.setFilter(<options>[,<options>]); New in meSpeak 2.0: Set filters for audio playback (post processing). Supported are any of the BiquadFilters and DynamicsCompressors. You may add any number of filters, which will be chained together before feeding into the gloabel gain node. Options: type: (String) Filter type, case-insenstitive BiquadFilters: 'lowpass', 'highpass', 'bandpass', 'lowshelf', 'highshelf', 'peaking', 'notch', 'allpass' DynamicsCompressor: 'dynamicscompressor' or 'compressor' For BiquadFilters: frequency (Number) Q (Number) gain (Number) detune (Number) For DynamicsCompressors: threshold (Number) knee (Number) ratio (Number) reduction (Number) attack (Number) release (Number) // Example: meSpeak.setFilter( { type: 'highpass', frequency: 85 }, { type: 'compressor', threshold: -10, knee: 40, ratio: 5, attack: 0, release: 0.25 }, { type: 'bandpass', frequency: 500, Q: 0.125, detune: 10 } ); myAnalyserNode = meSpeak.getAudioAnalyser(); returns an Web Audio AnalyserNode for further processing (e.g., a wave display) of the signal played by meSpeak.js. The AnalyserNode mirrors the signal present in the first global audio processing stage (after individual volume/gain), but before filters. Compare the Audio Anaylser Demo. meSpeak.getRunMode(); Determine, if the client is running a concurrent worker or a single-threaded instance. Returns either the string "worker" or "instance" meSpeak.restartWithInstance(); For testing purposes only: Restart MeSpeak forcing it to use an instance instead of a worker. Returns: nothing / void.

Note on export formats, ArrayBuffer (typed array, defaul) vs. simple array:
The ArrayBuffer (8-bit unsigned) provides a stream ready to be played by the Web Audio API (as a value for a BufferSourceNode), while the plain array (JavaScript Array object) may be best for export (e.g. sending the data to Flash via Falsh's ExternalInterface). The default raw format (ArrayBuffer) is the preferred format for caching streams to be played later by meSpeak by calling meSpeak.play(), since it provides the least overhead in processing.

Recommended File Layout

In order to ensure the functionality of meSpeak.js, the following layout is strongly encouraged:

mespeak/ mespeak.js # required mespeak-core.js # required voices/ # default location ca.json cs.json de.json ...

Mind that you just require thos vocie definitions which you are actually using.

meSpeak.speakMultipart() — concatenating multiple voices

Using meSpeak.speakMultipart() you may mix multiple parts into a single utterance.

See the Multipart-Example for a demo.

The general form of meSpeak.speakMultipart() is analogous to meSpeak.speak(), but with an array of objects (the parts to be spoken) as the first argument (rather than a single text):

meSpeak.speakMultipart( <parts-array> [, <options-object> [, <callback-function> ]] ); meSpeak.speakMultipart( [ { text: "text-1", <other options> ] }, { text: "text-2", <other options> ] }, ... { text: "text-n", <other options> ] }, ], { option1: value1, option2: value2 .. }, callback );

Only the the first argument is mandatory, any further arguments are optional.
The parts-array must contain a single element (of type object) at least.
For any other options refer to meSpeak.speak(). Any options supplied as the second argument will be used as defaults for the individual parts. (Same options provided with the individual parts will override these defaults.)
The method returns — like meSpeak.speak() — either an ID, or, if called with the "rawdata" option (in the general options / second argument), a stream-buffer representing the generated wav-file.

Note on iOS and Mobile Limitations

iOS (currently supported only using Safari) provides a single audio-slot, playing only one sound at a time.
Thus, any concurrent calls to meSpeak.speak() or meSpeak.play() will stop any other sound playing.
Further, iOS reserves volume control to the user exclusively. Any attempt to change the volume by a script will remain without effect.
Please note that you still need a user-interaction at the very beginning of the chain of events in order to have a sound played by iOS.

Note on Options

The first set of options listed above corresponds directly to options of the espeak command. For details see the eSpeak command documentation.
The meSpeak.js-options and their espeak-counterparts are (mespeak.speak() accepts both sets, but prefers the long form):

meSpeak.jseSpeak
amplitude-a
wordgap-g
pitch-p
speed-s
voice-v
variant-v<voice>+<variant>
utf16-b 4 (default: -b 1)
linebreak-l
capitals-k
nostop-z
ssml-m
punct--punct[="<characters>"]

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>" }

Alternatively the value of "voice" may be a text-string, if an additional property "voice_encoding": "text" is provided.
This shold allow for quick changes and testing:

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

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

For a guide to customizing languages and voices, see meSpeak – Voices & Languages.

Extendet Voice Format, Mbrola Voices

In order to support Mbrola voices and other voices requiring a more flexible layout and/or additional data, there is also an extended voice format:

{ "voice_id": "<voice-identifier>", "voice": "<base64-encoded octet stream>" "files": [ { "path", "<rel-pathname>", "data", "<base64-encoded octet stream>" }, { "path", "<rel-pathname>", "data", "<text-string>", "encoding": "text" }, ... ] }

or (using a text-encoded voice-definition):

{ "voice_id": "<voice-identifier>", "voice": "<text-string>", "voice_encoding": "text" "files": [ { "path", "<rel-pathname>", "data", "<base64-encoded octet stream>" }, { "path", "<rel-pathname>", "data", "<text-string>", "encoding": "text" }, ... ] }

Only a valid voice-definition is required and optionally an array "files" which may be empty or contain any number of objects, containing a property "path" (relative file-path from the espeak-data-directory) and a property "data", containing the file (either as base64-encoded data or as plain text, if there is also an optional property "encoding": "text").

In order to facilitate the use of Mbrola voices, for any "voice_id" beginning with "mb/mb-" only the part following the initial "mb/" will be used as the internal identifyer for the meSpeak.speak() method. (So any given voice_id "mb/mb-en1" will be translated to a voice "mb-en1" automatically. This applies to the speak-command only.)

Please don't ask for support on Mbrola voices (I don't have the faintest idea). Please refer to Mbrola section of the eSpeak documentation for a guide to setting up the required files locally. It should be possible to load these into meSpeak.js using the "extended voice format", since you may put any additional payload into the files-array. Please mind that you will still require a text-to-phoneme translator as stated in the eSpeak documentation (this is out of the scope of meSpeak.js).

Deferred Calls

In case that speak() is called before any 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();

Amplitude and Volume

There are now two separate parameters or options to control the volume of the spoken text: amplitude and volume.
While amplitude affects the generation of the sound stream by the TTS-algorithm, volume controls the playback volume of the browser. By the use of volume you can cache a generated stream and still provide an individual volume level at playback time. Please note that there is a global volume (controlled by setVolume()) and an individual volume level relative to the global one. Both default to 1 (max volume).

Notes on Chinese Languages and Voices

Please note that the Chinese voices do only support Pinyin input (phonetic transcript like "zhong1guo2" for 中 + 国, China) for "zh" and simple one-to-one translation from single Simplified Chinese characters or Jyutping romanised text for "zh-yue".

The eSpeak documentation provides the following notes:

*) zh (Mandarin Chinese):
This speaks Pinyin text and Chinese characters. There is only a simple one-to-one translation of Chinese characters to a single Pinyin pronunciation. There is no attempt yet at recognising different pronunciations of Chinese characters in context, or of recognising sequences of characters as "words". The eSpeak installation includes a basic set of Chinese characters. More are available in an additional data file for Mandarin Chinese at: http://espeak.sourceforge.net/data/.
**) zh-yue (Cantonese Chinese, Provisional):
Just a naive simple one-to-one translation from single Simplified Chinese characters to phonetic equivalents in Cantonese. There is limited attempt at disambiguation, grouping characters into words, or adjusting tones according to their surrounding syllables. This voice needs Chinese character to phonetic translation data, which is available as a separate download for Cantonese at: http://espeak.sourceforge.net/data/.
The voice can also read Jyutping romanised text.

For a simple zh-to-Pinyin translation in JavaScript see: https://www.masswerk.at/mespeak/zh-pinyin-translator.zip

Flash-Fallback for Wave Files

(m)eSpeak produces internally wav-files, which are then played. Internet Explorer 10 supports typed arrays (which are required for the binary logic), but does not provide native playback of wav-files. To provide compatibility for this browser, you could try the experimental meSpeak Flash Fallback.

Source

Download (all code under GPL): mespeak.zip
(v.2.0.7, last update: 2020-04-23)

The last version of the old API, v.1.9.7.1 may be downloaded here: mespeak_1-9-7-1.zip

Version History

v.2.0.7
Added audio unlocking for Safari desktop browsers.
v.2.0.6
Added a call counter to restart the core internally after the 80th count to work around a memory leak with some browsers. (It's unclear, if this is caused by the JS runtime or by the eSpeak code or the translation by Emscripten. At least, it's a browser specific issue.)
v.2.0.5
Added the original eSpeak license statement.
v.2.0.4
Added a simple mobile unlocker (plays a short, inaudible sound on the first touchstart event).
v.2.0.3
Changed implementation of meSpeak.getAudioAnalyser().
v.2.0.2
Oops, we can't play sounds on a postMessage event (no user interaction) on iOS and probably othe mobile systems as well. So workers are disabled on mobile devices.
v.2.0.1
Added meSpeak.getAudioAnalyser().
v.2.0
Major update. Now running a worker for the care application (or a separate instance for compatibility with older clients). Reduced file size, some new methods, minor API changes. (See note on top.)
v.1.9.7
Fix for Web Audio API changes in Apple Safari 9.x (Mac OS X and iOS, compare v.1.9.2).
v.1.9.6
Minor internal changes.
v.1.9.5
Added meSpeak.speakMultipart().
Also, meSpeak.speak() and meSpeak.speakMultipart() won't fail on a missing voice any more: As soon as there is a default-voice loaded and set, the default-voice will be used instead.
v.1.9.4.1
Fixed a bug in the error handling on missing voices.
v.1.9.4
Finally found a work-around for the Emscripten FS breaking on the 80th call to run() (internally called by meSpeak.speak()): We now reboot gracefully, preserving any loaded files; no external effects or differences in behavior are caused by this. In order to accomplish this, the eSpeak-core is now run as an instance of a constructor.
v.1.9.3
Added support for the Unicode Basic Latin and Latin-1 Supplement character range (U+0000 . U+00FF).
(Emscripten originally supports only the C-locale, 7-bit ASCII.)
v.1.9.2
Fix for Chrome 32: Worked around a behavioral change (bug?) in Chrome 32.
It might be worth noting that it is no more possible to play back sound with the Web Audio API by the same code with Webkit iOS and Chrome while using the decodeAudioData-method. (Welcome back to user-agent sniffing. Really Google?)

Since this might be of general interest, here is a short tutorial:

/* Cross-Browser Web Audio API Playback With Chrome And Callbacks */ // alias the Web Audio API AudioContext-object var aliasedAudioContext = window.AudioContext || window.webkitAudioContext; // ugly user-agent-string sniffing var isChrome = ((typeof navigator !== 'undefined') && navigator.userAgent && navigator.userAgent.indexOf('Chrome') !== -1); var chromeVersion = (isChrome)? parseInt( navigator.userAgent.replace(/^.*?\bChrome\/([0-9]+).*$/, '$1'), 10 ) : 0; function playSound(streamBuffer, callback) { // set up a BufferSource-node var audioContext = new aliasedAudioContext(); var source = audioContext.createBufferSource(); source.connect(audioContext.destination); // since the ended-event isn't generally implemented, // we need to use the decodeAudioData()-method in order // to extract the duration to be used as a timeout-delay audioContext.decodeAudioData(streamBuffer, function(audioData) { // detect any implementation of the ended-event // Chrome added support for the ended-event lately, // but it's unreliable (doesn't fire every time) // so let's exclude it. if (!isChrome && source.onended !== undefined) { // we could also use "source.addEventListener('ended', callback, false)" here source.onended = callback; } else { var duration = audioData.duration; // convert to msecs // use a default of 1 sec, if we lack a valid duration var delay = (duration)? Math.ceil(duration * 1000) : 1000; setTimeout(callback, delay); } // finally assign the buffer source.buffer = audioData; // start playback for Chrome >= 32 // please note that this would be without effect on iOS, since we're // inside an async callback and iOS requires direct user interaction if (chromeVersion >= 32) source.start(0); }, function(error) { /* decoding-error-callback */ }); // normal start of playback, this would be essentially autoplay // but is without any effect in Chrome 32 // let's exclude Chrome 32 and higher to avoid any double calls anyway if (!isChrome || chromeVersion < 32) { if (source.start) { source.start(0); } else { source.noteOn(0); } } }

v.1.9.1
Added support for IDs to meSpeak.setVolume() and meSpeak.getVolume() in order to optionally address relative playback volumes of individual sounds.
(If IDs are supplied as optional arguments, the volume will be the relative volume of the sound(s) with corresponding ID(s), else the global playback volume.)
v.1.9
Added meSpeak.stop(). For this a new return value is introduced:
meSpeak.speak() and meSpeak.play() return now a 32bit numeric ID (quite like setTimeout()).
IDs may be provided to meSpeak.stop() as argument(s) in order to stop specific sounds.
If meSpeak.stop() is called without any arguments, all sounds currently processed, playing, or queued will be stopped.
meSpeak.speak() returns still an audio-stream in the requested format, if called with the "rawdata"-option.
In case of failing, 0 is returned as an ID (or null with a "rawdata"-request), while a successful call will always return an ID greater than 0.
v.1.8.7
Returned to improved handling of durations reported by Web Audio streams, used to handle callbacks. This is as in 1.8.5.
v.1.8.6
Fixed a bug (itroduced in a previous version) preventing tablet-based webkit-browsers from actually playing. (So you can't start a sound from inside the decodeAudioData()-callback?)
v.1.8.5
Disabled the Web Audio source-node's onended event-handler for Chrome to work around a bug in Chrome, where the event is not firing reliably. (We are falling back to a timeout on the stream's duration like before Chrome implemented the onended event.)
v.1.8.4
speak() now also accepts the eSpeak flags as option keys (e.g. "k" for "capitals" or "v" for "voice", cf. the note on options).
Added documentation for the "punct"-option.
v.1.8.3
speak() now cleans up the filesystem from the internal wav-file after use and returns a unique array of the resulting sound-data (rather than just a pointer to the array produced by emscriptens filesystem).
v.1.8.2
Added a a bit of delay before finally unlinking any Web Audio API resources (working around a Chrome duration issue). meSpeak.play() now reports in the log the object type of any unsuitable input.
v.1.8.1
Tweeked the handling of Mbrola voices.
v.1.8
Added support for extended voice-formats (like Mbrola voices).
v.1.7
Added support for various minor eSpeak-options (now the full set of usable options is supported).
Also, we indicate explicitely that the text to be spoken is UTF-8 encoded (if not specified otherwise) rather than reliying on defaults.
v.1.6
Added support for voice-variants.
v.1.5.1
Fixed deferred call option to include and execute any callbacks.
v.1.5
Added an optional callback to meSpeak.speak() and meSpeak.play().
Added some clean-up code to prevent any memory leaks with some implementations of the Web Audio API.
Removed any references to "window" in favor for "self".
v.1.4.4
Cleaned up a bit of the Emscripten-generated code, changed wording in this page.
v.1.4.3
Better handling for base64-imports when using the HTMLAudioElement for playback with meSpeak.play(). (Less overhead.)
v.1.4.2
Added base64 or data-url as import-format for meSpeak.play().
v.1.4.1
Added a guide to voices and languages and an experimental Flash-fallback for MSIE10. No changes to the meSpeak-code.
v.1.4
Added an option to export data as a plain array.
v.1.3.1
Fixed a bug in the decoding of text-formatted voice data.
v.1.3
Added alternative text format for voices.
v.1.2
Added volume control and capability to play back exported audio-streams.
v.1.1
Added support for the Web Audio API (AudioContext), which is now the preferred method to play the generated sound. Browsers lacking support for the Web Audio API will use the HTMLAudioElement for playback. (v.1.1 was succesfully tested to play on iOS 6/Safari.) Also added an option to export the raw data in various formats.
v.1.04
Demo-page: Auto-speak will now be triggered only, if a URL-parameter "auto" set to "true" or "1" is provided.
(This additional parameter should inhibit any repeated attempts to play in case the script would fail and the demo-form would be sent via GET-parameters.)
v.1.03
Added an instant link for auto-speak to this demo-page.
v.1.02
Added Chinese voice-data (zh, zh-yue) by popular request.
v.1.01
Added an onload-callback to the assignment of the generated audio-data-URL. This should add compatibility to newer versions of WebKit and Chrome.
v.1.0
Initial upload.

About speak.js

speak.js is 100% clientside JavaScript. "speak.js" is a port of 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.
Note: There had been initially plans to merge this project with speak.js, but they somehow became stuck.

Browser requirements:

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