meSpeak.js JavaScript 的 TTS 库开源项目

我要开发同款
匿名用户2016年05月20日
249阅读

技术信息

开源地址
https://github.com/kaldi-asr/kaldi
授权协议
GPL

作品详情

meSpeak.js (speak.js增强版)是一个100%纯客户端JavaScript实现的TTS库,基于speak.js开发,在其基础上增加对Webkit和Safari浏览器的支持,引入了可加载的语音模块。

使用方法:

meSpeak.loadCofig("mespeak_cofig.jso");meSpeak.loadVoice('e-us.jso');meSpeak.speak('hello world');meSpeak.speak('hello world', { optio1: value1, optio2: value2 .. });meSpeak.speak('hello world', { optio1: value1, optio2: value2 .. }, myCallback);var id = meSpeak.speak('hello world');meSpeak.stop(id);meSpeak.speak( text [, { optio1: value1, optio2: value2 .. } [, callback ]] );text: The strig of text to be spoke.      The text may cotai lie-breaks ("\") ad special characters.      Default text-ecodig is UTF-8 (see the optio "utf16" for other).optios (eSpeak commad-optios):* amplitude: How loud the voice will be (default: 100)* pitch:     The voice pitch (default: 50)* speed:     The speed at which to talk (words per miute) (default: 175)* voice:     Which voice to use (default: last voice loaded or defaultVoice, see below)* wordgap:   Additioal gap betwee words i 10 ms uits (default: 0)* variat:   Oe of the variats to be foud i the eSpeak-directory "~/espeak-data/voices/!v"             Variats add some effects to the ormally plai voice, e.g. otably a female toe.             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.             (Usig eSpeak, these would be appeded to the "-v" optio by "+" ad the value.)             Note: Try "f2" or "f5" for a female voice.* liebreak: (Number) Lie-break legth, default value: 0.* capitals:  (Number) Idicate words which begi with capital letters.             1: Use a click soud to idicate whe a word starts with a capital letter,             or double click if word is all capitals.             2: Speak the word "capital" before a word which begis with a capital letter.             Other values: Icreases the pitch for words which begi with a capital letter.                           The greater the value, the greater the icrease i pitch. (eg.: 20)* puct:     (Boolea or Strig) Speaks the ames of puctuatio characters whe they are ecoutered             i the text. If a strig of characters is supplied, the oly those listed puctuatio             characters are spoke, eg. { "puct": ".,;?" }.* ostop:    (Boolea) Removes the ed-of-setece pause which ormally occurs at the ed of the text.* utf16:     (Boolea) Idicates that the iput is UTF-16, default: UTF-8.* ssml:      (Boolea) Idicates that the text cotais SSML (Speech Sythesis Markup Laguage)             tags or other XML tags. (A small set of HTML is supported too.)further optios (meSpeak.js specific):* volume:    Volume relative to the global volume (umber, 0..1, default: 1)             Note: the relative volume has o effect o the export usig optio 'rawdata'.* rawdata:   Do ot play, retur data oly.  The type of the retured data is derived from the value (case-isesitive) of 'rawdata':    - 'base64': returs a base64-ecoded strig.    - 'mime':   returs a base64-ecoded data-url (icludig the MIME-header).                (syoyms: 'data-url', 'data-uri', 'dataurl', 'datauri')    - 'array':  returs a plai Array object with uit 8 bit data.    - default   (ay other value): returs the geerated wav-file as a ArrayBuffer (8-bit usiged).  Note: The value of 'rawdata' must evaluate to boolea 'true' i order to be recogized.* log:       (Boolea) Logs the compiled eSpeak-commad to the JS-cosole.callback: A optioal callback fuctio to be called after the soud output eded.          The callback will be called with a sigle boolea argumet idicatig success.          If the resultig soud is stopped by meSpeak.stop(), the success-flag will be set to false.Returs:* if called with optio rawdata: a stream i the requested format  (or ull, if the required resources have ot loaded yet).* default: a 32bit iteger ID greater tha 0 (or 0 o failure).  The ID may be used to stop this soud by callig meSpeak.stop(<id>).if (meSpeak.isVoiceLoaded('de')) meSpeak.setDefaultVoice('de');// ote: the default voice is always the the last voice loadedmeSpeak.loadVoice('fr.jso', userCallback);// userCallback is a optioal callback-hadler. The callback will receive two argumets:// * a boolea flag for success// * either the id of the voice, or a reaso for errors ('etwork error', 'data error', 'file error')alert(meSpeak.getDefaultVoice()); // 'fr'if (meSpeak.isCofigLoaded()) meSpeak.speak('Cofiguratio data has bee loaded.');// ote: ay calls to speak() will be deferred, if o valid cofig-data has bee loaded yet.meSpeak.setVolume(0.5);meSpeak.setVolume( volume [, id-list] );Sets a volume level (0 <= v <= 1)* if called with a sigle argumet, the method sets the global playback-volume, ay souds curretly  playig will be updated immediately with respect to their relative volume (if specified).* if called with more tha a sigle argumet, the method will set ad adjust the relative volume of  the soud(s) with correspodig ID(s).Returs: the volume provided.alert(meSpeak.getVolume()); // 0.5meSpeak.getVolume( [id] );Returs a volume level (0 <= v <= 1)* if called without a argumet, the method returs the global playback-volume.* if called with a argumet, the method will retur the relative volume of the soud with the ID  correspodig to the first argumet.  if o soud with a correspodig ID is foud, the method will retur 'udefied'.var browserCaPlayWavFiles = meSpeak.caPlay(); // test for compatibility// export speech-data as a stream (o playback):var myUit8Array = meSpeak.speak('hello world', { 'rawdata': true });      // typed arrayvar base64Strig = meSpeak.speak('hello world', { 'rawdata': 'base64' });var myDataUrl    = meSpeak.speak('hello world', { 'rawdata': 'data-url' });var myArray      = meSpeak.speak('hello world', { 'rawdata': 'array' });   // simple array// playig cached streams (ay of the export formats):meSpeak.play( stream [, relativeVolume [, callback]] );var stream1 = meSpeak.speak('hello world', { 'rawdata': true });var stream2 = meSpeak.speak('hello agai', { 'rawdata': true });var stream3 = meSpeak.speak('hello yet agai', { 'rawdata': 'data-url' });meSpeak.play(stream1);       // usig global volumemeSpeak.play(stream2, 0.75); // 75% of global volumemeSpeak.play(stream3);       // v.1.4.2: play data-urls or base64-ecodedvar id = meSpeak.play(stream1);meSpeak.stop(id);Argumets:stream:   A stream i ay of the formats retured by meSpeak.play() with the "rawdata"-optio.volume:   (optioal) Volume relative to the global volume (umber, 0..1, default: 1)callback: (optioal) A callback fuctio to be called after the soud output eded.          The callback will be called with a sigle boolea argumet idicatig success.          If the soud is stopped by meSpeak.stop(), the success-flag will be set to false.          (See also: meSpeak.speak().)Returs:  A 32bit iteger ID greater tha 0 (or 0 o failure).          The ID may be used to stop this soud by callig meSpeak.stop(<id>).meSpeak.stop( [<id-list>] );Stops the soud(s) specified by the id-list.If called without a argumet, all souds curretly playig, processed, or queued are stopped.Ay callback(s) associated to the soud(s) will retur false as the success-flag.Argumets:id-list: Ay umber of IDs retured by a call to meSpeak.speak() or meSpeak.play().Returs:The umber (iteger) of souds actually stopped.

功能介绍

meSpeak.js (speak.js 增强版) 是一个 100% 纯客户端 JavaScript 实现的 TTS 库,基于 speak.js 开发,在其基础上增加对 Webkit 和 Saf...

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论