Coder Social home page Coder Social logo

kripken / speak.js Goto Github PK

View Code? Open in Web Editor NEW
1.3K 54.0 295.0 5.24 MB

Text-to-Speech in JavaScript using eSpeak

License: GNU General Public License v3.0

JavaScript 0.40% C 18.73% Shell 0.18% Python 0.08% C++ 77.44% HTML 0.14% Makefile 0.51% Inno Setup 1.40% Objective-C 1.12%

speak.js's Introduction

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

speak.js's People

Contributors

kripken avatar yukulele avatar

Stargazers

ReadWriteReality avatar Kyle Bob Mullens avatar Scott G avatar Mickael Araujo avatar Frey Frazão avatar Boning Li avatar Rik Hoffbauer avatar Dirk Krause avatar Marin Larsen avatar Rodrigo Pedra Brum avatar Jared Van Valkengoed avatar Carlos Vinicius Ananias avatar zhugqing avatar Jira Nguyễn avatar Đỗ Danh Mạnh avatar Luke Heerman avatar Felix Xi avatar treecko avatar Tibor Szász avatar Samer W Ali avatar Damian Feigelmuller avatar Burin Lumyai avatar  avatar  avatar  avatar Yuyu avatar Zhangcy avatar Ivan Dyumin avatar Eduardo Arruda avatar Jeff Xie avatar kurple avatar wonderzhu avatar Brad avatar Jelmer Veen avatar Mr_J avatar Todd Fast avatar Mikkel Ricafrente avatar  avatar  avatar stretch avatar Jesse Jones avatar Mr.kouhadi (中国朋友叫我布莱恩) avatar JulianZhu avatar Steven Lee avatar Krishnamurthy G B avatar john avatar  avatar iorileslie avatar Dylan Barva avatar Edgar Bermejo avatar  avatar Kirstian_Git avatar  avatar  avatar  avatar hunbL avatar  avatar  avatar  avatar Maumau avatar  avatar Ed Saleh avatar Shawn avatar Arash avatar  avatar  avatar Showns avatar  avatar Lon Beshiri avatar Zack avatar Rick Barraza avatar Liril Colombia avatar Luke Stanley avatar Gianni Hong avatar Gino avatar なすどんぐり avatar  avatar Benno Kruit avatar  avatar Yoshiki Kadoshita avatar  avatar  avatar  avatar Nikola Stamatović avatar Chetan Padia avatar amadman avatar Natalia Shmueli avatar  avatar Tim von Känel avatar  avatar Vitor Hugo Salgado avatar Luis Felipe Sousa avatar Sean P. Myrick V19.1.7.2 avatar Mikael Elmblad avatar  avatar Felipe Schenone avatar Bender Bending Rodriguez avatar Gnlow avatar Luis Phelipe avatar Reva Gomes avatar

Watchers

Bruno Leles avatar Dirk Sidney Jansen avatar  avatar Bastian Bittorf avatar Innovimax avatar Agus Made avatar Diego Terzano avatar  avatar a Goblin King avatar Neil avatar  avatar mindon avatar 小爪哇 avatar  avatar  avatar 정 경훈 (Kyung-hown Chung) avatar James Cloos avatar Ali Ismail avatar Pascal Garber avatar inmyfree avatar smjrifle avatar Daisuke Shimizu avatar Shima Chikao avatar Malte Kosian avatar Michael Anthony avatar Dmitry Atamanov avatar Fabrício Seger Kolling avatar Michael Paulukonis avatar Pavan avatar Krishnamurthy G B avatar Vu Bao Nhu avatar wurenhai avatar liuliu avatar  avatar Noel Koutlis avatar Tom Sparks avatar  avatar AJW  avatar Ernane Laranjo avatar Prasad Madhbhavikar avatar  avatar  avatar Rahul Y Gupta avatar Ryan Bregier avatar  avatar 王世锋 avatar KANGXI APPS avatar ram avatar Statanis 123 avatar  avatar  avatar Ashutosh Tripathi avatar Sean P. Myrick V19.1.7.2 avatar  avatar

speak.js's Issues

Windows compilation fail

hi guys, i'm getting this error when trying to compile in windows (please don't judge me, not my choice :D ) with cygwin

