From fd8408aae59c72797c7974f66a159834e6101bc4 Mon Sep 17 00:00:00 2001 From: Nathan Friedly Date: Wed, 24 Feb 2016 12:54:01 -0500 Subject: [PATCH] adding basic speech support Built in response to https://developer.ibm.com/answers/questions/254586/service-interconnected-speech-to-text-dialog-text.html?utm_campaign=answers&utm_medium=email&utm_source=answers-new-question&utm_content=answers-answer-question --- .cfignore | 3 ++- .gitignore | 1 + README.md | 5 +++-- app.js | 9 ++++++++ manifest.yml | 12 ++++++++-- package.json | 16 ++++++++------ public/css/style.css | 17 ++++++++++++++- public/images/icons/microphone.svg | 14 ++++++++++++ public/index.html | 6 +++-- public/js/demo.js | 35 ++++++++++++++++++++++++++++-- public/js/watson-speech.min.js | 8 +++++++ stt-token.js | 33 ++++++++++++++++++++++++++++ tts-token.js | 31 ++++++++++++++++++++++++++ 13 files changed, 173 insertions(+), 17 deletions(-) create mode 100644 public/images/icons/microphone.svg create mode 100644 public/js/watson-speech.min.js create mode 100644 stt-token.js create mode 100644 tts-token.js diff --git a/.cfignore b/.cfignore index b512c09..37d7e73 100644 --- a/.cfignore +++ b/.cfignore @@ -1 +1,2 @@ -node_modules \ No newline at end of file +node_modules +.env diff --git a/.gitignore b/.gitignore index 1a2903e..52a3740 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules /dialogs/dialog-id.json +.env diff --git a/README.md b/README.md index 96d3282..5e183f2 100755 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ -# Dialog Node.js +# Speech & Dialog Demo App - The Dialog starter application in Node.js is a sample that demonstrates how the IBM Watson [Dialog service][service_url] works in a specific context. + This is an extension of the IBM Watson [Dialog service][service_url] Dialog starter application that also incorporates + the [Speech JS SDK](https://github.com/watson-developer-cloud/speech-javascript-sdk) to allow for voice interactions.

diff --git a/app.js b/app.js index fb724b9..3ce24bc 100755 --- a/app.js +++ b/app.js @@ -16,6 +16,8 @@ 'use strict'; +require('dotenv').config({silent: true}); + var express = require('express'), app = express(), fs = require('fs'), @@ -24,9 +26,16 @@ var express = require('express'), extend = require('util')._extend, watson = require('watson-developer-cloud'); + // Bootstrap application settings require('./config/express')(app); +// token endpoints +// **Warning**: these endpoints should be guarded with additional authentication & authorization for production use +app.use('/api/speech-to-text/', require('./stt-token.js')); +app.use('/api/text-to-speech/', require('./tts-token.js')); + + // if bluemix credentials exists, then override local var credentials = extend({ url: '', diff --git a/manifest.yml b/manifest.yml index 5221ae7..bf46302 100755 --- a/manifest.yml +++ b/manifest.yml @@ -2,11 +2,19 @@ declared-services: dialog-service: label: dialog plan: standard + stt-service: + label: speech_to_text + plan: standard + tts-service: + label: text_to_speech + plan: standard applications: - services: - dialog-service - name: dialog-nodejs - command: node app.js + - stt-service + - tts-service + name: speech-dialog + command: npm start path: . memory: 512M env: diff --git a/package.json b/package.json index 13f5bbd..cb518a2 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,11 @@ { - "name": "DialogNodejsStarterApp", - "version": "0.1.8", - "description": "A sample nodejs app for Bluemix that use the Dialog", - "engines": { - "node": ">=0.10.38" - }, + "name": "speech-dialog", + "version": "1.0.0", + "description": "A simple extension of the Watson Dialog sample app to use the Speech JS SDK", "repository": { "type": "git", "url": "https://github.com/watson-developer-cloud/dialog-nodejs.git" }, - "author": "IBM Corp.", "contributors": [ { "name": "James Zhang", @@ -22,6 +18,10 @@ { "name": "German Attanasio Ruiz", "email": "germanatt@us.ibm.com" + }, + { + "name": "Nathan Friedly", + "url": "http://nfriedly.com/" } ], "license": "Apache-2.0", @@ -35,9 +35,11 @@ "dependencies": { "async": "^1.5.1", "body-parser": "~1.14.1", + "dotenv": "^2.0.0", "errorhandler": "~1.4.1", "express": "~4.13.3", "request": "^2.67.0", + "vcap_services": "^0.1.7", "watson-developer-cloud": "~1.0.6" } } diff --git a/public/css/style.css b/public/css/style.css index f9c1112..2bef654 100755 --- a/public/css/style.css +++ b/public/css/style.css @@ -1066,9 +1066,24 @@ pre[class*=" language-"] { .chat-window { position: relative; } + .chat-window--message-input { padding-top: 1.5rem; - padding-bottom: 1.5rem; } + padding-bottom: 1.5rem; + width: calc(100% - 37px); + } + .chat-window--microphone-button { + width: 32px; + height: 68px; + padding: 19px 2px; + cursor: pointer; + background-color: #00B2EF; + position: absolute; /* this is a hack, but it gets the job done */ + right: 0; + } + .chat-window--microphone-button.active { + background-color: #d74108; + } .chat-box { position: relative; diff --git a/public/images/icons/microphone.svg b/public/images/icons/microphone.svg new file mode 100644 index 0000000..0507dee --- /dev/null +++ b/public/images/icons/microphone.svg @@ -0,0 +1,14 @@ + + + + + + + + + diff --git a/public/index.html b/public/index.html index c6c351e..a116977 100755 --- a/public/index.html +++ b/public/index.html @@ -55,10 +55,10 @@

Documentation @@ -119,6 +119,7 @@

+ Record via Microphone @@ -159,6 +160,7 @@

