@bestcodes/edge-tts 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ # :warning: This project is non-functional as it is under development. Do NOT use it.
2
+
1
3
  # @bestcodes/edge-tts
2
4
 
3
5
  [![npm version](https://badge.fury.io/js/%40bestcodes%2Fedge-tts.svg)](https://badge.fury.io/js/%40bestcodes%2Fedge-tts)
package/dist/MsEdgeTTS.js CHANGED
@@ -1 +1 @@
1
- "use strict";var __assign=this&&this.__assign||function(){return __assign=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var a in e=arguments[n])Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a]);return t},__assign.apply(this,arguments)},__createBinding=this&&this.__createBinding||(Object.create?function(t,e,n,o){void 0===o&&(o=n);var a=Object.getOwnPropertyDescriptor(e,n);a&&!("get"in a?!e.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,o,a)}:function(t,e,n,o){void 0===o&&(o=n),t[o]=e[n]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),__importStar=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)"default"!==n&&Object.prototype.hasOwnProperty.call(t,n)&&__createBinding(e,t,n);return __setModuleDefault(e,t),e},__awaiter=this&&this.__awaiter||function(t,e,n,o){return new(n||(n=Promise))((function(a,r){function s(t){try{c(o.next(t))}catch(t){r(t)}}function i(t){try{c(o.throw(t))}catch(t){r(t)}}function c(t){var e;t.done?a(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,i)}c((o=o.apply(t,e||[])).next())}))},__generator=this&&this.__generator||function(t,e){var n,o,a,r,s={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return r={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function i(i){return function(c){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;r&&(r=0,i[0]&&(s=0)),s;)try{if(n=1,o&&(a=2&i[0]?o.return:i[0]?o.throw||((a=o.return)&&a.call(o),0):o.next)&&!(a=a.call(o,i[1])).done)return a;switch(o=0,a&&(i=[2&i[0],a.value]),i[0]){case 0:case 1:a=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,o=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(a=s.trys,(a=a.length>0&&a[a.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!a||i[1]>a[0]&&i[1]<a[3])){s.label=i[1];break}if(6===i[0]&&s.label<a[1]){s.label=a[1],a=i;break}if(a&&s.label<a[2]){s.label=a[2],s.ops.push(i);break}a[2]&&s.ops.pop(),s.trys.pop();continue}i=e.call(t,s)}catch(t){i=[6,t],o=0}finally{n=a=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}},__importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.MsEdgeTTS=exports.MetadataOptions=exports.ProsodyOptions=void 0;var axios_1=__importDefault(require("axios")),isomorphic_ws_1=__importDefault(require("isomorphic-ws")),buffer_1=require("buffer/"),randombytes_1=__importDefault(require("randombytes")),OUTPUT_FORMAT_1=require("./OUTPUT_FORMAT"),stream_1=require("stream"),fs=__importStar(require("fs")),ProsodyOptions=function(){this.pitch="+0Hz",this.rate=1,this.volume=100};exports.ProsodyOptions=ProsodyOptions;var messageTypes,MetadataOptions=function(){this.sentenceBoundaryEnabled=!1,this.wordBoundaryEnabled=!1};exports.MetadataOptions=MetadataOptions,function(t){t.TURN_START="turn.start",t.TURN_END="turn.end",t.RESPONSE="response",t.SPEECH_CONFIG="speech.config",t.AUDIO_METADATA="audio.metadata",t.AUDIO="audio",t.SSML="ssml"}(messageTypes||(messageTypes={}));var MsEdgeTTS=function(){function t(t,e){void 0===e&&(e=!1),this._metadataOptions=new MetadataOptions,this._streams={},this._startTime=0,this._agent=t,this._enableLogger=e,this._isBrowser="undefined"!=typeof window&&void 0!==window.document}return t.prototype._log=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this._enableLogger&&console.log.apply(console,t)},t.prototype._send=function(t){return __awaiter(this,void 0,void 0,(function(){var e,n=this;return __generator(this,(function(o){switch(o.label){case 0:e=1,o.label=1;case 1:return e<=3&&this._ws.readyState!==this._ws.OPEN?(1==e&&(this._startTime=Date.now()),this._log("connecting: ",e),[4,this._initClient()]):[3,4];case 2:o.sent(),o.label=3;case 3:return e++,[3,1];case 4:return this._ws.send(t,(function(){n._log("<-",t)})),[2]}}))}))},t.prototype._initClient=function(){var e=this;return this._ws=this._isBrowser?new isomorphic_ws_1.default(t.SYNTH_URL):new isomorphic_ws_1.default(t.SYNTH_URL,{agent:this._agent}),this._ws.binaryType="arraybuffer",new Promise((function(n,o){e._ws.onopen=function(){e._log("Connected in",(Date.now()-e._startTime)/1e3,"seconds"),e._send("Content-Type:application/json; charset=utf-8\r\nPath:".concat(messageTypes.SPEECH_CONFIG).concat(t.JSON_XML_DELIM,'\n {\n "context": {\n "synthesis": {\n "audio": {\n "metadataoptions": {\n "sentenceBoundaryEnabled": "').concat(e._metadataOptions.sentenceBoundaryEnabled,'",\n "wordBoundaryEnabled": "').concat(e._metadataOptions.wordBoundaryEnabled,'"\n },\n "outputFormat": "').concat(e._outputFormat,'" \n }\n }\n }\n }\n ')).then(n)},e._ws.onmessage=function(n){var o,a=buffer_1.Buffer.from(n.data),r=a.toString(),s=(null===(o=/X-RequestId:(.*?)\r\n/gm.exec(r))||void 0===o?void 0:o[1])||"";if(r.includes("Path:".concat(messageTypes.TURN_START)))e._log("->",r);else if(r.includes("Path:".concat(messageTypes.TURN_END)))e._log("->",r),e._streams[s].audio.push(null);else if(r.includes("Path:".concat(messageTypes.RESPONSE)))e._log("->",r);else if(r.includes("Path:".concat(messageTypes.AUDIO_METADATA))){var i=a.indexOf(t.JSON_XML_DELIM)+t.JSON_XML_DELIM.length,c=a.subarray(i);e._log("->",r),e._pushMetadata(c,s)}else if(r.includes("Path:".concat(messageTypes.AUDIO))&&n.data instanceof ArrayBuffer){i=a.indexOf(t.AUDIO_DELIM)+t.AUDIO_DELIM.length;var u=a.subarray(0,i).toString();c=a.subarray(i);e._log("->",u),e._pushAudioData(c,s)}else e._log("->","UNKNOWN MESSAGE",r)},e._ws.onclose=function(){for(var t in e._log("disconnected after:",(Date.now()-e._startTime)/1e3,"seconds"),e._streams)e._streams[t].audio.push(null)},e._ws.onerror=function(t){o("Connect Error: "+JSON.stringify(t,null,2))}}))},t.prototype._pushAudioData=function(t,e){this._streams[e].audio.push(t)},t.prototype._pushMetadata=function(t,e){this._streams[e].metadata.push(t)},t.prototype._SSMLTemplate=function(t,e){return void 0===e&&(e={}),e=__assign(__assign({},new ProsodyOptions),e),'<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="https://www.w3.org/2001/mstts" xml:lang="'.concat(this._metadataOptions.voiceLocale,'">\n <voice name="').concat(this._voice,'">\n <prosody pitch="').concat(e.pitch,'" rate="').concat(e.rate,'" volume="').concat(e.volume,'">\n ').concat(t,"\n </prosody> \n </voice>\n </speak>")},t.prototype.getVoices=function(){return new Promise((function(e,n){axios_1.default.get(t.VOICES_URL).then((function(t){return e(t.data)})).catch(n)}))},t.prototype.setMetadata=function(e,n,o){return __awaiter(this,void 0,void 0,(function(){var a,r,s,i;return __generator(this,(function(c){switch(c.label){case 0:if(a=this._voice,r=this._outputFormat,s=JSON.stringify(this._metadataOptions),this._voice=e,!this._metadataOptions.voiceLocale||o&&!o.voiceLocale&&a!==this._voice){if(!(i=t.VOICE_LANG_REGEX.exec(this._voice)))throw new Error("Could not infer voiceLocale from voiceName, and no voiceLocale was specified!");this._metadataOptions.voiceLocale=i[0]}return this._outputFormat=n,Object.assign(this._metadataOptions,o),a!==this._voice||r!==this._outputFormat||s!==JSON.stringify(this._metadataOptions)||this._ws.readyState!==this._ws.OPEN?(this._startTime=Date.now(),[4,this._initClient()]):[2];case 1:return c.sent(),[2]}}))}))},t.prototype._metadataCheck=function(){if(!this._ws)throw new Error("Speech synthesis not configured yet. Run setMetadata before calling toStream or toFile.")},t.prototype.close=function(){this._ws.close()},t.prototype.toFile=function(t,e,n){return this._rawSSMLRequestToFile(t,this._SSMLTemplate(e,n))},t.prototype.toStream=function(t,e){return this._rawSSMLRequest(this._SSMLTemplate(t,e)).audioStream},t.prototype.rawToFile=function(t,e){return this._rawSSMLRequestToFile(t,e)},t.prototype.rawToStream=function(t){return this._rawSSMLRequest(t).audioStream},t.prototype._rawSSMLRequestToFile=function(t,e){return __awaiter(this,void 0,void 0,(function(){var n,o,a,r,s,i,c,u=this;return __generator(this,(function(_){switch(_.label){case 0:n=this._rawSSMLRequest(e),o=n.audioStream,a=n.metadataStream,n.requestId,_.label=1;case 1:return _.trys.push([1,3,,4]),[4,Promise.all([new Promise((function(e,n){var r=o.pipe(fs.createWriteStream(t+"/example_audio.webm"));r.once("close",(function(){return __awaiter(u,void 0,void 0,(function(){return __generator(this,(function(o){return r.bytesWritten>0?e(t+"/example_audio.webm"):n("No audio data received"),[2]}))}))})),a.once("error",n)})),new Promise((function(e,n){var o=[];a.on("data",(function(t){var e=JSON.parse(t.toString());o.push.apply(o,e.Metadata)})),a.on("close",(function(){var n=t+"/example_metadata.json";fs.writeFileSync(n,JSON.stringify(o,null,2)),e(n)})),a.once("error",n)}))])];case 2:return r=_.sent(),s=r[0],i=r[1],[2,{audioFilePath:s,metadataFilePath:i}];case 3:throw c=_.sent(),o.destroy(),a.destroy(),c;case 4:return[2]}}))}))},t.prototype._rawSSMLRequest=function(e){this._metadataCheck();var n=(0,randombytes_1.default)(16).toString("hex"),o="X-RequestId:".concat(n,"\r\nContent-Type:application/ssml+xml\r\nPath:").concat(messageTypes.SSML).concat(t.JSON_XML_DELIM)+e.trim(),a=this,r=new stream_1.Readable({read:function(){},destroy:function(t,e){delete a._streams[n],e(t)}}),s=new stream_1.Readable({read:function(){}});return r.on("error",(function(t){r.destroy(),s.destroy()})),r.once("close",(function(){r.destroy(),s.destroy()})),this._streams[n]={audio:r,metadata:s},this._send(o).then(),{audioStream:r,metadataStream:s,requestId:n}},t.OUTPUT_FORMAT=OUTPUT_FORMAT_1.OUTPUT_FORMAT,t.TRUSTED_CLIENT_TOKEN="6A5AA1D4EAFF4E9FB37E23D68491D6F4",t.VOICES_URL="https://speech.platform.bing.com/consumer/speech/synthesize/readaloud/voices/list?trustedclienttoken=".concat(t.TRUSTED_CLIENT_TOKEN),t.SYNTH_URL="wss://speech.platform.bing.com/consumer/speech/synthesize/readaloud/edge/v1?TrustedClientToken=".concat(t.TRUSTED_CLIENT_TOKEN),t.JSON_XML_DELIM="\r\n\r\n",t.AUDIO_DELIM="Path:audio\r\n",t.VOICE_LANG_REGEX=/\w{2}-\w{2}/,t}();exports.MsEdgeTTS=MsEdgeTTS;
1
+ "use strict";var __assign=this&&this.__assign||function(){return __assign=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var a in e=arguments[n])Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a]);return t},__assign.apply(this,arguments)},__createBinding=this&&this.__createBinding||(Object.create?function(t,e,n,o){void 0===o&&(o=n);var a=Object.getOwnPropertyDescriptor(e,n);a&&!("get"in a?!e.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,o,a)}:function(t,e,n,o){void 0===o&&(o=n),t[o]=e[n]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),__importStar=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)"default"!==n&&Object.prototype.hasOwnProperty.call(t,n)&&__createBinding(e,t,n);return __setModuleDefault(e,t),e},__awaiter=this&&this.__awaiter||function(t,e,n,o){return new(n||(n=Promise))((function(a,r){function s(t){try{c(o.next(t))}catch(t){r(t)}}function i(t){try{c(o.throw(t))}catch(t){r(t)}}function c(t){var e;t.done?a(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,i)}c((o=o.apply(t,e||[])).next())}))},__generator=this&&this.__generator||function(t,e){var n,o,a,r={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=i(0),s.throw=i(1),s.return=i(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function i(i){return function(c){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,i[0]&&(r=0)),r;)try{if(n=1,o&&(a=2&i[0]?o.return:i[0]?o.throw||((a=o.return)&&a.call(o),0):o.next)&&!(a=a.call(o,i[1])).done)return a;switch(o=0,a&&(i=[2&i[0],a.value]),i[0]){case 0:case 1:a=i;break;case 4:return r.label++,{value:i[1],done:!1};case 5:r.label++,o=i[1],i=[0];continue;case 7:i=r.ops.pop(),r.trys.pop();continue;default:if(!(a=r.trys,(a=a.length>0&&a[a.length-1])||6!==i[0]&&2!==i[0])){r=0;continue}if(3===i[0]&&(!a||i[1]>a[0]&&i[1]<a[3])){r.label=i[1];break}if(6===i[0]&&r.label<a[1]){r.label=a[1],a=i;break}if(a&&r.label<a[2]){r.label=a[2],r.ops.push(i);break}a[2]&&r.ops.pop(),r.trys.pop();continue}i=e.call(t,r)}catch(t){i=[6,t],o=0}finally{n=a=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}},__importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.MsEdgeTTS=exports.MetadataOptions=exports.ProsodyOptions=void 0;var axios_1=__importDefault(require("axios")),isomorphic_ws_1=__importDefault(require("isomorphic-ws")),buffer_1=require("buffer/"),randombytes_1=__importDefault(require("randombytes")),OUTPUT_FORMAT_1=require("./OUTPUT_FORMAT"),stream_1=require("stream"),fs=__importStar(require("fs")),ProsodyOptions=function(){this.pitch="+0Hz",this.rate=1,this.volume=100};exports.ProsodyOptions=ProsodyOptions;var messageTypes,MetadataOptions=function(){this.sentenceBoundaryEnabled=!1,this.wordBoundaryEnabled=!1};exports.MetadataOptions=MetadataOptions,function(t){t.TURN_START="turn.start",t.TURN_END="turn.end",t.RESPONSE="response",t.SPEECH_CONFIG="speech.config",t.AUDIO_METADATA="audio.metadata",t.AUDIO="audio",t.SSML="ssml"}(messageTypes||(messageTypes={}));var MsEdgeTTS=function(){function t(t,e){void 0===e&&(e=!1),this._metadataOptions=new MetadataOptions,this._streams={},this._startTime=0,this._agent=t,this._enableLogger=e,this._isBrowser="undefined"!=typeof window&&void 0!==window.document}return t.prototype._log=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this._enableLogger&&console.log.apply(console,t)},t.prototype._send=function(t){return __awaiter(this,void 0,void 0,(function(){var e,n=this;return __generator(this,(function(o){switch(o.label){case 0:e=1,o.label=1;case 1:return e<=3&&this._ws.readyState!==this._ws.OPEN?(1==e&&(this._startTime=Date.now()),this._log("connecting: ",e),[4,this._initClient()]):[3,4];case 2:o.sent(),o.label=3;case 3:return e++,[3,1];case 4:return this._ws.send(t,(function(){n._log("<-",t)})),[2]}}))}))},t.prototype._initClient=function(){var e=this;return this._ws=this._isBrowser?new isomorphic_ws_1.default(t.SYNTH_URL):new isomorphic_ws_1.default(t.SYNTH_URL,{agent:this._agent}),this._ws.binaryType="arraybuffer",new Promise((function(n,o){e._ws.onopen=function(){e._log("Connected in",(Date.now()-e._startTime)/1e3,"seconds"),e._send("Content-Type:application/json; charset=utf-8\r\nPath:".concat(messageTypes.SPEECH_CONFIG).concat(t.JSON_XML_DELIM,'\n {\n "context": {\n "synthesis": {\n "audio": {\n "metadataoptions": {\n "sentenceBoundaryEnabled": "').concat(e._metadataOptions.sentenceBoundaryEnabled,'",\n "wordBoundaryEnabled": "').concat(e._metadataOptions.wordBoundaryEnabled,'"\n },\n "outputFormat": "').concat(e._outputFormat,'" \n }\n }\n }\n }\n ')).then(n)},e._ws.onmessage=function(n){var o,a=buffer_1.Buffer.from(n.data),r=a.toString(),s=(null===(o=/X-RequestId:(.*?)\r\n/gm.exec(r))||void 0===o?void 0:o[1])||"";if(r.includes("Path:".concat(messageTypes.TURN_START)))e._log("->",r);else if(r.includes("Path:".concat(messageTypes.TURN_END)))e._log("->",r),e._streams[s].audio.push(null);else if(r.includes("Path:".concat(messageTypes.RESPONSE)))e._log("->",r);else if(r.includes("Path:".concat(messageTypes.AUDIO_METADATA))){var i=a.indexOf(t.JSON_XML_DELIM)+t.JSON_XML_DELIM.length,c=a.subarray(i);e._log("->",r),e._pushMetadata(c,s)}else if(r.includes("Path:".concat(messageTypes.AUDIO))&&n.data instanceof ArrayBuffer){i=a.indexOf(t.AUDIO_DELIM)+t.AUDIO_DELIM.length;var u=a.subarray(0,i).toString();c=a.subarray(i);e._log("->",u),e._pushAudioData(c,s)}else e._log("->","UNKNOWN MESSAGE",r)},e._ws.onclose=function(){for(var t in e._log("disconnected after:",(Date.now()-e._startTime)/1e3,"seconds"),e._streams)e._streams[t].audio.push(null)},e._ws.onerror=function(t){o("Connect Error: "+JSON.stringify(t,null,2))}}))},t.prototype._pushAudioData=function(t,e){this._streams[e].audio.push(t)},t.prototype._pushMetadata=function(t,e){this._streams[e].metadata.push(t)},t.prototype._SSMLTemplate=function(t,e){return void 0===e&&(e={}),e=__assign(__assign({},new ProsodyOptions),e),'<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="https://www.w3.org/2001/mstts" xml:lang="'.concat(this._metadataOptions.voiceLocale,'">\n <voice name="').concat(this._voice,'">\n <prosody pitch="').concat(e.pitch,'" rate="').concat(e.rate,'" volume="').concat(e.volume,'">\n ').concat(t,"\n </prosody> \n </voice>\n </speak>")},t.prototype.getVoices=function(){return new Promise((function(e,n){axios_1.default.get(t.VOICES_URL).then((function(t){return e(t.data)})).catch(n)}))},t.prototype.setMetadata=function(e,n,o){return __awaiter(this,void 0,void 0,(function(){var a,r,s,i;return __generator(this,(function(c){switch(c.label){case 0:if(a=this._voice,r=this._outputFormat,s=JSON.stringify(this._metadataOptions),this._voice=e,!this._metadataOptions.voiceLocale||o&&!o.voiceLocale&&a!==this._voice){if(!(i=t.VOICE_LANG_REGEX.exec(this._voice)))throw new Error("Could not infer voiceLocale from voiceName, and no voiceLocale was specified!");this._metadataOptions.voiceLocale=i[0]}return this._outputFormat=n,Object.assign(this._metadataOptions,o),a!==this._voice||r!==this._outputFormat||s!==JSON.stringify(this._metadataOptions)||this._ws.readyState!==this._ws.OPEN?(this._startTime=Date.now(),[4,this._initClient()]):[2];case 1:return c.sent(),[2]}}))}))},t.prototype._metadataCheck=function(){if(!this._ws)throw new Error("Speech synthesis not configured yet. Run setMetadata before calling toStream or toFile.")},t.prototype.close=function(){this._ws.close()},t.prototype.toFile=function(t,e,n){return this._rawSSMLRequestToFile(t,this._SSMLTemplate(e,n))},t.prototype.toStream=function(t,e){return this._rawSSMLRequest(this._SSMLTemplate(t,e)).audioStream},t.prototype.rawToFile=function(t,e){return this._rawSSMLRequestToFile(t,e)},t.prototype.rawToStream=function(t){return this._rawSSMLRequest(t).audioStream},t.prototype._rawSSMLRequestToFile=function(t,e){return __awaiter(this,void 0,void 0,(function(){var n,o,a,r,s,i,c,u=this;return __generator(this,(function(_){switch(_.label){case 0:n=this._rawSSMLRequest(e),o=n.audioStream,a=n.metadataStream,n.requestId,_.label=1;case 1:return _.trys.push([1,3,,4]),[4,Promise.all([new Promise((function(e,n){var r=o.pipe(fs.createWriteStream(t+"/example_audio.webm"));r.once("close",(function(){return __awaiter(u,void 0,void 0,(function(){return __generator(this,(function(o){return r.bytesWritten>0?e(t+"/example_audio.webm"):n("No audio data received"),[2]}))}))})),a.once("error",n)})),new Promise((function(e,n){var o=[];a.on("data",(function(t){var e=JSON.parse(t.toString());o.push.apply(o,e.Metadata)})),a.on("close",(function(){var n=t+"/example_metadata.json";fs.writeFileSync(n,JSON.stringify(o,null,2)),e(n)})),a.once("error",n)}))])];case 2:return r=_.sent(),s=r[0],i=r[1],[2,{audioFilePath:s,metadataFilePath:i}];case 3:throw c=_.sent(),o.destroy(),a.destroy(),c;case 4:return[2]}}))}))},t.prototype._rawSSMLRequest=function(e){this._metadataCheck();var n=(0,randombytes_1.default)(16).toString("hex"),o="X-RequestId:".concat(n,"\r\nContent-Type:application/ssml+xml\r\nPath:").concat(messageTypes.SSML).concat(t.JSON_XML_DELIM)+e.trim(),a=this,r=new stream_1.Readable({read:function(){},destroy:function(t,e){delete a._streams[n],e(t)}}),s=new stream_1.Readable({read:function(){}});return r.on("error",(function(t){r.destroy(),s.destroy()})),r.once("close",(function(){r.destroy(),s.destroy()})),this._streams[n]={audio:r,metadata:s},this._send(o).then(),{audioStream:r,metadataStream:s,requestId:n}},t.OUTPUT_FORMAT=OUTPUT_FORMAT_1.OUTPUT_FORMAT,t.TRUSTED_CLIENT_TOKEN="6A5AA1D4EAFF4E9FB37E23D68491D6F4",t.VOICES_URL="https://speech.platform.bing.com/consumer/speech/synthesize/readaloud/voices/list?trustedclienttoken=".concat(t.TRUSTED_CLIENT_TOKEN),t.SYNTH_URL="wss://speech.platform.bing.com/consumer/speech/synthesize/readaloud/edge/v1?TrustedClientToken=".concat(t.TRUSTED_CLIENT_TOKEN),t.JSON_XML_DELIM="\r\n\r\n",t.AUDIO_DELIM="Path:audio\r\n",t.VOICE_LANG_REGEX=/\w{2}-\w{2}/,t}();exports.MsEdgeTTS=MsEdgeTTS;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bestcodes/edge-tts",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "An Azure Speech Service module that uses the Microsoft Edge Read Aloud API.",
5
5
  "author": "The-Best-Codes",
6
6
  "license": "MIT",