fs.js:338
return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
^
Error: ENOENT, no such file or directory 'C:\tmp\tmp6uCJ03.txt'
at Object.fs.openSync (fs.js:338:18)
at Object.fs.readFileSync (fs.js:182:15)
at read (C:\opt\emscripten\src\compiler.js:36:37)
at Object. (C:\opt\emscripten\src\compiler.js:120:29)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:492:10)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)
Traceback (most recent call last):
File "/opt/emscripten/emcc", line 871, in
final = shared.Building.emscripten(final, append_ext=False, extra_args=extra_args)
File "/opt/emscripten/tools/shared.py", line 736, in emscripten
assert os.path.exists(filename + '.o.js') and len(open(filename + '.o.js', 'r').read()) > 0, 'Emscripten failed to generate .js: ' + str(compiler_output)
AssertionError: Emscripten failed to generate .js:
cat: speak.raw.js: No such file or directory

I tryed changing the /tmp folder in emscripten config file and didn't work(it's like the file was never created, even when full access to /tmp folder or C:\tmp folder). I'm not sure if this is a Node issue or what. any ideas?

Bad voice option : error

Hey,

I'm busy trying to modify speak.js to work on the Node.js platform, and I keep running into this error:
Bad voice option: option reduce_t 1 is anyone able to explain whats going wrong here?

Thanks in advance.

Re: speak.js on Node, as currently speak.js relies on typed arrays, it will only be compatible with Node.js >= 0.5.5
Also running into memory issues but i'll get round to that later.

Doesn't work on Android 4.0

In theory, Android 4.0 should support typed arrays. However, when trying to initialize a Float64Array over an existing buffer an INDEX_SIZE_ERR is thrown. Therefore generateSpeech doesn't really work

Getting raw data without decoding the wav

Hey there!

Great job on this, but I'm currently needing only the raw data as a Float32Array (applying effects to it and using Audio APIs for playback), so it feels somewhat silly that I have to decode the wav file to get that. The process takes a while as it is and eliminating the step where speak.js first encodes the file as a wav and then I decode that wav would probably save a good while of the user's time.

Am I missing something and is this possible? Or would it be possible to get this in the future?

Cheers,
Jussi

Make Voice data optional/external

Hi,

is there any way to make the language wav data (voices/gramar) optional/external
so no need to rebuild speak.js everytime another language needs support

sth like having the wav data in a separate js file and add them as parameters to the main speak.js Class

sth like https://github.com/foo123/HAAR.js where the feature data are external and the detector is generic

Thanks

Words ending in vowels

speak.js seems to have trouble with words ending in vowels. The vowels tend to get detached or lost. Here are a few:

  • data
  • daily
  • Millbrae
  • menagerie

Other words that sound OK, but have detached sounds at the end

  • melee

Cannot set property 'onmessage' of undefined

I try on Windows 7 and demo.html doesn't work.
From the javascript console of Google Chrome:
speak.js warning: no worker support
Cannot set property 'onmessage' of undefined from line 98 of speakClient.js.
Please help me

all -at ending words are mispronounced

Try the words chat, fat, shat...etc. All -at ending words seem to be mispronounced. I think the speak.js module is unable to distinguish between the word sound if the letters were at the end of the word vs beginning.

Synchronous or callback options

hey there,
I was just wondering if there was a way to make speak() a synchronous call or if there was any sort of callback functionality available.

Node.js version?

Would it be possible / make any sense to have a node.js version of this module?

Currently we use http://github.com/marak/say.js , which is nothing more then a child process wrapper for whatever native TTS binary exists on the machine.

Would be nice to be able to do this all in pure JS.

French version

Hello,

Have you a French version for javascript files because I have a little difficulty to recompile.

thank you

speak.js doesnt work on chrome, safari and opera ...

Hi,
I'm trying to using speak.js but it is not working when using chrome, safari and opera and it is working using FireFox,
Can you helop me?
the error i get using chrome is "Uncaught TypeError: Cannot set property 'onmessage' of undefined" on line "speakWorker.onmessage = function(event) {

and when Im trying to define: speakWorker = new Worker('speakWorker.js');
i get "Uncaught SecurityError: Failed to create a worker: script at 'file:///C:/Users/ortal.lagziel/Desktop/pp/speak-js-master/speakWorker.js' cannot be accessed from origin 'null'."
Thanks

