forked from hiddentao/google-tts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
google-tts.min.js
1 lines (1 loc) · 3.83 KB
/
google-tts.min.js
1
!function(a,b){"use strict";if("function"==typeof define)define(b);else if("undefined"!=typeof module&&module.exports)module.exports=b();else{var c=window||this,d=c[a],e=b();e.noConflict=function(){return c[a]=d,e},c[a]=e}}("GoogleTTS",function(){"use strict";var a=function(b){var c=this,d=100;c.defaultLanguage=b||"en";var e={af:"Afrikaans",sq:"Albanian",ar:"Arabic",hy:"Armenian",ca:"Catalan","zh-CN":"Mandarin (simplified)","zh-TW":"Mandarin (traditional)",hr:"Croatian",cs:"Czech",da:"Danish",nl:"Dutch",en:"English",eo:"Esperanto",fi:"Finnish",fr:"French",de:"German",el:"Greek",ht:"Haitian Creole",hi:"Hindi",hu:"Hungarian",is:"Icelandic",id:"Indonesian",it:"Italian",ja:"Japanese",ko:"Korean",la:"Latin",lv:"Latvian",mk:"Macedonian",no:"Norwegian",pl:"Polish",pt:"Portuguese",ro:"Romanian",ru:"Russian",sr:"Serbian",sk:"Slovak",es:"Spanish",sw:"Swahili",sv:"Swedish",ta:"Tamil",th:"Thai",tr:"Turkish",vi:"Vietnamese",cy:"Welsh"};c._players=[new a.HTML5Player,new a.SM2Player],c.addPlayer=function(b){if(!(b instanceof a.Player))throw new Error("Must be a instance of base Player class");c._players.push(b)},c.languages=function(){return e},c.getPlayer=function(a){if(c.availablePlayer)return a(null,c.availablePlayer);var b,d=-1;(b=function(){return c._players.length<=++d?a():(c._players[d].available(function(e){return e?(c.availablePlayer=c._players[d],a(null,c.availablePlayer)):(b(),void 0)}),void 0)}).call()},c.urls=function(a,b){if(b=b||c.defaultLanguage,!a||0>=a.length)throw new Error("Need some text");for(var e=c._sliceInput(a,d),f=[],g=0;g<e.length;++g){var h=e[g];f.push("http://translate.google.com/translate_tts?ie=UTF-8&tl="+b+"&q="+h+"&textlen="+h.length+"&idx="+g+"&total="+e.length)}return f},c._sliceInput=function(a,b){var c=[],d=0;do c.push(a.slice(d,d+b)),d+=b;while(a.length>d);return c},c.play=function(a,b,d){c.getPlayer(function(e,f){if(e)return d(e);if(!f)return d(new Error("No playback mechanism is available"));var g=c.urls(a,b),h=null;(h=function(a){return a?d(a):0>=g.length?d():(f.play(g.shift(),h),void 0)}).call()})}},b=function(a,b){a.prototype=new b,a.prototype.constructor=a,a.prototype.parent=b.prototype};return a.Player=function(){var a=this;a.available=function(){throw new Error("Not yet implemented")},a.play=function(){throw new Error("Not yet implemented")},a.toString=function(){throw new Error("Not yet implemented")}},a.HTML5Player=function(){var a=this;a._available=null,a.available=function(b){return null===a._available?(function(a){try{if("undefined"==typeof window.Audio)return a(null,!1);var b=new Audio;if("probably"===b.canPlayType("audio/mpeg"))return a(null,!0);b.addEventListener("canplaythrough",function(){a(null,!0)},!1),b.addEventListener("error",function(){a(null,!1)},!1),b.src="data:audio/mpeg;base64,/+MYxAAAAANIAUAAAASEEB/jwOFM/0MM/90b/+RhST//w4NFwOjf///PZu////9lns5GFDv//l9GlUIEEIAAAgIg8Ir/JGq3/+MYxDsLIj5QMYcoAP0dv9HIjUcH//yYSg+CIbkGP//8w0bLVjUP///3Z0x5QCAv/yLjwtGKTEFNRTMuOTeqqqqqqqqqqqqq/+MYxEkNmdJkUYc4AKqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq",b.load()}catch(c){a(c)}}(function(c,d){c&&console.log(c),a._available=d,b(a._available)}),void 0):(b(a._available),void 0)},a.play=function(a,b){try{var c=new Audio;c.src=a,c.addEventListener("ended",function(){b()}),c.play()}catch(d){return b(d)}},a.toString=function(){return"HTML5 Audio"}},b(a.HTML5Player,a.Player),a.SM2Player=function(){var a=this;a._available=null,a._soundId=0,a._unique_instance_id=parseInt(1e3*Math.random(),10),a.available=function(b){null===a._available&&"undefined"!=typeof window.soundManager&&"function"==typeof window.soundManager.ok&&(a._available=window.soundManager.ok()),b(a._available)},a.play=function(b,c){try{window.soundManager.createSound({id:"googletts-"+a._unique_instance_id+"-"+ ++a._soundId,url:b,onfinish:c}).play()}catch(d){c(d)}},a.toString=function(){return"SoundManager2"}},b(a.SM2Player,a.Player),a});