Profile
+ diff --git a/public/js/demo.js b/public/js/demo.js index 1f8b070..75f2226 100755 --- a/public/js/demo.js +++ b/public/js/demo.js @@ -26,8 +26,32 @@ $(document).ready(function () { $jsonPanel = $('#json-panel .base--textarea'), $information = $('.data--information'), $profile = $('.data--profile'), - $loading = $('.loader'); + $loading = $('.loader'), + $micButton = $('.chat-window--microphone-button'); + + // note: these tokens expire after an hour. + var getSTTToken = $.ajax('/api/speech-to-text/token'); + var getTTSToken = $.ajax('/api/text-to-speech/token'); + + var deactivateMicButton = $micButton.removeClass.bind($micButton, 'active'); + + function record() { + getSTTToken.then(function(token) { + $micButton.addClass('active'); + WatsonSpeech.SpeechToText.recognizeMicrophone({ + token: token, + continuous: false, + outputElement: $chatInput[0], + keepMicrophone: navigator.userAgent.indexOf('Firefox') > 0 + }).promise().then(function() { + converse($chatInput.val()); + }) + .then(deactivateMicButton) + .catch(deactivateMicButton); + }); + } + $micButton.click(record); $chatInput.keyup(function(event){ if(event.keyCode === 13) { @@ -67,6 +91,13 @@ $(document).ready(function () { var texts = dialog.conversation.response; var response = texts.join('<br/>'); // <br/> is
+ getTTSToken.then(function(token) { + WatsonSpeech.TextToSpeech.synthesize({ + text: texts, + token: token + }).addEventListener('ended', record); // trigger the button again once recording stops + }); + $chatInput.show(); $chatInput[0].focus(); @@ -169,4 +200,4 @@ $(document).ready(function () { converse(); scrollToInput(); -}); \ No newline at end of file +}); diff --git a/public/js/watson-speech.min.js b/public/js/watson-speech.min.js new file mode 100644 index 0000000..828ab15 --- /dev/null +++ b/public/js/watson-speech.min.js @@ -0,0 +1,8 @@ +// IBM Watson Speech JavaScript SDK +// 0.13.1 +// Generated at Wed Feb 24 14:07:56 EST 2016 +// Copyright IBM (Apache-2.0) +// https://github.com/watson-developer-cloud/speech-javascript-sdk +!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.WatsonSpeech=e()}}(function(){return function e(t,r,n){function i(s,a){if(!r[s]){if(!t[s]){var u="function"==typeof require&&require;if(!a&&u)return u(s,!0);if(o)return o(s,!0);var c=new Error("Cannot find module '"+s+"'");throw c.code="MODULE_NOT_FOUND",c}var f=r[s]={exports:{}};t[s][0].call(f.exports,function(e){var r=t[s][1][e];return i(r?r:e)},f,f.exports,e,t,r,n)}return r[s].exports}for(var o="function"==typeof require&&require,s=0;s1?arguments[1]:"utf8"):u(this,e)):arguments.length>1?new o(e,arguments[1]):new o(e)}function s(e,t){if(e=g(e,0>t?0:0|m(t)),!o.TYPED_ARRAY_SUPPORT)for(var r=0;t>r;r++)e[r]=0;return e}function a(e,t,r){("string"!=typeof r||""===r)&&(r="utf8");var n=0|y(t,r);return e=g(e,n),e.write(t,r),e}function u(e,t){if(o.isBuffer(t))return c(e,t);if(V(t))return f(e,t);if(null==t)throw new TypeError("must start with number, buffer, array or string");if("undefined"!=typeof ArrayBuffer){if(t.buffer instanceof ArrayBuffer)return l(e,t);if(t instanceof ArrayBuffer)return h(e,t)}return t.length?p(e,t):d(e,t)}function c(e,t){var r=0|m(t.length);return e=g(e,r),t.copy(e,0,0,r),e}function f(e,t){var r=0|m(t.length);e=g(e,r);for(var n=0;r>n;n+=1)e[n]=255&t[n];return e}function l(e,t){var r=0|m(t.length);e=g(e,r);for(var n=0;r>n;n+=1)e[n]=255&t[n];return e}function h(e,t){return t.byteLength,o.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t),e.__proto__=o.prototype):e=l(e,new Uint8Array(t)),e}function p(e,t){var r=0|m(t.length);e=g(e,r);for(var n=0;r>n;n+=1)e[n]=255&t[n];return e}function d(e,t){var r,n=0;"Buffer"===t.type&&V(t.data)&&(r=t.data,n=0|m(r.length)),e=g(e,n);for(var i=0;n>i;i+=1)e[i]=255&r[i];return e}function g(e,t){o.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t),e.__proto__=o.prototype):e.length=t;var r=0!==t&&t<=o.poolSize>>>1;return r&&(e.parent=Z),e}function m(e){if(e>=i())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i().toString(16)+" bytes");return 0|e}function b(e,t){if(!(this instanceof b))return new b(e,t);var r=new o(e,t);return delete r.parent,r}function y(e,t){"string"!=typeof e&&(e=""+e);var r=e.length;if(0===r)return 0;for(var n=!1;;)switch(t){case"ascii":case"binary":case"raw":case"raws":return r;case"utf8":case"utf-8":return Y(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return $(e).length;default:if(n)return Y(e).length;t=(""+t).toLowerCase(),n=!0}}function v(e,t,r){var n=!1;if(t=0|t,r=void 0===r||r===1/0?this.length:0|r,e||(e="utf8"),0>t&&(t=0),r>this.length&&(r=this.length),t>=r)return"";for(;;)switch(e){case"hex":return M(this,t,r);case"utf8":case"utf-8":return k(this,t,r);case"ascii":return O(this,t,r);case"binary":return T(this,t,r);case"base64":return R(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return P(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function w(e,t,r,n){r=Number(r)||0;var i=e.length-r;n?(n=Number(n),n>i&&(n=i)):n=i;var o=t.length;if(o%2!==0)throw new Error("Invalid hex string");n>o/2&&(n=o/2);for(var s=0;n>s;s++){var a=parseInt(t.substr(2*s,2),16);if(isNaN(a))throw new Error("Invalid hex string");e[r+s]=a}return s}function _(e,t,r,n){return H(Y(t,e.length-r),e,r,n)}function S(e,t,r,n){return H(q(t),e,r,n)}function j(e,t,r,n){return S(e,t,r,n)}function E(e,t,r,n){return H($(t),e,r,n)}function x(e,t,r,n){return H(J(t,e.length-r),e,r,n)}function R(e,t,r){return 0===t&&r===e.length?G.fromByteArray(e):G.fromByteArray(e.slice(t,r))}function k(e,t,r){r=Math.min(e.length,r);for(var n=[],i=t;r>i;){var o=e[i],s=null,a=o>239?4:o>223?3:o>191?2:1;if(r>=i+a){var u,c,f,l;switch(a){case 1:128>o&&(s=o);break;case 2:u=e[i+1],128===(192&u)&&(l=(31&o)<<6|63&u,l>127&&(s=l));break;case 3:u=e[i+1],c=e[i+2],128===(192&u)&&128===(192&c)&&(l=(15&o)<<12|(63&u)<<6|63&c,l>2047&&(55296>l||l>57343)&&(s=l));break;case 4:u=e[i+1],c=e[i+2],f=e[i+3],128===(192&u)&&128===(192&c)&&128===(192&f)&&(l=(15&o)<<18|(63&u)<<12|(63&c)<<6|63&f,l>65535&&1114112>l&&(s=l))}}null===s?(s=65533,a=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|1023&s),n.push(s),i+=a}return A(n)}function A(e){var t=e.length;if(K>=t)return String.fromCharCode.apply(String,e);for(var r="",n=0;t>n;)r+=String.fromCharCode.apply(String,e.slice(n,n+=K));return r}function O(e,t,r){var n="";r=Math.min(e.length,r);for(var i=t;r>i;i++)n+=String.fromCharCode(127&e[i]);return n}function T(e,t,r){var n="";r=Math.min(e.length,r);for(var i=t;r>i;i++)n+=String.fromCharCode(e[i]);return n}function M(e,t,r){var n=e.length;(!t||0>t)&&(t=0),(!r||0>r||r>n)&&(r=n);for(var i="",o=t;r>o;o++)i+=F(e[o]);return i}function P(e,t,r){for(var n=e.slice(t,r),i="",o=0;oe)throw new RangeError("offset is not uint");if(e+t>r)throw new RangeError("Trying to access beyond buffer length")}function L(e,t,r,n,i,s){if(!o.isBuffer(e))throw new TypeError("buffer must be a Buffer instance");if(t>i||s>t)throw new RangeError("value is out of bounds");if(r+n>e.length)throw new RangeError("index out of range")}function D(e,t,r,n){0>t&&(t=65535+t+1);for(var i=0,o=Math.min(e.length-r,2);o>i;i++)e[r+i]=(t&255<<8*(n?i:1-i))>>>8*(n?i:1-i)}function U(e,t,r,n){0>t&&(t=4294967295+t+1);for(var i=0,o=Math.min(e.length-r,4);o>i;i++)e[r+i]=t>>>8*(n?i:3-i)&255}function C(e,t,r,n,i,o){if(r+n>e.length)throw new RangeError("index out of range");if(0>r)throw new RangeError("index out of range")}function z(e,t,r,n,i){return i||C(e,t,r,4,3.4028234663852886e38,-3.4028234663852886e38),X.write(e,t,r,n,23,4),r+4}function I(e,t,r,n,i){return i||C(e,t,r,8,1.7976931348623157e308,-1.7976931348623157e308),X.write(e,t,r,n,52,8),r+8}function N(e){if(e=W(e).replace(Q,""),e.length<2)return"";for(;e.length%4!==0;)e+="=";return e}function W(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}function F(e){return 16>e?"0"+e.toString(16):e.toString(16)}function Y(e,t){t=t||1/0;for(var r,n=e.length,i=null,o=[],s=0;n>s;s++){if(r=e.charCodeAt(s),r>55295&&57344>r){if(!i){if(r>56319){(t-=3)>-1&&o.push(239,191,189);continue}if(s+1===n){(t-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(56320>r){(t-=3)>-1&&o.push(239,191,189),i=r;continue}r=(i-55296<<10|r-56320)+65536}else i&&(t-=3)>-1&&o.push(239,191,189);if(i=null,128>r){if((t-=1)<0)break;o.push(r)}else if(2048>r){if((t-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(65536>r){if((t-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(1114112>r))throw new Error("Invalid code point");if((t-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function q(e){for(var t=[],r=0;r>8,i=r%256,o.push(i),o.push(n);return o}function $(e){return G.toByteArray(N(e))}function H(e,t,r,n){for(var i=0;n>i&&!(i+r>=t.length||i>=e.length);i++)t[i+r]=e[i];return i}var G=e("base64-js"),X=e("ieee754"),V=e("isarray");r.Buffer=o,r.SlowBuffer=b,r.INSPECT_MAX_BYTES=50,o.poolSize=8192;var Z={};o.TYPED_ARRAY_SUPPORT=void 0!==t.TYPED_ARRAY_SUPPORT?t.TYPED_ARRAY_SUPPORT:n(),o._augment=function(e){return e.__proto__=o.prototype,e},o.TYPED_ARRAY_SUPPORT?(o.prototype.__proto__=Uint8Array.prototype,o.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&o[Symbol.species]===o&&Object.defineProperty(o,Symbol.species,{value:null,configurable:!0})):(o.prototype.length=void 0,o.prototype.parent=void 0),o.isBuffer=function(e){return!(null==e||!e._isBuffer)},o.compare=function(e,t){if(!o.isBuffer(e)||!o.isBuffer(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var r=e.length,n=t.length,i=0,s=Math.min(r,n);s>i&&e[i]===t[i];)++i;return i!==s&&(r=e[i],n=t[i]),n>r?-1:r>n?1:0},o.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},o.concat=function(e,t){if(!V(e))throw new TypeError("list argument must be an Array of Buffers.");if(0===e.length)return new o(0);var r;if(void 0===t)for(t=0,r=0;r0&&(e=this.toString("hex",0,t).match(/.{2}/g).join(" "),this.length>t&&(e+=" ... ")),""},o.prototype.compare=function(e){if(!o.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?0:o.compare(this,e)},o.prototype.indexOf=function(e,t){function r(e,t,r){for(var n=-1,i=0;r+i2147483647?t=2147483647:-2147483648>t&&(t=-2147483648),t>>=0,0===this.length)return-1;if(t>=this.length)return-1;if(0>t&&(t=Math.max(this.length+t,0)),"string"==typeof e)return 0===e.length?-1:String.prototype.indexOf.call(this,e,t);if(o.isBuffer(e))return r(this,e,t);if("number"==typeof e)return o.TYPED_ARRAY_SUPPORT&&"function"===Uint8Array.prototype.indexOf?Uint8Array.prototype.indexOf.call(this,e,t):r(this,[e],t);throw new TypeError("val must be string, number or Buffer")},o.prototype.write=function(e,t,r,n){if(void 0===t)n="utf8",r=this.length,t=0;else if(void 0===r&&"string"==typeof t)n=t,r=this.length,t=0;else if(isFinite(t))t=0|t,isFinite(r)?(r=0|r,void 0===n&&(n="utf8")):(n=r,r=void 0);else{var i=n;n=t,t=0|r,r=i}var o=this.length-t;if((void 0===r||r>o)&&(r=o),e.length>0&&(0>r||0>t)||t>this.length)throw new RangeError("attempt to write outside buffer bounds");n||(n="utf8");for(var s=!1;;)switch(n){case"hex":return w(this,e,t,r);case"utf8":case"utf-8":return _(this,e,t,r);case"ascii":return S(this,e,t,r);case"binary":return j(this,e,t,r);case"base64":return E(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return x(this,e,t,r);default:if(s)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),s=!0}},o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var K=4096;o.prototype.slice=function(e,t){var r=this.length;e=~~e,t=void 0===t?r:~~t,0>e?(e+=r,0>e&&(e=0)):e>r&&(e=r),0>t?(t+=r,0>t&&(t=0)):t>r&&(t=r),e>t&&(t=e);var n;if(o.TYPED_ARRAY_SUPPORT)n=this.subarray(e,t),n.__proto__=o.prototype;else{var i=t-e;n=new o(i,void 0);for(var s=0;i>s;s++)n[s]=this[s+e]}return n.length&&(n.parent=this.parent||this),n},o.prototype.readUIntLE=function(e,t,r){e=0|e,t=0|t,r||B(e,t,this.length);for(var n=this[e],i=1,o=0;++o0&&(i*=256);)n+=this[e+--t]*i;return n},o.prototype.readUInt8=function(e,t){return t||B(e,1,this.length),this[e]},o.prototype.readUInt16LE=function(e,t){return t||B(e,2,this.length),this[e]|this[e+1]<<8},o.prototype.readUInt16BE=function(e,t){return t||B(e,2,this.length),this[e]<<8|this[e+1]},o.prototype.readUInt32LE=function(e,t){return t||B(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},o.prototype.readUInt32BE=function(e,t){return t||B(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},o.prototype.readIntLE=function(e,t,r){e=0|e,t=0|t,r||B(e,t,this.length);for(var n=this[e],i=1,o=0;++o=i&&(n-=Math.pow(2,8*t)),n},o.prototype.readIntBE=function(e,t,r){e=0|e,t=0|t,r||B(e,t,this.length);for(var n=t,i=1,o=this[e+--n];n>0&&(i*=256);)o+=this[e+--n]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*t)),o},o.prototype.readInt8=function(e,t){return t||B(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},o.prototype.readInt16LE=function(e,t){t||B(e,2,this.length);var r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},o.prototype.readInt16BE=function(e,t){t||B(e,2,this.length);var r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},o.prototype.readInt32LE=function(e,t){return t||B(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},o.prototype.readInt32BE=function(e,t){return t||B(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},o.prototype.readFloatLE=function(e,t){return t||B(e,4,this.length),X.read(this,e,!0,23,4)},o.prototype.readFloatBE=function(e,t){return t||B(e,4,this.length),X.read(this,e,!1,23,4)},o.prototype.readDoubleLE=function(e,t){return t||B(e,8,this.length),X.read(this,e,!0,52,8)},o.prototype.readDoubleBE=function(e,t){return t||B(e,8,this.length),X.read(this,e,!1,52,8)},o.prototype.writeUIntLE=function(e,t,r,n){e=+e,t=0|t,r=0|r,n||L(this,e,t,r,Math.pow(2,8*r),0);var i=1,o=0;for(this[t]=255&e;++o=0&&(o*=256);)this[t+i]=e/o&255;return t+r},o.prototype.writeUInt8=function(e,t,r){return e=+e,t=0|t,r||L(this,e,t,1,255,0),o.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},o.prototype.writeUInt16LE=function(e,t,r){return e=+e,t=0|t,r||L(this,e,t,2,65535,0),o.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):D(this,e,t,!0),t+2},o.prototype.writeUInt16BE=function(e,t,r){return e=+e,t=0|t,r||L(this,e,t,2,65535,0),o.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):D(this,e,t,!1),t+2},o.prototype.writeUInt32LE=function(e,t,r){return e=+e,t=0|t,r||L(this,e,t,4,4294967295,0),o.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):U(this,e,t,!0),t+4},o.prototype.writeUInt32BE=function(e,t,r){return e=+e,t=0|t,r||L(this,e,t,4,4294967295,0),o.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):U(this,e,t,!1),t+4},o.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t=0|t,!n){var i=Math.pow(2,8*r-1);L(this,e,t,r,i-1,-i)}var o=0,s=1,a=0>e?1:0;for(this[t]=255&e;++o>0)-a&255;return t+r},o.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t=0|t,!n){var i=Math.pow(2,8*r-1);L(this,e,t,r,i-1,-i)}var o=r-1,s=1,a=0>e?1:0;for(this[t+o]=255&e;--o>=0&&(s*=256);)this[t+o]=(e/s>>0)-a&255;return t+r},o.prototype.writeInt8=function(e,t,r){return e=+e,t=0|t,r||L(this,e,t,1,127,-128),o.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),0>e&&(e=255+e+1),this[t]=255&e,t+1},o.prototype.writeInt16LE=function(e,t,r){return e=+e,t=0|t,r||L(this,e,t,2,32767,-32768),o.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):D(this,e,t,!0),t+2},o.prototype.writeInt16BE=function(e,t,r){return e=+e,t=0|t,r||L(this,e,t,2,32767,-32768),o.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):D(this,e,t,!1),t+2},o.prototype.writeInt32LE=function(e,t,r){return e=+e,t=0|t,r||L(this,e,t,4,2147483647,-2147483648),o.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):U(this,e,t,!0),t+4},o.prototype.writeInt32BE=function(e,t,r){return e=+e,t=0|t,r||L(this,e,t,4,2147483647,-2147483648),0>e&&(e=4294967295+e+1),o.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):U(this,e,t,!1),t+4},o.prototype.writeFloatLE=function(e,t,r){return z(this,e,t,!0,r)},o.prototype.writeFloatBE=function(e,t,r){return z(this,e,t,!1,r)},o.prototype.writeDoubleLE=function(e,t,r){return I(this,e,t,!0,r)},o.prototype.writeDoubleBE=function(e,t,r){return I(this,e,t,!1,r)},o.prototype.copy=function(e,t,r,n){if(r||(r=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&r>n&&(n=r),n===r)return 0;if(0===e.length||0===this.length)return 0;if(0>t)throw new RangeError("targetStart out of bounds");if(0>r||r>=this.length)throw new RangeError("sourceStart out of bounds");if(0>n)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-tr&&n>t)for(i=s-1;i>=0;i--)e[i+t]=this[i+r];else if(1e3>s||!o.TYPED_ARRAY_SUPPORT)for(i=0;s>i;i++)e[i+t]=this[i+r];else Uint8Array.prototype.set.call(e,this.subarray(r,r+s),t);return s},o.prototype.fill=function(e,t,r){if(e||(e=0),t||(t=0),r||(r=this.length),t>r)throw new RangeError("end < start");if(r!==t&&0!==this.length){if(0>t||t>=this.length)throw new RangeError("start out of bounds");if(0>r||r>this.length)throw new RangeError("end out of bounds");var n;if("number"==typeof e)for(n=t;r>n;n++)this[n]=e;else{var i=Y(e.toString()),o=i.length;for(n=t;r>n;n++)this[n]=i[n%o]}return this}};var Q=/[^+\/0-9A-Za-z-_]/g}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"base64-js":4,ieee754:5,isarray:6}],4:[function(e,t,r){!function(e){"use strict";function t(e){var t=f[e.charCodeAt(0)];return void 0!==t?t:-1}function r(e){function r(e){u[f++]=e}var n,i,o,s,a,u;if(e.length%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var c=e.length;a="="===e.charAt(c-2)?2:"="===e.charAt(c-1)?1:0,u=new l(3*e.length/4-a),o=a>0?e.length-4:e.length;var f=0;for(n=0,i=0;o>n;n+=4,i+=3)s=t(e.charAt(n))<<18|t(e.charAt(n+1))<<12|t(e.charAt(n+2))<<6|t(e.charAt(n+3)),r((16711680&s)>>16),r((65280&s)>>8),r(255&s);return 2===a?(s=t(e.charAt(n))<<2|t(e.charAt(n+1))>>4,r(255&s)):1===a&&(s=t(e.charAt(n))<<10|t(e.charAt(n+1))<<4|t(e.charAt(n+2))>>2,r(s>>8&255),r(255&s)),u}function n(e){return c[e]}function i(e){return n(e>>18&63)+n(e>>12&63)+n(e>>6&63)+n(63&e)}function o(e,t,r){for(var n,o=[],s=t;r>s;s+=3)n=(e[s]<<16)+(e[s+1]<<8)+e[s+2],o.push(i(n));return o.join("")}function s(e){var t,r,i,s=e.length%3,a="",u=[],c=16383;for(t=0,i=e.length-s;i>t;t+=c)u.push(o(e,t,t+c>i?i:t+c));switch(s){case 1:r=e[e.length-1],a+=n(r>>2),a+=n(r<<4&63),a+="==";break;case 2:r=(e[e.length-2]<<8)+e[e.length-1],a+=n(r>>10),a+=n(r>>4&63),a+=n(r<<2&63),a+="="}return u.push(a),u.join("")}var a,u="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",c=[];for(a=0;a>1,f=-7,l=r?i-1:0,h=r?-1:1,p=e[t+l];for(l+=h,o=p&(1<<-f)-1,p>>=-f,f+=a;f>0;o=256*o+e[t+l],l+=h,f-=8);for(s=o&(1<<-f)-1,o>>=-f,f+=n;f>0;s=256*s+e[t+l],l+=h,f-=8);if(0===o)o=1-c;else{if(o===u)return s?NaN:(p?-1:1)*(1/0);s+=Math.pow(2,n),o-=c}return(p?-1:1)*s*Math.pow(2,o-n)},r.write=function(e,t,r,n,i,o){var s,a,u,c=8*o-i-1,f=(1<>1,h=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:o-1,d=n?1:-1,g=0>t||0===t&&0>1/t?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=f):(s=Math.floor(Math.log(t)/Math.LN2),t*(u=Math.pow(2,-s))<1&&(s--,u*=2),t+=s+l>=1?h/u:h*Math.pow(2,1-l),t*u>=2&&(s++,u/=2),s+l>=f?(a=0,s=f):s+l>=1?(a=(t*u-1)*Math.pow(2,i),s+=l):(a=t*Math.pow(2,l-1)*Math.pow(2,i),s=0));i>=8;e[r+p]=255&a,p+=d,a/=256,i-=8);for(s=s<0;e[r+p]=255&s,p+=d,s/=256,c-=8);e[r+p-d]|=128*g}},{}],6:[function(e,t,r){var n={}.toString;t.exports=Array.isArray||function(e){return"[object Array]"==n.call(e)}},{}],7:[function(e,t,r){function n(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function i(e){return"function"==typeof e}function o(e){return"number"==typeof e}function s(e){return"object"==typeof e&&null!==e}function a(e){return void 0===e}t.exports=n,n.EventEmitter=n,n.prototype._events=void 0,n.prototype._maxListeners=void 0,n.defaultMaxListeners=10,n.prototype.setMaxListeners=function(e){if(!o(e)||0>e||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},n.prototype.emit=function(e){var t,r,n,o,u,c;if(this._events||(this._events={}),"error"===e&&(!this._events.error||s(this._events.error)&&!this._events.error.length)){if(t=arguments[1],t instanceof Error)throw t;throw TypeError('Uncaught, unspecified "error" event.')}if(r=this._events[e],a(r))return!1;if(i(r))switch(arguments.length){case 1:r.call(this);break;case 2:r.call(this,arguments[1]);break;case 3:r.call(this,arguments[1],arguments[2]);break;default:o=Array.prototype.slice.call(arguments,1),r.apply(this,o)}else if(s(r))for(o=Array.prototype.slice.call(arguments,1),c=r.slice(),n=c.length,u=0;n>u;u++)c[u].apply(this,o);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]?s(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,s(this._events[e])&&!this._events[e].warned&&(r=a(this._maxListeners)?n.defaultMaxListeners:this._maxListeners,r&&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 r(){this.removeListener(e,r),n||(n=!0,t.apply(this,arguments))}if(!i(t))throw TypeError("listener must be a function");var n=!1;return r.listener=t,this.on(e,r),this},n.prototype.removeListener=function(e,t){var r,n,o,a;if(!i(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(r=this._events[e],o=r.length,n=-1,r===t||i(r.listener)&&r.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(s(r)){for(a=o;a-- >0;)if(r[a]===t||r[a].listener&&r[a].listener===t){n=a;break}if(0>n)return this;1===r.length?(r.length=0,delete this._events[e]):r.splice(n,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},n.prototype.removeAllListeners=function(e){var t,r;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(r=this._events[e],i(r))this.removeListener(e,r);else if(r)for(;r.length;)this.removeListener(e,r[r.length-1]);return delete this._events[e],this},n.prototype.listeners=function(e){var t;return t=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)}},{}],8:[function(e,t,r){"function"==typeof Object.create?t.exports=function(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}:t.exports=function(e,t){e.super_=t;var r=function(){};r.prototype=t.prototype,e.prototype=new r,e.prototype.constructor=e}},{}],9:[function(e,t,r){t.exports=function(e){return!(null==e||!(e._isBuffer||e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)))}},{}],10:[function(e,t,r){t.exports=Array.isArray||function(e){return"[object Array]"==Object.prototype.toString.call(e)}},{}],11:[function(e,t,r){function n(){f=!1,a.length?c=a.concat(c):l=-1,c.length&&i()}function i(){if(!f){var e=setTimeout(n);f=!0;for(var t=c.length;t;){for(a=c,c=[];++l1)for(var r=1;r0)if(t.ended&&!i){var a=new Error("stream.push() after EOF");e.emit("error",a)}else if(t.endEmitted&&i){var a=new Error("stream.unshift() after end event");e.emit("error",a)}else!t.decoder||i||n||(r=t.decoder.write(r)),i||(t.reading=!1),t.flowing&&0===t.length&&!t.sync?(e.emit("data",r),e.read(0)):(t.length+=t.objectMode?1:r.length,i?t.buffer.unshift(r):t.buffer.push(r),t.needReadable&&l(e)),p(e,t);else i||(t.reading=!1);return s(t)}function s(e){return!e.ended&&(e.needReadable||e.length=D?e=D:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}function u(e,t){return 0===t.length&&t.ended?0:t.objectMode?0===e?0:1:null===e||isNaN(e)?t.flowing&&t.buffer.length?t.buffer[0].length:t.length:0>=e?0:(e>t.highWaterMark&&(t.highWaterMark=a(e)),e>t.length?t.ended?t.length:(t.needReadable=!0,0):e)}function c(e,t){var r=null;return k.isBuffer(t)||"string"==typeof t||null===t||void 0===t||e.objectMode||(r=new TypeError("Invalid non-string/buffer chunk")),r}function f(e,t){if(!t.ended){if(t.decoder){var r=t.decoder.end();r&&r.length&&(t.buffer.push(r),t.length+=t.objectMode?1:r.length)}t.ended=!0,l(e)}}function l(e){var t=e._readableState;t.needReadable=!1,t.emittedReadable||(M("emitReadable",t.flowing),t.emittedReadable=!0,t.sync?x(h,e):h(e))}function h(e){M("emit readable"),e.emit("readable"),v(e)}function p(e,t){t.readingMore||(t.readingMore=!0,x(d,e,t))}function d(e,t){for(var r=t.length;!t.reading&&!t.flowing&&!t.ended&&t.length=i)r=o?n.join(""):1===n.length?n[0]:k.concat(n,i),n.length=0;else if(ec&&e>u;c++){var a=n[0],l=Math.min(e-u,a.length);o?r+=a.slice(0,l):a.copy(r,u,0,l),l0)throw new Error("endReadable called on non-empty stream");t.endEmitted||(t.ended=!0,x(S,t,e))}function S(e,t){e.endEmitted||0!==e.length||(e.endEmitted=!0,t.readable=!1,t.emit("end"))}function j(e,t){for(var r=0,n=e.length;n>r;r++)t(e[r],r)}function E(e,t){for(var r=0,n=e.length;n>r;r++)if(e[r]===t)return r;return-1}t.exports=i;var x=e("process-nextick-args"),R=e("isarray"),k=e("buffer").Buffer;i.ReadableState=n;var A,O=(e("events"),function(e,t){return e.listeners(t).length});!function(){try{A=e("stream")}catch(e){}finally{A||(A=e("events").EventEmitter)}}();var k=e("buffer").Buffer,T=e("core-util-is");T.inherits=e("inherits");var M,P=e("util");M=P&&P.debuglog?P.debuglog("stream"):function(){};var B;T.inherits(i,A);var L,L;i.prototype.push=function(e,t){var r=this._readableState;return r.objectMode||"string"!=typeof e||(t=t||r.defaultEncoding,t!==r.encoding&&(e=new k(e,t),t="")),o(this,r,e,t,!1)},i.prototype.unshift=function(e){var t=this._readableState;return o(this,t,e,"",!0)},i.prototype.isPaused=function(){return this._readableState.flowing===!1},i.prototype.setEncoding=function(t){return B||(B=e("string_decoder/").StringDecoder),this._readableState.decoder=new B(t),this._readableState.encoding=t,this};var D=8388608;i.prototype.read=function(e){M("read",e);var t=this._readableState,r=e;if(("number"!=typeof e||e>0)&&(t.emittedReadable=!1),0===e&&t.needReadable&&(t.length>=t.highWaterMark||t.ended))return M("read: emitReadable",t.length,t.ended), + 0===t.length&&t.ended?_(this):l(this),null;if(e=u(e,t),0===e&&t.ended)return 0===t.length&&_(this),null;var n=t.needReadable;M("need readable",n),(0===t.length||t.length-e0?w(e,t):null,null===i&&(t.needReadable=!0,e=0),t.length-=e,0!==t.length||t.ended||(t.needReadable=!0),r!==e&&t.ended&&0===t.length&&_(this),null!==i&&this.emit("data",i),i},i.prototype._read=function(e){this.emit("error",new Error("not implemented"))},i.prototype.pipe=function(e,t){function n(e){M("onunpipe"),e===l&&o()}function i(){M("onend"),e.end()}function o(){M("cleanup"),e.removeListener("close",u),e.removeListener("finish",c),e.removeListener("drain",m),e.removeListener("error",a),e.removeListener("unpipe",n),l.removeListener("end",i),l.removeListener("end",o),l.removeListener("data",s),b=!0,!h.awaitDrain||e._writableState&&!e._writableState.needDrain||m()}function s(t){M("ondata");var r=e.write(t);!1===r&&(1!==h.pipesCount||h.pipes[0]!==e||1!==l.listenerCount("data")||b||(M("false write response, pause",l._readableState.awaitDrain),l._readableState.awaitDrain++),l.pause())}function a(t){M("onerror",t),f(),e.removeListener("error",a),0===O(e,"error")&&e.emit("error",t)}function u(){e.removeListener("finish",c),f()}function c(){M("onfinish"),e.removeListener("close",u),f()}function f(){M("unpipe"),l.unpipe(e)}var l=this,h=this._readableState;switch(h.pipesCount){case 0:h.pipes=e;break;case 1:h.pipes=[h.pipes,e];break;default:h.pipes.push(e)}h.pipesCount+=1,M("pipe count=%d opts=%j",h.pipesCount,t);var p=(!t||t.end!==!1)&&e!==r.stdout&&e!==r.stderr,d=p?i:o;h.endEmitted?x(d):l.once("end",d),e.on("unpipe",n);var m=g(l);e.on("drain",m);var b=!1;return l.on("data",s),e._events&&e._events.error?R(e._events.error)?e._events.error.unshift(a):e._events.error=[a,e._events.error]:e.on("error",a),e.once("close",u),e.once("finish",c),e.emit("pipe",l),h.flowing||(M("pipe resume"),l.resume()),e},i.prototype.unpipe=function(e){var t=this._readableState;if(0===t.pipesCount)return this;if(1===t.pipesCount)return e&&e!==t.pipes?this:(e||(e=t.pipes),t.pipes=null,t.pipesCount=0,t.flowing=!1,e&&e.emit("unpipe",this),this);if(!e){var r=t.pipes,n=t.pipesCount;t.pipes=null,t.pipesCount=0,t.flowing=!1;for(var i=0;n>i;i++)r[i].emit("unpipe",this);return this}var i=E(t.pipes,e);return-1===i?this:(t.pipes.splice(i,1),t.pipesCount-=1,1===t.pipesCount&&(t.pipes=t.pipes[0]),e.emit("unpipe",this),this)},i.prototype.on=function(e,t){var r=A.prototype.on.call(this,e,t);if("data"===e&&!1!==this._readableState.flowing&&this.resume(),"readable"===e&&this.readable){var n=this._readableState;n.readableListening||(n.readableListening=!0,n.emittedReadable=!1,n.needReadable=!0,n.reading?n.length&&l(this,n):x(m,this))}return r},i.prototype.addListener=i.prototype.on,i.prototype.resume=function(){var e=this._readableState;return e.flowing||(M("resume"),e.flowing=!0,b(this,e)),this},i.prototype.pause=function(){return M("call pause flowing=%j",this._readableState.flowing),!1!==this._readableState.flowing&&(M("pause"),this._readableState.flowing=!1,this.emit("pause")),this},i.prototype.wrap=function(e){var t=this._readableState,r=!1,n=this;e.on("end",function(){if(M("wrapped end"),t.decoder&&!t.ended){var e=t.decoder.end();e&&e.length&&n.push(e)}n.push(null)}),e.on("data",function(i){if(M("wrapped data"),t.decoder&&(i=t.decoder.write(i)),(!t.objectMode||null!==i&&void 0!==i)&&(t.objectMode||i&&i.length)){var o=n.push(i);o||(r=!0,e.pause())}});for(var i in e)void 0===this[i]&&"function"==typeof e[i]&&(this[i]=function(t){return function(){return e[t].apply(e,arguments)}}(i));var o=["error","close","destroy","pause","resume"];return j(o,function(t){e.on(t,n.emit.bind(n,t))}),n._read=function(t){M("wrapped _read",t),r&&(r=!1,e.resume())},n},i._fromList=w}).call(this,e("_process"))},{"./_stream_duplex":13,_process:11,buffer:3,"core-util-is":18,events:7,inherits:8,isarray:10,"process-nextick-args":19,"string_decoder/":26,util:2}],16:[function(e,t,r){"use strict";function n(e){this.afterTransform=function(t,r){return i(e,t,r)},this.needTransform=!1,this.transforming=!1,this.writecb=null,this.writechunk=null}function i(e,t,r){var n=e._transformState;n.transforming=!1;var i=n.writecb;if(!i)return e.emit("error",new Error("no writecb in Transform class"));n.writechunk=null,n.writecb=null,null!==r&&void 0!==r&&e.push(r),i&&i(t);var o=e._readableState;o.reading=!1,(o.needReadable||o.length-1))throw new TypeError("Unknown encoding: "+e);this._writableState.defaultEncoding=e},s.prototype._write=function(e,t,r){r(new Error("not implemented"))},s.prototype._writev=null,s.prototype.end=function(e,t,r){var n=this._writableState;"function"==typeof e?(r=e,e=null,t=null):"function"==typeof t&&(r=t,t=null),null!==e&&void 0!==e&&this.write(e,t),n.corked&&(n.corked=1,this.uncork()),n.ending||n.finished||_(this,n,r)}},{"./_stream_duplex":13,buffer:3,"core-util-is":18,events:7,inherits:8,"process-nextick-args":19,"util-deprecate":20}],18:[function(e,t,r){(function(e){function t(e){return Array.isArray?Array.isArray(e):"[object Array]"===m(e)}function n(e){return"boolean"==typeof e}function i(e){return null===e}function o(e){return null==e}function s(e){return"number"==typeof e}function a(e){return"string"==typeof e}function u(e){return"symbol"==typeof e}function c(e){return void 0===e}function f(e){return"[object RegExp]"===m(e)}function l(e){return"object"==typeof e&&null!==e}function h(e){return"[object Date]"===m(e)}function p(e){return"[object Error]"===m(e)||e instanceof Error}function d(e){return"function"==typeof e}function g(e){return null===e||"boolean"==typeof e||"number"==typeof e||"string"==typeof e||"symbol"==typeof e||"undefined"==typeof e}function m(e){return Object.prototype.toString.call(e)}r.isArray=t,r.isBoolean=n,r.isNull=i,r.isNullOrUndefined=o,r.isNumber=s,r.isString=a,r.isSymbol=u,r.isUndefined=c,r.isRegExp=f,r.isObject=l,r.isDate=h,r.isError=p,r.isFunction=d,r.isPrimitive=g,r.isBuffer=e.isBuffer}).call(this,{isBuffer:e("../../../../insert-module-globals/node_modules/is-buffer/index.js")})},{"../../../../insert-module-globals/node_modules/is-buffer/index.js":9}],19:[function(e,t,r){(function(e){"use strict";function r(t){for(var r=new Array(arguments.length-1),n=0;n=this.charLength-this.charReceived?this.charLength-this.charReceived:e.length;if(e.copy(this.charBuffer,this.charReceived,0,r),this.charReceived+=r,this.charReceived=55296&&56319>=n)){if(this.charReceived=this.charLength=0,0===e.length)return t;break}this.charLength+=this.surrogateSize,t=""}this.detectIncompleteChar(e);var i=e.length;this.charLength&&(e.copy(this.charBuffer,0,e.length-this.charReceived,i),i-=this.charReceived),t+=e.toString(this.encoding,0,i);var i=t.length-1,n=t.charCodeAt(i);if(n>=55296&&56319>=n){var o=this.surrogateSize;return this.charLength+=o,this.charReceived+=o,this.charBuffer.copy(this.charBuffer,o,0,o),e.copy(this.charBuffer,0,0,o),t.substring(0,i)}return t},c.prototype.detectIncompleteChar=function(e){for(var t=e.length>=3?3:e.length;t>0;t--){var r=e[e.length-t];if(1==t&&r>>5==6){this.charLength=2;break}if(2>=t&&r>>4==14){this.charLength=3;break}if(3>=t&&r>>3==30){this.charLength=4;break}}this.charReceived=t},c.prototype.end=function(e){var t="";if(e&&e.length&&(t=this.write(e)),this.charReceived){var r=this.charReceived,n=this.charBuffer,i=this.encoding;t+=n.slice(0,r).toString(i)}return t}},{buffer:3}],27:[function(e,t,r){t.exports=function(e){return e&&"object"==typeof e&&"function"==typeof e.copy&&"function"==typeof e.fill&&"function"==typeof e.readUInt8}},{}],28:[function(e,t,r){(function(t,n){function i(e,t){var n={seen:[],stylize:s};return arguments.length>=3&&(n.depth=arguments[2]),arguments.length>=4&&(n.colors=arguments[3]),g(t)?n.showHidden=t:t&&r._extend(n,t),_(n.showHidden)&&(n.showHidden=!1),_(n.depth)&&(n.depth=2),_(n.colors)&&(n.colors=!1),_(n.customInspect)&&(n.customInspect=!0),n.colors&&(n.stylize=o),u(n,e,n.depth)}function o(e,t){var r=i.styles[t];return r?"["+i.colors[r][0]+"m"+e+"["+i.colors[r][1]+"m":e}function s(e,t){return e}function a(e){var t={};return e.forEach(function(e,r){t[e]=!0}),t}function u(e,t,n){if(e.customInspect&&t&&R(t.inspect)&&t.inspect!==r.inspect&&(!t.constructor||t.constructor.prototype!==t)){var i=t.inspect(n,e);return v(i)||(i=u(e,i,n)),i}var o=c(e,t);if(o)return o;var s=Object.keys(t),g=a(s);if(e.showHidden&&(s=Object.getOwnPropertyNames(t)),x(t)&&(s.indexOf("message")>=0||s.indexOf("description")>=0))return f(t);if(0===s.length){if(R(t)){var m=t.name?": "+t.name:"";return e.stylize("[Function"+m+"]","special")}if(S(t))return e.stylize(RegExp.prototype.toString.call(t),"regexp");if(E(t))return e.stylize(Date.prototype.toString.call(t),"date");if(x(t))return f(t)}var b="",y=!1,w=["{","}"];if(d(t)&&(y=!0,w=["[","]"]),R(t)){var _=t.name?": "+t.name:"";b=" [Function"+_+"]"}if(S(t)&&(b=" "+RegExp.prototype.toString.call(t)),E(t)&&(b=" "+Date.prototype.toUTCString.call(t)),x(t)&&(b=" "+f(t)),0===s.length&&(!y||0==t.length))return w[0]+b+w[1];if(0>n)return S(t)?e.stylize(RegExp.prototype.toString.call(t),"regexp"):e.stylize("[Object]","special");e.seen.push(t);var j;return j=y?l(e,t,n,g,s):s.map(function(r){return h(e,t,n,g,r,y)}),e.seen.pop(),p(j,b,w)}function c(e,t){if(_(t))return e.stylize("undefined","undefined");if(v(t)){var r="'"+JSON.stringify(t).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return e.stylize(r,"string")}return y(t)?e.stylize(""+t,"number"):g(t)?e.stylize(""+t,"boolean"):m(t)?e.stylize("null","null"):void 0}function f(e){return"["+Error.prototype.toString.call(e)+"]"}function l(e,t,r,n,i){for(var o=[],s=0,a=t.length;a>s;++s)M(t,String(s))?o.push(h(e,t,r,n,String(s),!0)):o.push("");return i.forEach(function(i){i.match(/^\d+$/)||o.push(h(e,t,r,n,i,!0))}),o}function h(e,t,r,n,i,o){var s,a,c;if(c=Object.getOwnPropertyDescriptor(t,i)||{value:t[i]},c.get?a=c.set?e.stylize("[Getter/Setter]","special"):e.stylize("[Getter]","special"):c.set&&(a=e.stylize("[Setter]","special")),M(n,i)||(s="["+i+"]"),a||(e.seen.indexOf(c.value)<0?(a=m(r)?u(e,c.value,null):u(e,c.value,r-1),a.indexOf("\n")>-1&&(a=o?a.split("\n").map(function(e){return" "+e}).join("\n").substr(2):"\n"+a.split("\n").map(function(e){return" "+e}).join("\n"))):a=e.stylize("[Circular]","special")),_(s)){if(o&&i.match(/^\d+$/))return a;s=JSON.stringify(""+i),s.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(s=s.substr(1,s.length-2),s=e.stylize(s,"name")):(s=s.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),s=e.stylize(s,"string"))}return s+": "+a}function p(e,t,r){var n=0,i=e.reduce(function(e,t){return n++,t.indexOf("\n")>=0&&n++,e+t.replace(/\u001b\[\d\d?m/g,"").length+1},0);return i>60?r[0]+(""===t?"":t+"\n ")+" "+e.join(",\n ")+" "+r[1]:r[0]+t+" "+e.join(", ")+" "+r[1]}function d(e){return Array.isArray(e)}function g(e){return"boolean"==typeof e}function m(e){return null===e}function b(e){return null==e}function y(e){return"number"==typeof e}function v(e){return"string"==typeof e}function w(e){return"symbol"==typeof e}function _(e){return void 0===e}function S(e){return j(e)&&"[object RegExp]"===A(e)}function j(e){return"object"==typeof e&&null!==e}function E(e){return j(e)&&"[object Date]"===A(e)}function x(e){return j(e)&&("[object Error]"===A(e)||e instanceof Error)}function R(e){return"function"==typeof e}function k(e){return null===e||"boolean"==typeof e||"number"==typeof e||"string"==typeof e||"symbol"==typeof e||"undefined"==typeof e}function A(e){return Object.prototype.toString.call(e)}function O(e){return 10>e?"0"+e.toString(10):e.toString(10)}function T(){var e=new Date,t=[O(e.getHours()),O(e.getMinutes()),O(e.getSeconds())].join(":");return[e.getDate(),D[e.getMonth()],t].join(" ")}function M(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var P=/%[sdj%]/g;r.format=function(e){if(!v(e)){for(var t=[],r=0;r=o)return e;switch(e){case"%s":return String(n[r++]);case"%d":return Number(n[r++]);case"%j":try{return JSON.stringify(n[r++])}catch(e){return"[Circular]"}default:return e}}),a=n[r];o>r;a=n[++r])s+=m(a)||!j(a)?" "+a:" "+i(a);return s},r.deprecate=function(e,i){function o(){if(!s){if(t.throwDeprecation)throw new Error(i);t.traceDeprecation?console.trace(i):console.error(i),s=!0}return e.apply(this,arguments)}if(_(n.process))return function(){return r.deprecate(e,i).apply(this,arguments)};if(t.noDeprecation===!0)return e;var s=!1;return o};var B,L={};r.debuglog=function(e){if(_(B)&&(B=t.env.NODE_DEBUG||""),e=e.toUpperCase(),!L[e])if(new RegExp("\\b"+e+"\\b","i").test(B)){var n=t.pid;L[e]=function(){var t=r.format.apply(r,arguments);console.error("%s %d: %s",e,n,t)}}else L[e]=function(){};return L[e]},r.inspect=i,i.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},i.styles={special:"cyan",number:"yellow",boolean:"yellow",undefined:"grey",null:"bold",string:"green",date:"magenta",regexp:"red"},r.isArray=d,r.isBoolean=g,r.isNull=m,r.isNullOrUndefined=b,r.isNumber=y,r.isString=v,r.isSymbol=w,r.isUndefined=_,r.isRegExp=S,r.isObject=j,r.isDate=E,r.isError=x,r.isFunction=R,r.isPrimitive=k,r.isBuffer=e("./support/isBuffer");var D=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];r.log=function(){console.log("%s - %s",T(),r.format.apply(r,arguments))},r.inherits=e("inherits"),r._extend=function(e,t){if(!t||!j(t))return e;for(var r=Object.keys(t),n=r.length;n--;)e[r[n]]=t[r[n]];return e}}).call(this,e("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./support/isBuffer":27,_process:11,inherits:8}],29:[function(e,t,r){(function(e){var r=function(){"use strict";function t(r,n,i,o){function a(r,i){if(null===r)return null;if(0==i)return r;var u,h;if("object"!=typeof r)return r;if(t.__isArray(r))u=[];else if(t.__isRegExp(r))u=new RegExp(r.source,s(r)),r.lastIndex&&(u.lastIndex=r.lastIndex);else if(t.__isDate(r))u=new Date(r.getTime());else{if(l&&e.isBuffer(r))return u=new e(r.length),r.copy(u),u;"undefined"==typeof o?(h=Object.getPrototypeOf(r),u=Object.create(h)):(u=Object.create(o),h=o)}if(n){var p=c.indexOf(r);if(-1!=p)return f[p];c.push(r),f.push(u)}for(var d in r){var g;h&&(g=Object.getOwnPropertyDescriptor(h,d)),g&&null==g.set||(u[d]=a(r[d],i-1))}return u}var u;"object"==typeof n&&(i=n.depth,o=n.prototype,u=n.filter,n=n.circular);var c=[],f=[],l="undefined"!=typeof e;return"undefined"==typeof n&&(n=!0),"undefined"==typeof i&&(i=1/0),a(r,i)}function r(e){return Object.prototype.toString.call(e)}function n(e){return"object"==typeof e&&"[object Date]"===r(e)}function i(e){return"object"==typeof e&&"[object Array]"===r(e)}function o(e){return"object"==typeof e&&"[object RegExp]"===r(e)}function s(e){var t="";return e.global&&(t+="g"),e.ignoreCase&&(t+="i"),e.multiline&&(t+="m"),t}return t.clonePrototype=function(e){if(null===e)return null;var t=function(){};return t.prototype=e,new t},t.__objToStr=r,t.__isDate=n,t.__isArray=i,t.__isRegExp=o,t.__getRegExpFlags=s,t}();"object"==typeof t&&t.exports&&(t.exports=r)}).call(this,e("buffer").Buffer)},{buffer:3}],30:[function(e,t,r){var n=e("clone");t.exports=function(e,t){return e=e||{},Object.keys(t).forEach(function(r){"undefined"==typeof e[r]&&(e[r]=n(t[r]))}),e}},{clone:29}],31:[function(e,t,r){(function(r,n){"use strict";function i(e,t){function i(e){f&&c.push(t.objectMode?e.inputBuffer:new n(e.inputBuffer.getChannelData(0)))}var s="undefined"==typeof window.AudioContext?4096:null;t=t||{},s=t.bufferSize||s;var a=1,u=1;o.call(this,t);var c=this,f=!0,l=window.AudioContext||window.webkitAudioContext,h=new l,p=h.createMediaStreamSource(e),d=h.createScriptProcessor(s,a,u);d.onaudioprocess=i,p.connect(d),d.connect(h.destination),this.stop=function(){try{e.getTracks()[0].stop()}catch(e){}d.disconnect(),p.disconnect();try{h.close()}catch(e){}f=!1,c.push(null),c.emit("close")},r.nextTick(function(){c.emit("format",{channels:1,bitDepth:32,sampleRate:h.sampleRate,signed:!0,float:!0})})}var o=e("stream").Readable,s=e("util");s.inherits(i,o),i.prototype._read=function(){},i.toRaw=function(e){return new Float32Array(e.buffer)},t.exports=i}).call(this,e("_process"),e("buffer").Buffer)},{_process:11,buffer:3,stream:25,util:28}],32:[function(e,t,r){"use strict";var n=e("object-keys");t.exports=function(){if("function"!=typeof Symbol||"function"!=typeof Object.getOwnPropertySymbols)return!1;if("symbol"==typeof Symbol.iterator)return!0;var e={},t=Symbol("test");if("string"==typeof t)return!1;var r=42;e[t]=r;for(t in e)return!1;if(0!==n(e).length)return!1;if("function"==typeof Object.keys&&0!==Object.keys(e).length)return!1;if("function"==typeof Object.getOwnPropertyNames&&0!==Object.getOwnPropertyNames(e).length)return!1;var i=Object.getOwnPropertySymbols(e);if(1!==i.length||i[0]!==t)return!1;if(!Object.prototype.propertyIsEnumerable.call(e,t))return!1;if("function"==typeof Object.getOwnPropertyDescriptor){var o=Object.getOwnPropertyDescriptor(e,t);if(o.value!==r||o.enumerable!==!0)return!1}return!0}},{"object-keys":36}],33:[function(e,t,r){"use strict";var n=e("object-keys"),i=e("function-bind"),o=function(e){return"undefined"!=typeof e&&null!==e},s=e("./hasSymbols")(),a=Object,u=i.call(Function.call,Array.prototype.push),c=i.call(Function.call,Object.prototype.propertyIsEnumerable);t.exports=function(e,t){if(!o(e))throw new TypeError("target must be an object");var r,i,f,l,h,p,d,g=a(e);for(r=1;rl;l++)f.push("$"+l);if(r=Function("binder","return function ("+f.join(",")+"){ return binder.apply(this,arguments); }")(u),t.prototype){var h=function(){};h.prototype=t.prototype,r.prototype=new h,h.prototype=null}return r}},{}],35:[function(e,t,r){var n=e("./implementation");t.exports=Function.prototype.bind||n},{"./implementation":34}],36:[function(e,t,r){"use strict";var n=Object.prototype.hasOwnProperty,i=Object.prototype.toString,o=Array.prototype.slice,s=e("./isArguments"),a=!{toString:null}.propertyIsEnumerable("toString"),u=function(){}.propertyIsEnumerable("prototype"),c=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],f=function(e){var t=e.constructor;return t&&t.prototype===e},l={$console:!0,$frame:!0,$frameElement:!0,$frames:!0,$parent:!0,$self:!0,$webkitIndexedDB:!0,$webkitStorageInfo:!0,$window:!0},h=function(){if("undefined"==typeof window)return!1;for(var e in window)try{if(!l["$"+e]&&n.call(window,e)&&null!==window[e]&&"object"==typeof window[e])try{f(window[e])}catch(e){return!0}}catch(e){return!0}return!1}(),p=function(e){if("undefined"==typeof window||!h)return f(e);try{return f(e)}catch(e){return!1}},d=function(e){var t=null!==e&&"object"==typeof e,r="[object Function]"===i.call(e),o=s(e),f=t&&"[object String]"===i.call(e),l=[];if(!t&&!r&&!o)throw new TypeError("Object.keys called on a non-object");var h=u&&r;if(f&&e.length>0&&!n.call(e,0))for(var d=0;d0)for(var g=0;g=0&&"[object Function]"===n.call(e.callee)),r}},{}],38:[function(e,t,r){"use strict";var n=e("./implementation"),i=function(){if(!Object.assign)return!1;for(var e="abcdefghijklmnopqrst",t=e.split(""),r={},n=0;n=this._blob.size)return void this.push(null);var i=this._blob.slice(t,r),s=new c;s.onload=function(){var e=new f(s.result);e=o(e),this.push(e)}.bind(this),s.onerror=function(){this.emit("error",s.error)}.bind(this),s.readAsArrayBuffer(i)}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},e("buffer").Buffer)},{buffer:3,inherits:41,stream:25}],41:[function(e,t,r){arguments[4][8][0].apply(r,arguments)},{dup:8}],42:[function(e,t,r){function n(e,t){var r;return r=t?new o(e,t):new o(e)}var i=function(){return this}(),o=i.WebSocket||i.MozWebSocket,s=e("./version");t.exports={w3cwebsocket:o?n:null,version:s}},{"./version":43}],43:[function(e,t,r){t.exports=e("../package.json").version},{"../package.json":44}],44:[function(e,t,r){t.exports={name:"websocket",description:"Websocket Client & Server Library implementing the WebSocket protocol as specified in RFC 6455.",keywords:["websocket","websockets","socket","networking","comet","push","RFC-6455","realtime","server","client"],author:{name:"Brian McKelvey",email:"brian@worlize.com",url:"https://www.worlize.com/"},contributors:[{name:"Iñaki Baz Castillo",email:"ibc@aliax.net",url:"http://dev.sipdoc.net"}],version:"1.0.22",repository:{type:"git",url:"git+https://github.com/theturtle32/WebSocket-Node.git"},homepage:"https://github.com/theturtle32/WebSocket-Node",engines:{node:">=0.8.0"},dependencies:{debug:"~2.2.0",nan:"~2.0.5","typedarray-to-buffer":"~3.0.3",yaeti:"~0.0.4"},devDependencies:{"buffer-equal":"^0.0.1",faucet:"^0.0.1",gulp:"git+https://github.com/gulpjs/gulp.git#4.0","gulp-jshint":"^1.11.2","jshint-stylish":"^1.0.2",tape:"^4.0.1"},config:{verbose:!1},scripts:{install:"(node-gyp rebuild 2> builderror.log) || (exit 0)",test:"faucet test/unit",gulp:"gulp"},main:"index",directories:{lib:"./lib"},browser:"lib/browser.js",license:"Apache-2.0",gitHead:"19108bbfd7d94a5cd02dbff3495eafee9e901ca4",bugs:{url:"https://github.com/theturtle32/WebSocket-Node/issues"},_id:"websocket@1.0.22",_shasum:"8c33e3449f879aaf518297c9744cebf812b9e3d8",_from:"websocket@>=1.0.22 <2.0.0",_npmVersion:"2.14.3",_nodeVersion:"3.3.1",_npmUser:{name:"theturtle32",email:"brian@worlize.com"},maintainers:[{name:"theturtle32",email:"brian@worlize.com"}],dist:{shasum:"8c33e3449f879aaf518297c9744cebf812b9e3d8",tarball:"http://registry.npmjs.org/websocket/-/websocket-1.0.22.tgz"},_resolved:"https://registry.npmjs.org/websocket/-/websocket-1.0.22.tgz",readme:"ERROR: No README data found!"}},{}],45:[function(e,t,r){"use strict";var n={fLaC:"audio/flac",RIFF:"audio/wav",OggS:"audio/ogg; codecs=opus"};t.exports=function(e){return n[e]}},{}],46:[function(e,t,r){"use strict";function n(e){return new Promise(function(t,r){var n=new Blob([e]).slice(0,4),i=new FileReader;i.readAsText(n),i.onload=function(){var e=s(i.result);if(e)t(e);else{var n=new Error("Unable to determine content type from file header; only wav, flac, and ogg/opus are supported.");n.name="UNRECOGNIZED_FORMAT",r(n)}}})}function i(e,t){var r=this.audio=new Audio;if(!r.canPlayType(t)){var n=new Error("Current browser is unable to play back "+t);throw n.name="UNSUPPORTED_FORMAT",n.contentType=t,n}r.src=URL.createObjectURL(new Blob([e],{type:t})),r.play(),this.stop=function(){r.pause(),r.currentTime=0}}function o(e){return n(e).then(function(t){return new i(e,t)})}var s=e("./content-type");t.exports=i,t.exports.getContentType=n,t.exports.playFile=o},{"./content-type":45}],47:[function(e,t,r){"use strict";function n(e){this.options=a(e,{model:"",hesitation:"…",decodeStrings:!1}),i.call(this,this.options),this.isJaCn="ja-JP"===this.options.model.substring(0,5)||"zh-CN"===this.options.model.substring(0,5),this._transform=this.options.objectMode?this.formatResult:this.formatString}var i=e("stream").Transform,o=e("util"),s=e("clone"),a=e("defaults");o.inherits(n,i);var u=/%HESITATION\s/g,c=/(.)\1{2,}/g,f=/D_[^\s]+/g;n.prototype.clean=function(e){return(e=e.trim().replace(u,this.options.hesitation).replace(c,"").replace(f,""))?(this.isJaCn&&(e=e.replace(/ /g,"")),e):e},n.prototype.capitalize=function(e){return e.charAt(0).toUpperCase()+e.substring(1)},n.prototype.period=function(e){return e+(this.isJaCn?"。":". ")},n.prototype.formatString=function(e,t,r){this.push(this.period(this.capitalize(this.clean(e.toString())))),r()},n.prototype.formatResult=function(e,t,r){e=s(e),e.alternatives=e.alternatives.map(function(t){return t.transcript=this.capitalize(this.clean(t.transcript)),e.final&&(t.transcript=this.period(t.transcript)),t.timestamps&&(t.timestamps=t.timestamps.map(function(t,r,n){return t[0]=this.clean(t[0]),0===r&&(t[0]=this.capitalize(t[0])),r==n.length-1&&e.final&&(t[0]=this.period(t[0])),t},this)),t},this),this.push(e),r()},n.prototype.promise=e("./to-promise"),t.exports=n},{"./to-promise":56,clone:29,defaults:30,stream:25,util:28}],48:[function(e,t,r){"use strict";t.exports=function(e){return navigator.mediaDevices&&navigator.mediaDevices.getUserMedia?navigator.mediaDevices.getUserMedia(e):new Promise(function(t,r){var n=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia;if(!n){var i=error=new Error("MediaStreamError");return error.name="NotSupportedError",r(i)}n.call(navigator,e,t,r)})}},{}],49:[function(e,t,r){(function(r){"use strict";t.exports={recognizeMicrophone:e("./recognize-microphone"),recognizeFile:e("./recognize-file"),recognizeElement:e("./recognize-element"),WebAudioL16Stream:e("./webaudio-l16-stream"),MediaElementAudioStream:e("./media-element-audio-stream"),RecognizeStream:e("./recognize-stream"),FilePlayer:e("./file-player"),getUserMedia:e("./getusermedia"),FormatStream:e("./format-stream"),TimingStream:e("./timing-stream"),WritableElementStream:e("./writable-element-stream"),MicrophoneStream:e("microphone-stream"),Buffer:r}}).call(this,e("buffer").Buffer)},{"./file-player":46,"./format-stream":47,"./getusermedia":48,"./media-element-audio-stream":50,"./recognize-element":51,"./recognize-file":52,"./recognize-microphone":53,"./recognize-stream":54,"./timing-stream":55,"./webaudio-l16-stream":57,"./writable-element-stream":58,buffer:3,"microphone-stream":31}],50:[function(e,t,r){(function(r,n){"use strict";function i(e,t){function i(e){p&&h.push(t.objectMode?e.inputBuffer:new n(e.inputBuffer.getChannelData(0)))}function s(){m.connect(b),b.connect(g.destination),e.removeEventListener("playing",s)}function u(){e.play(),e.removeEventListener("canplaythrough",u)}function c(){p=!1,b.disconnect(),m.disconnect(),h.push(null),h.emit("close")}t=a(t,{bufferSize:"undefined"!=typeof d?null:4096,muteSource:!1,autoPlay:!0,crossOrigin:"anonymous",objectMode:!0});var f=1,l=1;if("string"==typeof e&&(e=document.querySelector(e)),!e)throw new Error("Watson Speech to Text MediaElementAudioStream: missing element");o.call(this,t);var h=this,p=!0;e.crossOrigin=t.crossOrigin;var d=window.AudioContext||window.webkitAudioContext,g=e.context=e.context||new d,m=e.node=e.node||g.createMediaElementSource(e),b=g.createScriptProcessor(t.bufferSize,f,l);if(b.onaudioprocess=i,!t.muteSource){var y=g.createGain();m.connect(y),y.connect(g.destination)}e.addEventListener("playing",s),t.autoPlay&&(e.readyState===e.HAVE_ENOUGH_DATA?e.play():e.addEventListener("canplaythrough",u)),e.addEventListener("ended",c),this.stop=function(){e.pause(),c()},e.addEventListener("error",this.emit.bind(this,"error")),r.nextTick(function(){h.emit("format",{channels:1,bitDepth:32,sampleRate:g.sampleRate,signed:!0,float:!0})})}var o=e("stream").Readable,s=e("util"),a=e("defaults");s.inherits(i,o),i.prototype._read=function(){},i.toRaw=function(e){return new Float32Array(e.buffer)},t.exports=i}).call(this,e("_process"),e("buffer").Buffer)},{_process:11,buffer:3,defaults:30,stream:25,util:28}],51:[function(e,t,r){"use strict";var n=e("./media-element-audio-stream"),i=e("./webaudio-l16-stream"),o=e("./recognize-stream.js"),s=e("./format-stream.js"),a=e("object.assign/polyfill")(),u=e("./writable-element-stream");t.exports=function(e){if(!e||!e.token)throw new Error("WatsonSpeechToText: missing required parameter: opts.token");e.outputElement&&e.objectMode!==!1&&(e.objectMode=!0);var t=a({},e);t.readableObjectMode=e.objectMode,t["content-type"]="audio/l16;rate=16000",delete t.objectMode;var r=new o(t),c=new n(e.element,{objectMode:!0,bufferSize:e.bufferSize,muteSource:e.muteSource,autoPlay:e.autoPlay!==!1}),f=c.pipe(new i({writableObjectMode:!0})).pipe(r);return e.format!==!1&&(f=f.pipe(new s(e)),f.stop=r.stop.bind(r)),r.on("stop",c.stop.bind(c)),e.outputElement&&f.pipe(new u(e)),f}},{"./format-stream.js":47,"./media-element-audio-stream":50,"./recognize-stream.js":54,"./webaudio-l16-stream":57,"./writable-element-stream":58,"object.assign/polyfill":38}],52:[function(e,t,r){"use strict";var n=e("readable-blob-stream"),i=e("./recognize-stream.js"),o=e("./file-player.js"),s=e("./format-stream.js"),a=e("./timing-stream.js"),u=e("object.assign/polyfill")(),c=e("./writable-element-stream");t.exports=function(e){if(!e||!e.token)throw new Error("WatsonSpeechToText: missing required parameter: opts.token");e.outputElement&&e.objectMode!==!1&&(e.objectMode=!0);var t=e.realtime||"undefined"==typeof e.realtime&&e.play;t&&(e.timestamps=!0);var r=u({},e);r.readableObjectMode=e.objectMode||t,delete r.objectMode;var f=new i(r),l=new n(e.data).pipe(f);return e.format!==!1&&(l=l.pipe(new s(e))),t&&(l=l.pipe(new a(e))),l.stop=f.stop.bind(f),e.play&&o.playFile(e.data).then(function(e){f.on("stop",e.stop.bind(e))}).catch(function(e){l.emit("playback-error",e)}),e.outputElement&&l.pipe(new c(e)),l}},{"./file-player.js":46,"./format-stream.js":47,"./recognize-stream.js":54,"./timing-stream.js":55,"./writable-element-stream":58,"object.assign/polyfill":38,"readable-blob-stream":40}],53:[function(e,t,r){"use strict";var n,i=e("./getusermedia"),o=e("microphone-stream"),s=e("./recognize-stream.js"),a=e("./webaudio-l16-stream.js"),u=e("./format-stream.js"),c=e("object.assign/polyfill")(),f=e("./writable-element-stream"),l=e("stream").Readable,h=new l;t.exports=function(e){if(!e||!e.token)throw new Error("WatsonSpeechToText: missing required parameter: opts.token");e.outputElement&&e.objectMode!==!1&&(e.objectMode=!0);var t=c({},e);t.readableObjectMode=e.objectMode,t["content-type"]="audio/l16;rate=16000",delete t.objectMode;var r,l=new s(t),p=e.keepMicrophone;p&&n?(n.unpipe(h),r=Promise.resolve(n)):r=i({video:!1,audio:!0}).then(function(t){var r=new o(t,{objectMode:!0,bufferSize:e.bufferSize});return p&&(n=r),Promise.resolve(r)}),r.then(function(e){function t(){e.unpipe(r),e.pipe(h),r.end()}var r=new a({writableObjectMode:!0});e.pipe(r).pipe(l),p?(l.on("end",t),l.on("stop",t)):(l.on("end",e.stop.bind(e)),l.on("stop",e.stop.bind(e)))}).catch(l.emit.bind(l,"error"));var d=l;return e.format!==!1&&(d=d.pipe(new u(e)),d.stop=l.stop.bind(l)),e.outputElement&&d.pipe(new f(e)),d}},{"./format-stream.js":47,"./getusermedia":48,"./recognize-stream.js":54,"./webaudio-l16-stream.js":57,"./writable-element-stream":58,"microphone-stream":31,"object.assign/polyfill":38,stream:25}],54:[function(e,t,r){(function(r){"use strict";function n(e){function t(i){("results"==i||"result"==i)&&(n.removeListener("newListener",t),r.nextTick(function(){n.on("data",function(){})}),e.silent||console.log(new Error("Watson Speech to Text RecognizeStream: the "+i+" event is deprecated and will be removed from a future release. Please set {objectMode: true} and listen for the data event instead. Pass {silent: true} to disable this message.")))}i.call(this,e),this.options=e,this.listening=!1,this.initialized=!1,this.finished=!1;var n=this;this.on("newListener",t)}var i=e("stream").Duplex,o=e("util"),s=e("object.pick"),a=e("websocket").w3cwebsocket,u=e("./content-type"),c=e("defaults"),f=e("../util/querystring.js"),l=["continuous","max_alternatives","timestamps","word_confidence","inactivity_timeout","content-type","interim_results","keywords","keywords_threshold","word_alternatives_threshold"],h=["model","watson-token"];o.inherits(n,i),n.prototype.initialize=function(){function e(e,t,r){r?r.message=e+" "+r.message:r=new Error(e),r.raw=t,g.emit("error",r)}var t=this.options;t.token&&!t["watson-token"]&&(t["watson-token"]=t.token),t.content_type&&!t["content-type"]&&(t["content-type"]=t.content_type),t["X-WDC-PL-OPT-OUT"]&&!t["X-Watson-Learning-Opt-Out"]&&(t["X-Watson-Learning-Opt-Out"]=t["X-WDC-PL-OPT-OUT"]);var r=o._extend({model:"en-US_BroadbandModel"},s(t,h)),n=f.stringify(r),i=(t.url||"wss://stream.watsonplatform.net/speech-to-text/api").replace(/^http/,"ws")+"/v1/recognize?"+n,u={action:"start","content-type":"audio/wav",continuous:!0,inactivity_timeout:30,interim_results:!1,word_confidence:!1,timestamps:!1,max_alternatives:1},p={action:"start","content-type":"audio/wav",continuous:!0,inactivity_timeout:30,interim_results:!0,word_confidence:!1,timestamps:!1,max_alternatives:1},d=c(s(t,l),t.objectMode||t.readableObjectMode?p:u),g=this,m=this.socket=new a(i,null,null,t.headers,null);g.on("finish",g.finish.bind(g)),m.onerror=function(e){g.listening=!1,g.emit("error",e)},this.socket.onopen=function(){g.sendJSON(d),g.emit("connect")},this.socket.onclose=function(e){g.listening&&(g.listening=!1,g.push(null)),g.emit("close",e.code,e.reason),g.emit("connection-close",e.code,e.reason)},m.onmessage=function(r){if("string"!=typeof r.data)return e("Unexpected binary data received from server",r);var n;try{n=JSON.parse(r.data)}catch(t){return e("Invalid JSON received from service:",r,t)}g.emit("message",n),n.error?e(n.error,r):"listening"===n.state?g.listening?(g.listening=!1,g.push(null),m.close()):(g.listening=!0,g.emit("listening")):n.results?(g.emit("results",n.results),n.results.forEach(function(e){e.index=n.result_index,g.emit("result",e),t.objectMode||t.readableObjectMode?g.push(e):e.final&&e.alternatives&&g.push(e.alternatives[0].transcript,"utf8")})):e("Unrecognised message from server",r)},this.initialized=!0},n.prototype.sendJSON=function(e){return this.emit("send-json",e),this.socket.send(JSON.stringify(e))},n.prototype.sendData=function(e){return this.emit("send-data",e),this.socket.send(e)},n.prototype._read=function(e){},n.prototype._write=function(e,t,r){var i=this;i.finished||(i.listening?(i.sendData(e),this.afterSend(r)):(this.initialized||(this.options["content-type"]||(this.options["content-type"]=n.getContentType(e)),this.initialize()),this.once("listening",function(){i.sendData(e),this.afterSend(r)})))},n.prototype.afterSend=function(e){this.socket.bufferedAmount<=this._writableState.highWaterMark?e():setTimeout(this.afterSend.bind(this,e),10)},n.prototype.stop=function(){this.emit("stop"),this.finish()},n.prototype.finish=function(){if(!this.finished){this.finished=!0;var e=this,t={action:"stop"};e.socket&&e.socket.readyState!==e.socket.CLOSED&&e.socket.readyState!==e.socket.CLOSING?e.sendJSON(t):this.once("connect",function(){e.sendJSON(t)})}},n.prototype.promise=e("./to-promise"),n.getContentType=function(e){return u(e.slice(0,4).toString())},t.exports=n}).call(this,e("_process"))},{"../util/querystring.js":62,"./content-type":45,"./to-promise":56,_process:11,defaults:30,"object.pick":39,stream:25,util:28,websocket:42}],55:[function(e,t,r){(function(r){"use strict";function n(e){this.options=u(e,{emitAt:n.START,delay:0,allowHalfOpen:!0,writableObjectMode:!0}),o.call(this,e),this.startTime=Date.now(),this.final=[],this.interim=[],this.nextTick=null,this.sourceEnded=!1;var t=this;this.on("pipe",function(e){e.on("end",function(){t.sourceEnded=!0})})}function i(e){var t=e.alternatives&&e.alternatives[0];return t&&t.transcript.trim()&&!t.timestamps||!t.timestamps.length}var o=e("stream").Duplex,s=e("util"),a=e("clone"),u=e("defaults");s.inherits(n,o),n.START=1,n.END=2,n.prototype._write=function(e,t,n){return e instanceof r?this.emit("error",new Error("TimingStream requires the source to be in objectMode")):(this.handleResult(e),void n())},n.prototype._read=function(e){},n.prototype.cutoff=function(){return(Date.now()-this.startTime)/1e3-this.options.delay},n.prototype.withinRange=function(e,t){return e.alternatives.some(function(e){var r=e.timestamps[0];return!!r&&r[this.options.emitAt]<=t},this)},n.prototype.completelyWithinRange=function(e,t){return e.alternatives.every(function(e){var r=e.timestamps[e.timestamps.length-1];return r[this.options.emitAt]<=t},this)},o.prototype.crop=function(e,t){return e=a(e),e.alternatives=e.alternatives.map(function(e){for(var r,n=[],i=0;ie)return this.nextTick=setTimeout(this.tick.bind(this),this.startTime+1e3*i)}throw new Error("No future words found")}this.sourceEnded&&(this.emit("close"),this.push(null))},n.prototype.handleResult=function(e){if(i(e))return this.emit("error",new Error("TimingStream requires timestamps"));for(e.alternatives.length>1&&(e.alternatives.length=1);this.interim.length&&this.interim[0].index<=e.index;)this.interim.shift();e.final?this.final.push(e):this.interim.push(e),this.tick()},n.prototype.promise=e("./to-promise"),t.exports=n}).call(this,e("buffer").Buffer)},{"./to-promise":56,buffer:3,clone:29,defaults:30,stream:25,util:28}],56:[function(e,t,r){(function(e){"use strict";t.exports=function(t){return t=t||this,new Promise(function(r,n){var i=[];t.on("data",function(e){i.push(e)}).on("end",function(){r(e.isBuffer(i[0])?e.concat(i).toString():i)}).on("error",n)})}}).call(this,e("buffer").Buffer)},{buffer:3}],57:[function(e,t,r){(function(r,n){"use strict";function i(e){e=this.options=a(e,{sourceSampleRate:48e3,downsample:!0}),o.call(this,e),this.bufferUnusedSamples=[],e.objectMode||e.writableObjectMode?this._transform=this.handleFirstAudioBuffer:(this._transform=this.transformBuffer,r.nextTick(this.emitFormat.bind(this)))}var o=e("stream").Transform,s=e("util"),a=e("defaults"),u=16e3;s.inherits(i,o),i.prototype.emitFormat=function(){this.emit("format",{channels:1,bitDepth:16,sampleRate:this.options.downsample?u:this.options.sourceSampleRate,signed:!0,float:!1})},i.prototype.downsample=function(e){var t=null,r=e.length,n=this.bufferUnusedSamples.length;if(n>0){t=new Float32Array(n+r);for(var i=0;n>i;++i)t[i]=this.bufferUnusedSamples[i];for(i=0;r>i;++i)t[n+i]=e[i]}else t=e;for(var o,s=[-.037935,-89024e-8,.040173,.019989,.0047792,-.058675,-.056487,-.0040653,.14527,.26927,.33913,.26927,.14527,-.0040653,-.056487,-.058675,.0047792,.019989,.040173,-89024e-8,-.037935],a=this.options.sourceSampleRate/u,c=Math.floor((t.length-s.length)/a)+1,f=new Float32Array(c),l=0;l+s.length-10)for(this.bufferUnusedSamples=new Float32Array(g),i=0;g>i;++i)this.bufferUnusedSamples[i]=t[d+i];else this.bufferUnusedSamples=new Float32Array(0);return f},i.prototype.floatTo16BitPCM=function(e){for(var t=new DataView(new ArrayBuffer(2*e.length)),r=0;r', + password: '' +}, vcapServices.getCredentials('speech_to_text')); + +console.log(process.env.VCAP_SERVICES); + +var sttAuthService = watson.authorization(sttConfig); + +router.get('/token', function(req, res) { + sttAuthService.getToken({url: sttConfig.url}, function(err, token) { + if (err) { + console.log('Error retrieving token: ', err); + return res.status(500).send('Error retrieving token') + } + res.send(token); + }); +}); + +module.exports = router; diff --git a/tts-token.js b/tts-token.js new file mode 100644 index 0000000..5de464d --- /dev/null +++ b/tts-token.js @@ -0,0 +1,31 @@ +'use strict'; + +var express = require('express'), + router = express.Router(), + vcapServices = require('vcap_services'), + extend = require('util')._extend, + watson = require('watson-developer-cloud'); + +// another endpoint for the text to speech service + +// For local development, replace username and password +var ttsConfig = extend({ + version: 'v1', + url: 'https://stream.watsonplatform.net/text-to-speech/api', + username: '', + password: '' +}, vcapServices.getCredentials('text_to_speech')); + +var ttsAuthService = watson.authorization(ttsConfig); + +router.get('/token', function(req, res) { + ttsAuthService.getToken({url: ttsConfig.url}, function(err, token) { + if (err) { + console.log('Error retrieving token: ', err); + return res.status(500).send('Error retrieving token') + } + res.send(token); + }); +}); + +module.exports = router;