Changing pronunciation?

I'm building a speaking calculator, so I need to change how speak.js reads the numeric function characters (+, -, *, /) to plus, minus, times and divide.

*Plus already works

Silent build failure

I want to build speak.js from source with multiple languages, only tried to add french for now, but somehow it fails silently.

This is the last part of the output I get:

espeak.cpp:358:4: warning: conversion from string literal to 'char *' is deprecated
        [-Wdeprecated-writable-strings]
                {"ipa",     no_argument,       0, 0x10a},
                    ^
12 warnings generated.
mv libespeak.so libespeak.so.1.1.45
/bin/ln -sf libespeak.so.1.1.45 libespeak.so.1
/bin/ln -sf libespeak.so.1 libespeak.so
/root/sources/emscripten/em++  -o espeak espeak.o -lstdc++ -L . -lespeak
llvm-ld: error: Cannot link in module '/tmp/tmpkzZ3iN/libespeak.a(x_speak_lib.o)': Linking globals named '_Z13GetFileLengthPKc': symbol multiply defined!
emscripten
root@debian:~/sources/speak.js/src# ls -l
total 8772
-rwxrwxrwx 1 root root    3562 Dec 13 01:13 Makefile
-rwxrwxrwx 1 root root      71 Dec 13 01:13 StdAfx.h
-rwxr-xr-x 1 root root      86 Dec 13 04:16 a.out
…

(Don't mind the file timestamp, it doesn't update)

OS: Debian 6
LLVM & Clang v3.0 (cbuild)
Node v0.6.5

# ~/.emscripten
# defined NODE_JS, SPIDERMONKEY_ENGINE & CLOSURE COMPILER
# but not the V8_ENGINE

COMPILER_ENGINE = NODE_JS
JS_ENGINES = [NODE_JS]

Lagunge and Gender implementation

Hi ,

great work done by you ., thanks a lot

can u please help me how can i implement different language in speak.js .
i had wrote this " speak('boulanger', { voice: 'fr' }) " but its give me the default english,
also how to get the female voice . please provide me solution ..

Read selected text

Hi,

If it possible to read a selected text from the site instead of reading input text?

All integers announced as "zero"

Hey there,

Thanks for building speak.js. It's easy to use and exactly what I need so far...

I have a (in my case fairly critical) problem: speak("4") speaks to "four", but speak("4 new") speaks "zero new". It works fine with native eSpeak on Ubuntu 11.04.

Announcing numbers is really important for my project, but I don't want to deal with translating numbers to words because I have a wide (theoretically infinite) range of numbers to announce.

Any ideas what could cause this problem?

Have a great day
Tom

"cat: speak.raw.js: File or directory not found" Language Support

I found this error when I tried to build speak.js for language support (using emscripten.sh, bundle.py, post.js). Follow the instructions in the file README.markdown

I use:
closure compiler
Node.js 0.6.6
clang + llvm 3.0
Ubuntu 11.10 32bits
later versions of emscriptem and speak.js


espeak.cpp:357:4: warning: conversion from string literal to 'char *' is
deprecated [-Wdeprecated-writable-strings]
{"pho", no_argument, 0, 0x109},
^
espeak.cpp:358:4: warning: conversion from string literal to 'char *' is
deprecated [-Wdeprecated-writable-strings]
{"ipa", no_argument, 0, 0x10a},
^
12 warnings generated.
emcc: x_debug.o: Not valid LLVM bitcode
mv libespeak.so libespeak.so.1.1.45
/bin/ln -sf libespeak.so.1.1.45 libespeak.so.1
/bin/ln -sf libespeak.so.1 libespeak.so
/home/alan/emscripten/em++ -o espeak espeak.o -lstdc++ -L . -lespeak
dis
emscripten
emcc: warning: The relooper optimization can be very slow.
Traceback (most recent call last):
File "/home/alan/emscripten/emcc", line 540, in
final = shared.Building.closure_compiler(final)
File "/home/alan/emscripten/tools/shared.py", line 659, in closure_compiler
'--js', filename, '--js_output_file', filename + '.cc.js'], stdout=PIPE, stderr=STDOUT).communicate()[0]
File "/usr/lib/python2.7/subprocess.py", line 679, in init
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1239, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

