<! DOCTYPE Html> http://code.google.com/p/jqtts/source/checkout
/*! JQuery Text-to-Speech plugin--------------------------------------------http://code.google.com/p/jqtts/Copyright (c), Kevin Hoang Le. All rights reserved. Code provided under the MIT license:http://www.opensource.org/licenses/mit-license.html v0.1*/(function ($) {$.fn. Extend {jtts:function (options) {var defaults = {lang: ' en ', Msperword: 900}; var options = $.extend (defaults, options); passed-in var sentences = []; var Lang; var Msperword; var Elem; internal Var plugin; var ttsurl = ' Http://translate.google.com/translate_tts '; var inProgress = false; var currentplaying = 0; var total = 0; var Isie; var jplayer = null; var Talknonie = function () { var url = ttsurl + '? tl= ' + lang + ' &q= ' + sentences[currentplaying++]; Jplayer.jplayer (' setfile ', url). Jplayer (' play '). Jplayer (' Onsoundcomplete ', onsoundcomplete); }; var talkie = function () {if (Currentplaying < total) {var re =/\w+/g; var words = Sentences[currentplaying].match (re); var url = ttsurl + '? tl= ' + lang + ' &q= ' + sentences[currentplaying++]; SetTimeout (Talkie, words.length * Msperword); if (Jplayer! = null) {jplayer.remove (); } Jplayer = $ (' <embed> ', {src:url, hidden:true}). AppendTo ($ (elem)); } else {inProgress = false; Plugin.trigger (' OnComplete ', []); } }; var OnsoundcoMplete = function () {if (Currentplaying < total) {Talknonie (); } else {inProgress = false; Plugin.trigger (' OnComplete ', []); } }; Return This.each (function () {plugin = $ (this); Elem = $ (Options.elem); if ($.browser.msie) {Isie = true; } else {Isie = false; Jplayer = $ (elem); Jplayer.jplayer (Options.jplayer); } lang = Options.lang; Msperword = Options.msperword; }). bind (' playing ', function (e, lines) {currentplaying = 0; sentences = lines; Total = Sentences.length; if (Isie) { Talkie (); } else {Talknonie (); }}). bind (' Pause ', function () {}). bind (' Stop ', function () { }). bind (' Resume ', function () {}); }, play:function (sentences) {return This.trigger (' playing ', [sentences]); }, Pause:function () {return This.trigger (' pause '); }, Abort:function () {return This.trigger (' abort '); }, Resume:function () {return This.trigger (' Resume '); } });}) (JQuery);
JQuery Text-to-Speech Google online voice