UNPKG

talkr-tts

Version:

Wraps speechSynthesis calls for applications that want to animate to the voice

1 lines 23.4 kB
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("talkr-tts",[],t):"object"==typeof exports?exports["talkr-tts"]=t():e["talkr-tts"]=t()}("undefined"!=typeof self?self:this,function(){return function(e){function t(i){if(n[i])return n[i].exports;var r=n[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,t),r.l=!0,r.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,i){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:i})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=6)}([function(e,t,n){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function o(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0});var s=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),a=n(3),u=function(e){return e&&e.__esModule?e:{default:e}}(a),l=function(e){function t(e,n){if(i(this,t),void 0===n)n=Math.random().toString(36).substr(2,9);else if("string"!=typeof n)throw new Error("Invalid id");var o=r(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return o._id=n,o._type=e,o._type in t.objects||(t.objects[o._type]={}),t.lastID[o._type]=o._id,t.objects[o._type][o._id]=o,o}return o(t,e),s(t,[{key:"delete",value:function(){delete t.objects[this._type][this._id]}},{key:"id",get:function(){return this._id},set:function(e){this._id in t.objects[this._type]&&delete t.objects[this._type][this._id],this._id=e,t.objects[this._type][this._id]=this,t.lastID[this._type]=this._id}}],[{key:"getlastID",value:function(e){return t.lastID[e]}},{key:"getByTypeAndID",value:function(e,n){return e in t.objects&&n in t.objects[e]?(t.lastID[e]=n,t.objects[e][n]):null}},{key:"store",get:function(){return t.objects},set:function(e){t.objects=e}}]),t}(u.default);t.default=l,l.lastID={},l.objects={},e.exports=t.default},function(e,t,n){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},s="object"===("undefined"==typeof window?"undefined":o(window))&&null!==window&&window.self===window&&null!==window.navigator,a=s&&/iPad|iPhone|iPod/.test(window.navigator.userAgent)&&!window.MSStream,u=s&&null!==window.speechSynthesis,l=["Maged","Zuzana","Sara","Anna","Melina","Karen","Daniel","Moira","Tessa","Alex","Monica","Paulina","Satu","Amelie","Thomas","Carmit","Lekha","Mariska","Damayanti","Alice","Kyoko","Yuna","Ellen","Xander","Nora","Zosia","Luciana","Joana","Ioana","Milena","Laura","Alva","Kanya","Yelda","Ting-Ting","Sin-Ji","Mei-Jia"],c={"Microsoft David Desktop - English (United States)":{male:!0,priority:13},"Microsoft Hazel Desktop - English (Great Britain)":{male:!1,priority:14},"Microsoft Zira Desktop - English (United States)":{male:!1,priority:14},"Google US English":{male:!1,priority:24},"Google UK English Female":{male:!1,priority:24},"Google UK English Male":{male:!0,priority:23},Lee:{male:!0,priority:33},Fred:{male:!0,priority:8},Alex:{male:!0,priority:34},Daniel:{male:!0,priority:33},"Daniel (Enhanced)":{male:!0,priority:43},Oliver:{male:!0,priority:33},"Oliver (Enhanced)":{male:!0,priority:43},Samantha:{male:!1,priority:38},Victoria:{male:!1,priority:9},Veena:{male:!1,priority:32},Tessa:{male:!1,priority:37},Fiona:{male:!1,priority:37},Moira:{male:!1,priority:37},Karen:{male:!1,priority:37}},f={en:"English",zh:"Chinese",ru:"Russian",de:"German",it:"Italian",pt:"Portuguese",vi:"Vietnamese",tr:"Turkish",th:"Thai",es:"Spanish",fr:"French",sk:"Slovak",ro:"Romanian",pl:"Polish",nl:"Dutch",ko:"Korean",ja:"Japanese",he:"Hebrew",el:"Greek",fi:"Finish",no:"Norwegian",da:"Danish",cs:"Czech",ar:"Arabic"},h={English:"en",Chinese:"zh",Russian:"ru",German:"de",Italian:"it",Portuguese:"pt",Vietnamese:"vi",Turkish:"tr",Thai:"th",Spanish:"es",French:"fr",Slovak:"sk",Romanian:"ro",Polish:"pl",Dutch:"nl",Korean:"ko",Japanese:"ja",Hebrew:"he",Greek:"el",Finish:"fi",Norwegian:"no",Danish:"da",Czech:"cs",Arabic:"ar"},p=function(){function e(t,n,r){i(this,e),this._locale=t,this._bIsMale=n,this._name=r,this._index=null,void 0===this._locale&&(this._locale=e.defaultlocale),void 0===this._bIsMale&&(this._bIsMale=e.defaultbIsMale),void 0!==this._name&&this._name in c&&(this._bIsMale=c[this._name].male),this._name&&!isNaN(this._name)&&(this._index=this._name,this._name=null),e.defaultlocale=this._locale,e.defaulbIsMale=this._bIsMale}return r(e,null,[{key:"getLangauges",value:function(){function e(e,t,n){return n.indexOf(e)===t}var t=[],n=[];return u&&speechSynthesis.getVoices().forEach(function(e){t.push(e.lang.substring(0,2))}),t.filter(e).forEach(function(e){e in f?n.push(f[e]):n.push(e)}),n}},{key:"getVoicesForLangauge",value:function(t){var n=h[t],i=[],r=[];return n?(r=e.getVoicesWithLangSubstring(n),r.forEach(function(e){i.push(e.name)}),i):[]}},{key:"getVoicesWithLangSubstring",value:function(e){function t(e,t){var n=0,i=0;return c[e.name]&&(n=c[e.name].priority),c[t.name]&&(i=c[t.name].priority),e.name.includes("Enhanced")&&n++,t.name.includes("Enhanced")&&i++,i-n}var n=[];if(u&&(n=speechSynthesis.getVoices().filter(function(t){return!(c[t.name]&&c[t.name].priority<10)&&t.lang.substring(0,e.length)===e})),a){for(var i=[],r=n.length-1,o=r;o>=0;--o)for(var s=0;s<l.length;++s)n[o].name===l[s]&&i.push(n[o]);n=i}return n.sort(t)}},{key:"getTTSVoice",value:function(t){return e._getBestVoice(t.name,t.locale,t.isMale,t.index)}},{key:"_getBestVoice",value:function(t,n,i,r){if(t){var o=e._getVoiceWithName(t);if(o)return o}var s=e._getBestVoices(n,i);if(s.length>0)return null!=r?(r=Math.abs(parseInt(r,10)),r%=s.length):r=0,s[r];if("en"!==n)return console.warn("No voices for locale: "+n),e._getBestVoice(null,"en",i,r);var a=[];return u&&(a=speechSynthesis.getVoices()),a[0]?a[0]:null}},{key:"_getBestVoices",value:function(t,n){var i=[],r=[];return t&&t.length>1&&(i=e.getVoicesWithLangSubstring(t)),i.forEach(function(e){e.name in c?n===c[e.name].male&&r.push(e):r.push(e)}),0===r.length&&t.length>2?this._getBestVoices(t.substring(0,2),n):(0===r.length&&i.forEach(function(e){r.push(e)}),r)}},{key:"_getVoicesWithName",value:function(e){return u?speechSynthesis.getVoices().filter(function(t){return t.name===e}):[]}},{key:"_getVoiceWithName",value:function(e){if(u){var t=speechSynthesis.getVoices().filter(function(t){return t.name===e});if(t.length>0)return t[0]}return null}},{key:"doesSupportPitchAndRate",value:function(t){var n=e._getVoiceWithName(t);return!!n&&!0===n.localService}}]),r(e,[{key:"index",get:function(){return this._index}},{key:"name",get:function(){return this._name}},{key:"locale",get:function(){return this._locale}},{key:"isMale",get:function(){return this._bIsMale}},{key:"language",get:function(){return f[this._locale.substring(0,2)]}}]),e}();t.default=p,p.defaultlocale="en-US",p.defaultbIsMale=!1,e.exports=t.default},function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{default:e}}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0});var a=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),u=n(0),l=i(u),c=n(1),f=i(c),h=function(e){function t(e,n){r(this,t);var i=o(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,"face",e));return void 0===n&&(n=new f.default),i._voice=n,i}return s(t,e),a(t,[{key:"url",get:function(){return this._id},set:function(e){this._id=e}},{key:"voice",get:function(){return this._voice},set:function(e){this._voice=e}}],[{key:"getByID",value:function(e){return l.default.getByTypeAndID("face",e)}},{key:"getlastID",value:function(){return l.default.getlastID("face")}},{key:"fromJSON",value:function(e){if(e._id){var n=e._voice,i=null;return n&&(i=new f.default(n._locale,n._bIsMale,n._name)),new t(e._id,i)}return null}}]),t}(l.default);t.default=h,e.exports=t.default},function(e,t){function n(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function i(e){return"function"==typeof e}function r(e){return"number"==typeof e}function o(e){return"object"==typeof e&&null!==e}function s(e){return void 0===e}e.exports=n,n.EventEmitter=n,n.prototype._events=void 0,n.prototype._maxListeners=void 0,n.defaultMaxListeners=10,n.prototype.setMaxListeners=function(e){if(!r(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},n.prototype.emit=function(e){var t,n,r,a,u,l;if(this._events||(this._events={}),"error"===e&&(!this._events.error||o(this._events.error)&&!this._events.error.length)){if((t=arguments[1])instanceof Error)throw t;var c=new Error('Uncaught, unspecified "error" event. ('+t+")");throw c.context=t,c}if(n=this._events[e],s(n))return!1;if(i(n))switch(arguments.length){case 1:n.call(this);break;case 2:n.call(this,arguments[1]);break;case 3:n.call(this,arguments[1],arguments[2]);break;default:a=Array.prototype.slice.call(arguments,1),n.apply(this,a)}else if(o(n))for(a=Array.prototype.slice.call(arguments,1),l=n.slice(),r=l.length,u=0;u<r;u++)l[u].apply(this,a);return!0},n.prototype.addListener=function(e,t){var r;if(!i(t))throw TypeError("listener must be a function");return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,i(t.listener)?t.listener:t),this._events[e]?o(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,o(this._events[e])&&!this._events[e].warned&&(r=s(this._maxListeners)?n.defaultMaxListeners:this._maxListeners)&&r>0&&this._events[e].length>r&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace()),this},n.prototype.on=n.prototype.addListener,n.prototype.once=function(e,t){function n(){this.removeListener(e,n),r||(r=!0,t.apply(this,arguments))}if(!i(t))throw TypeError("listener must be a function");var r=!1;return n.listener=t,this.on(e,n),this},n.prototype.removeListener=function(e,t){var n,r,s,a;if(!i(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(n=this._events[e],s=n.length,r=-1,n===t||i(n.listener)&&n.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(o(n)){for(a=s;a-- >0;)if(n[a]===t||n[a].listener&&n[a].listener===t){r=a;break}if(r<0)return this;1===n.length?(n.length=0,delete this._events[e]):n.splice(r,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},n.prototype.removeAllListeners=function(e){var t,n;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(n=this._events[e],i(n))this.removeListener(e,n);else if(n)for(;n.length;)this.removeListener(e,n[n.length-1]);return delete this._events[e],this},n.prototype.listeners=function(e){return this._events&&this._events[e]?i(this._events[e])?[this._events[e]]:this._events[e].slice():[]},n.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(i(t))return 1;if(t)return t.length}return 0},n.listenerCount=function(e,t){return e.listenerCount(t)}},function(e,t,n){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),o=function(){function e(t,n,r,o){i(this,e),this._text=t,this._pitch=n,this._rate=r,this._delay=o,void 0===this._pitch&&(this._pitch=1),void 0===this._rate&&(this._rate=1),void 0===this._delay&&(this._delay=0)}return r(e,[{key:"text",get:function(){return this._text},set:function(e){this._text=e}},{key:"pitch",get:function(){return this._pitch},set:function(e){this._pitch=e}},{key:"rate",get:function(){return this._rate},set:function(e){this._rate=e}},{key:"delay",get:function(){return this._delay},set:function(e){this._delay=e}}]),e}();t.default=o,e.exports=t.default},function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{default:e}}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0});var a=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},l=n(4),c=i(l),f=n(1),h=i(f),p=n(2),y=i(p),d=n(0),_=i(d),v="object"===("undefined"==typeof window?"undefined":u(window))&&null!==window&&window.self===window,g=v&&"speechSynthesis"in window?window.speechSynthesis:null,m=function(e){function t(e,n,i){r(this,t);var s=o(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,"clip",i));if(void 0===e&&(e=[]),"string"==typeof e)s._utterances=s._splitUtterances(e);else{if(!Array.isArray(e))throw Error("Unknown type for utterances.");e.forEach(function(e){if(!(e instanceof c.default))throw Error("Invalid utterance array.")}),s._utterances=e}if("string"==typeof n)s._faceid=n;else if(n instanceof y.default)s._faceid=n.id;else{var a=y.default.getlastID();a||(a=(new y.default).id),s._faceid=a}return s._stopped=!0,s}return s(t,e),a(t,[{key:"playAfterDelay",value:function(e){this._stopped||(g.speak(e),e.delay>0&&(g.pause(),setTimeout(function(){var t=new Event("start");e.delay=0,e.dispatchEvent(t),g.resume()},1e3*e.delay)))}},{key:"playUtterances",value:function(e,n,i){var r=this;if(this._stopped=!1,t.playing=this,g){g.speaking&&g.cancel(),this._ssUtterances=[];for(var o=0,s=this._utterances.length;o<s;++o){var a=this._utterances[o],u=a.text;if(u&&0!==u.length){var l=new SpeechSynthesisUtterance,c=50*u.length;u.match(/[\u3400-\u9FBF]/)&&(c=200*u.length),l.rate=a.rate,l.pitch=a.pitch,l.text=u,l.delay=a.delay,this.voice&&(l.voice=h.default.getTTSVoice(this.voice),l.voice&&(l.voiceURI=l.voice.voiceURI)),this._ssUtterances.push([l,c])}}if(this._ssUtterances.length>0){this._ssUtterances[0][0].addEventListener("start",function(){i&&0===r._ssUtterances[0][0].delay&&i()}),this._ssUtterances[this._ssUtterances.length-1][0].addEventListener("end",function(){n&&n(),r._stopped=!0,t.playing=null,r._ssUtterances=[]});for(var f=0,p=this._ssUtterances.length;f<p;++f)!function(t,n){t.addEventListener("start",function(){e&&0===t.delay&&e(n,r.face)})}(this._ssUtterances[f][0],this._ssUtterances[f][1]);for(var y=0,d=this._ssUtterances.length-1;y<d;++y)!function(e,t){e.addEventListener("end",function(){r.playAfterDelay(t)})}(this._ssUtterances[y][0],this._ssUtterances[y+1][0]);this.playAfterDelay(this._ssUtterances[0][0])}}}},{key:"updateText",value:function(e){var t=this._splitUtterances(e),n=this._utterances.length,i=t.length;if(n!==i){for(var r={},o=0;o<n;++o)this._utterances[o].text in r?r[this._utterances[o].text].push(this._utterances[o]):r[this._utterances[o].text]=[this._utterances[o]];for(var s=[],a=0;a<i;++a){var u=t[a].text;u in r?(t[a]=r[u].shift(),0===r[u].length&&delete r[u]):s.push(a)}if(s.length>0&&Object.values(r).length>0){var l=t[s[0]].text;t[s[0]]=Object.values(r)[0][0],t[s[0]].text=l}this._utterances=t}else for(var c=0;c<n;++c)this._utterances[c].text=t[c].text}},{key:"_splitUtterances",value:function(e){var t=[],n=e.match(/[^.?,!]+[.?,!]?/g);if(n)for(var i=0,r=n.length;i<r;++i){var o=n[i].trim(),s=(o.match(/[.?,!]/g)||[]).length;o.length-s>0&&t.push(new c.default(o))}return t}},{key:"utterances",get:function(){return this._utterances}},{key:"face",get:function(){return y.default.getByID(this._faceid)},set:function(e){"string"==typeof e&&y.default.getByID(e)&&(this._faceid=e),this._faceid=e.id}},{key:"voice",get:function(){return this.face.voice},set:function(e){this.face.voice=e}},{key:"text",get:function(){for(var e="",t=this._utterances.length,n=0;n<t;++n)e=e+this._utterances[n].text+" ";return e.trim()}},{key:"sceneid",get:function(){return this._sceneid},set:function(e){this._sceneid=e}}],[{key:"stop",value:function(){t.playing&&(t.playing._stopped=!0),t.playing=null,g&&g.cancel()}},{key:"getByID",value:function(e){return _.default.getByTypeAndID("clip",e)}},{key:"fromJSON",value:function(e){if(e._utterances&&e._id){for(var n=[],i=0,r=e._utterances.length;i<r;++i){var o=e._utterances[i];n.push(new c.default(o._text,o._rate,o._pitch,o._delay))}var s=new t(n,e._faceid,e._id);return s._sceneid=e._sceneid,s}return null}}]),t}(_.default);t.default=m,m.playing=null,e.exports=t.default},function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0}),t.Scene=t.Clip=t.Utterance=t.Voice=t.Face=t.Base=void 0;var r=n(2),o=i(r),s=n(1),a=i(s),u=n(4),l=i(u),c=n(5),f=i(c),h=n(7),p=i(h),y=n(0),d=i(y);t.Base=d.default,t.Face=o.default,t.Voice=a.default,t.Utterance=l.default,t.Clip=f.default,t.Scene=p.default},function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{default:e}}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0});var a=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),u=function e(t,n,i){null===t&&(t=Function.prototype);var r=Object.getOwnPropertyDescriptor(t,n);if(void 0===r){var o=Object.getPrototypeOf(t);return null===o?void 0:e(o,n,i)}if("value"in r)return r.value;var s=r.get;if(void 0!==s)return s.call(i)},l=n(5),c=i(l),f=n(0),h=i(f),p=n(3),y=i(p),d=function(e){function t(e,n){r(this,t);var i=o(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,"scene",n));if(void 0===e&&(e=[]),!Array.isArray(e))throw Error("clipIDs were not an array.");return e.forEach(function(e){if("string"!=typeof e)throw Error("Invalid clip id.")}),i._clips=e,i._stopped=!0,i._name=null,i}return s(t,e),a(t,[{key:"deleteClip",value:function(e){var t=this._clips.indexOf(e);if(t>-1){var n=c.default.getByID(e);this._clips.splice(t,1),n&&n.delete()}}},{key:"addClip",value:function(e){var t=c.default.getByID(e);t&&(this._clips.push(e),t.sceneid=this._id)}},{key:"delete",value:function(){this._clips.forEach(function(e){delete h.default.objects.clip[e]}),u(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"delete",this).call(this)}},{key:"playClips",value:function(e){var n=this;t.playing=this,void 0===e&&(e=0);var i=this._clips.length;if(this._stopped=!1,!(i<=e)){var r=function(e,n){t.eventEmitter.emit("utterancestart",{duration:e,face:n})},o=this,s=null,a=function(e){if(!n._stopped){var i=c.default.getByID(o.clipIDs[e]);if(!i)throw new Error("unknown clip ID: "+o.clipIDs[e]);t.eventEmitter.emit("clipstart",i),i.playUtterances(r,s)}},u=e;s=function(){if(u===i-1)return t.eventEmitter.emit("scenefinished"),void(t.playing=null);t.eventEmitter.emit("clipfinished",u),u+=1,a(u)},a(e)}}},{key:"clipIDs",get:function(){return this._clips}},{key:"name",get:function(){return this._name},set:function(e){this._name=e}},{key:"text",get:function(){var e="";return this._clips.forEach(function(t){var n=c.default.getByID(t);if(!n)throw new Error("Invalid clip ID.");e+=n.text+" "}),e.trim()}},{key:"clips",get:function(){var e=[];return this._clips.forEach(function(t){var n=c.default.getByID(t);if(!n)throw new Error("Invalid clip ID.");e.push(n)}),e}}],[{key:"stop",value:function(){t.playing&&(t.playing._stopped=!0),t.playing=null,c.default.stop()}},{key:"fromTextAndFace",value:function(e,n){return new t([new c.default(e,n).id])}},{key:"getByID",value:function(e){return h.default.getByTypeAndID("scene",e)}},{key:"fromJSON",value:function(e){if(e._clips&&e._id){var n=new t(e._clips,e._id),i=e._name;return i&&(n.name=i),n}return null}}]),t}(h.default);t.default=d,d.playing=null,d.eventEmitter=new y.default,h.default.objects.scene={},e.exports=t.default}])});