cat: speak.raw.js: File or directory not found

How to build it in windows?

untitled

vs-tools doesn't work, seems it's the problems of "include <wchar.h>",
but when include it:
C:/mingw64/bin\llvm-link: link error in 'C:\tmp\tmpz8qklq\espeak_3.o': Linking globals named '_Z8strncpy0PcPKci': symbol multiply defined!

HelloWorld not run

I put helloworld.html and three js files in a folder and open html file in IE, click talks and nothing happened. I tried tomcat and chrome, also can't work. p.s. I use windows. Is there other files I need to config?

Demo doesn't work (V.Important !!!!)

Hello.

After downloading all the files, I tried running it on Safari as well as on Google chrome but it just doesn't work. I kept refreshing the page but still no sound.
Can you please tell me what's the cause of this?

Hermie.

Processing A Lot Of Text Causes JS to Restart Speech Multiple Times

Hi - I'd be happy to provide a private url of the app I have written for this.

Scenario:

Large text var sent to speak ( or speak.play using the other branch ) .... takes time to process...

speak.js: worker processing took 11686.00 ms speakClient.js:128
speak.js: wav processing took 1793.00 ms speakClient.js:115
speak.js: worker processing took 20646.00 ms speakClient.js:128
speak.js: wav processing took 1814.00 ms speakClient.js:115
speak.js: worker processing took 28872.00 ms speakClient.js:128
speak.js: wav processing took 1787.00 ms

