speak.js

Text-to-Speech in JavaScript using eSpeak

Github星跟踪图

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

主要指标

概览
名称与所有者kripken/speak.js
主编程语言C++
编程语言JavaScript (语言数: 9)
平台
许可证GNU General Public License v3.0
所有者活动
创建于2011-08-02 18:36:26
推送于2020-01-30 04:30:13
最后一次提交2017-12-04 11:56:06
发布数0
用户参与
星数1.3k
关注者数54
派生数295
提交数39
已启用问题?
问题数63
打开的问题数51
拉请求数2
打开的拉请求数5
关闭的拉请求数4
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?