Each time the above console error was logged the speech was restarted from the start again. Ideally it needs to be fully loading the speech var and then only process once - even better if some of the processing can go on in the background while speaking to save delays. ( How ever i'm guessing thats what the worker is for ? ).

Terran

What wrong place

./emscripten.sh

make
rm -f .o *.a *~
rm -f speak
rm -f espeak
rm -f libespeak.so

rm -f .o *.a *~
rm: libespeak.
: No such file or directory
rm: speak: No such file or directory
rm: speak.bc: No such file or directory
rm: speak.o: No such file or directory
env: python2: No such file or directory
mv: rename speak to speak.bc: No such file or directory
emscripten
env: python2: No such file or directory
cat: speak.raw.js: No such file or directory

phoneme input/output

Now that I have been playing with it for a bit it would be fun to get the phonemes with -x to see how the input is getting parsed.

[[D,Is Iz sVm f@n'EtIk t'Ekst 'InpUt]] as input already works, and it is fun to hack with the phonemes.

Improve speech quality

Perhaps by tweaking eSpeak's parameters, or use a different voice file or dictionary file, we can improve the speech quality. We should investigate this. Perhaps we can interest the eSpeak devs in this?

Czech characters like č

The script for some reason skips czech special characters like ě, č and reads only the rest. Though e-speak on windows work properly with the same dictionaries.

Use BlobBuilder

You should use BlobBuilder instead of data: URIs when available (Chrome 11+, FF 6+), and just append your array buffers right into the BlobBuilder instead of strings.

speak.js compile error

1 emscripten-1.37.5
2 emscripten-fastcomp-1.37.5
3 emscripten-fastcomp-clang-1.37.5 already move it into emscripten-fastcomp-1.37.5/tools/clang

then
cd spreak.js/src
./emscripten.sh
.....

1 warning generated.
/home/git/emscripten-1.37.5/em++ -L/usr/local/lib -L/usr/local/BerkeleyDB.4.8/lib/ -o speak speak.o compiledict.o dictionary.o intonation.o readclause.o setlengths.o numbers.o synth_mbrola.o synthdata.o synthesize.o translate.o mbrowrap.o tr_languages.o voices.o wavegen.o phonemelist.o klatt.o sonic.o -lstdc++ -lpthread
emscripten
error: Linking globals named 'wcschr': symbol multiply defined!
Traceback (most recent call last):
File "/home/git/emscripten-1.37.5/emcc", line 13, in
emcc.run()
File "/home/git/emscripten-1.37.5/emcc.py", line 1637, in run
final = shared.Building.llvm_opt(final, link_opts, DEFAULT_FINAL)
File "/home/git/emscripten-1.37.5/tools/shared.py", line 1838, in llvm_opt
assert os.path.exists(target), 'Failed to run llvm optimizations: ' + output
AssertionError: Failed to run llvm optimizations:

anybody help me!!!

How can I use it?

Hello,
That's the first time i use HTMLx (HTML5 in this case) and I don't know how can I use the speak() function. Must I include a library?
Thanks!!!

Is there a minified version of speak.js which speaks English (US) only?

Hi! I am a developer of an online lexicon dictionary. It's for a minority language in Nepal. Impressed by this project, I would like to add the impressive speak.js into the website for the english explanation, but my concern is that a 7MB package with over 2MB main .js file could be a big drawback to loading speed. Anyway, I will only need the English(US) version of it and there won't be a need to adjust speed and pitch. Dear krispken, would mind introduce me a way to minify the source code according to this need? Thanks a lot!

'semaphore.h' file not found

So uh, I ran into this error when I tried to build speak.js (i.e. using emscripten.sh)

/home/icid/Downloads/emscripten/system/include/libc/stdlib.h:193:10: warning: 'long long' is an
      extension when C99 mode is not enabled [-pedantic,-Wlong-long]
unsigned long long _EXFUN(_strtoull_r,(struct _reent *, const char *__n, char ...
         ^
event.cpp:32:10: fatal error: 'semaphore.h' file not found
#include <semaphore.h>
         ^
16 warnings and 1 error generated.
make: *** [x_event.o] Error 1
dis
emscripten
Traceback (most recent call last):
  File "/home/icid/Downloads/emscripten/emscripten.py", line 289, in <module>
    main(keywords)
  File "/home/icid/Downloads/emscripten/emscripten.py", line 164, in main
    if args.optimize: args.infile = optimize(args.infile)
  File "/home/icid/Downloads/emscripten/emscripten.py", line 92, in optimize
    command = [shared.LLVM_OPT, '-o=-', filepath] + shared.pick_llvm_opts(3, True)
AttributeError: 'module' object has no attribute 'pick_llvm_opts'
bundling

Yes, I am aware that I normally shouldn't place everything in my Download folder.
It's just because it's a temporary Ubuntu (v11.10) setup..

Could this be because I'm using llvm and clang version 3.1 (svn)?

PS. Also installed SpiderMonkey and V8 from trunk

Not able to make it work in rails web app

I was trying to implement the speak functionality in the Rails webapp. But I was stuck with no response form my app. Then I opened my console and found an error `speakWorker.self-33f6e6e150af2ba6ed025be7af717e8798de3e72da62eb409de0f0155a6159d8.js:1

Uncaught ReferenceError: importScripts is not defined(anonymous function) @ speakWorker.self-33f6e6e150af2ba6ed025be7af717e8798de3e72da62eb409de0f0155a6159d8.js:1
annyang.min.self-f30b0a5….js?body=1:6 Commands successfully loaded: 1`

Can someone please tell me how can I get out of this issue.

Firefox javascript console filled with warnings

When using mespeak with firefox the console is filled with warnings.

The below is an example using the mespeak.full.js library so that I could see where these are

...
SyntaxError: unreachable code after return statement mespeak.full.js:4167:4
SyntaxError: unreachable code after return statement mespeak.full.js:4376:4
SyntaxError: unreachable code after return statement mespeak.full.js:4386:4
SyntaxError: unreachable code after return statement mespeak.full.js:4413:4
SyntaxError: unreachable code after return statement mespeak.full.js:5232:4
SyntaxError: unreachable code after return statement mespeak.full.js:5301:4
SyntaxError: unreachable code after return statement mespeak.full.js:5375:4
SyntaxError: unreachable code after return statement mespeak.full.js:5448:4
SyntaxError: unreachable code after return statement mespeak.full.js:5558:4
SyntaxError: unreachable code after return statement mespeak.full.js:5606:4
SyntaxError: unreachable code after return statement mespeak.full.js:5640:4
...

An example of code from mespeak.full.js showing why this happens follows
;
return; //@line 846 "wavegen.cpp"
return;

There are lots of these double return statements throughout the file and it is very annoying when using the library with FireFox. Chrome has no problem.

The problem occurs with both the full.js and minified version

Regards

L before F goes wrong

I notice that if you have any word with an L before an F, the sound doesn't come out correctly.

Example:
loaf
leaf
life
loofer

From the sound of it, it's as if it ignores L and any vowels following it up to, but not including, an F.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.