edge-tts-node
Advanced tools
Comparing version 1.5.1 to 1.5.5
import { OUTPUT_FORMAT } from "./OUTPUT_FORMAT"; | ||
import { Readable } from "stream"; | ||
import { Agent } from "http"; | ||
import { PITCH } from "./PITCH"; | ||
@@ -17,19 +16,4 @@ import { RATE } from "./RATE"; | ||
export declare class ProsodyOptions { | ||
/** | ||
* The pitch to use. | ||
* Can be any {@link PITCH}, or a relative frequency in Hz (+50Hz), a relative semitone (+2st), or a relative percentage (+50%). | ||
* [SSML documentation](https://learn.microsoft.com/en-us/azure/ai-services/speech-service/speech-synthesis-markup-voice#:~:text=Optional-,pitch,-Indicates%20the%20baseline) | ||
*/ | ||
pitch?: PITCH | string; | ||
/** | ||
* The rate to use. | ||
* Can be any {@link RATE}, or a relative number (0.5), or string with a relative percentage (+50%). | ||
* [SSML documentation](https://learn.microsoft.com/en-us/azure/ai-services/speech-service/speech-synthesis-markup-voice#:~:text=Optional-,rate,-Indicates%20the%20speaking) | ||
*/ | ||
rate?: RATE | string | number; | ||
/** | ||
* The volume to use. | ||
* Can be any {@link VOLUME}, or an absolute number (0, 100), a string with a relative number (+50), or a relative percentage (+50%). | ||
* [SSML documentation](https://learn.microsoft.com/en-us/azure/ai-services/speech-service/speech-synthesis-markup-voice#:~:text=Optional-,volume,-Indicates%20the%20volume) | ||
*/ | ||
volume?: VOLUME | string | number; | ||
@@ -41,4 +25,2 @@ } | ||
static TRUSTED_CLIENT_TOKEN: string; | ||
private static VOICES_URL; | ||
private static SYNTH_URL; | ||
private static BINARY_DELIM; | ||
@@ -55,4 +37,7 @@ private static VOICE_LANG_REGEX; | ||
private readonly _agent; | ||
private _headers; | ||
private _arraybuffer; | ||
private state; | ||
private static getVoicesUrl; | ||
private static getSynthUrl; | ||
private _log; | ||
@@ -65,3 +50,7 @@ /** | ||
*/ | ||
constructor(agent?: Agent, enableLogger?: boolean); | ||
constructor({ agent, headers, enableLogger }: { | ||
agent?: any; | ||
headers?: any; | ||
enableLogger?: boolean; | ||
}); | ||
private _send; | ||
@@ -68,0 +57,0 @@ private _initClient; |
@@ -37,21 +37,8 @@ "use strict"; | ||
const fs = __importStar(require("fs")); | ||
const SecMSGec_1 = require("./SecMSGec"); | ||
const utils_1 = require("./utils"); | ||
const Headers_1 = require("./Headers"); | ||
class ProsodyOptions { | ||
/** | ||
* The pitch to use. | ||
* Can be any {@link PITCH}, or a relative frequency in Hz (+50Hz), a relative semitone (+2st), or a relative percentage (+50%). | ||
* [SSML documentation](https://learn.microsoft.com/en-us/azure/ai-services/speech-service/speech-synthesis-markup-voice#:~:text=Optional-,pitch,-Indicates%20the%20baseline) | ||
*/ | ||
pitch = "+0Hz"; | ||
/** | ||
* The rate to use. | ||
* Can be any {@link RATE}, or a relative number (0.5), or string with a relative percentage (+50%). | ||
* [SSML documentation](https://learn.microsoft.com/en-us/azure/ai-services/speech-service/speech-synthesis-markup-voice#:~:text=Optional-,rate,-Indicates%20the%20speaking) | ||
*/ | ||
rate = 1.0; | ||
/** | ||
* The volume to use. | ||
* Can be any {@link VOLUME}, or an absolute number (0, 100), a string with a relative number (+50), or a relative percentage (+50%). | ||
* [SSML documentation](https://learn.microsoft.com/en-us/azure/ai-services/speech-service/speech-synthesis-markup-voice#:~:text=Optional-,volume,-Indicates%20the%20volume) | ||
*/ | ||
volume = 100.0; | ||
@@ -64,4 +51,2 @@ } | ||
static TRUSTED_CLIENT_TOKEN = "6A5AA1D4EAFF4E9FB37E23D68491D6F4"; | ||
static VOICES_URL = `https://speech.platform.bing.com/consumer/speech/synthesize/readaloud/voices/list?trustedclienttoken=${MsEdgeTTS.TRUSTED_CLIENT_TOKEN}`; | ||
static SYNTH_URL = `wss://speech.platform.bing.com/consumer/speech/synthesize/readaloud/edge/v1?TrustedClientToken=${MsEdgeTTS.TRUSTED_CLIENT_TOKEN}`; | ||
static BINARY_DELIM = "Path:audio\r\n"; | ||
@@ -78,2 +63,3 @@ static VOICE_LANG_REGEX = /\w{2}-\w{2}/; | ||
_agent; | ||
_headers = null; | ||
_arraybuffer = false; | ||
@@ -84,2 +70,10 @@ state = { | ||
}; | ||
static getVoicesUrl() { | ||
const param = (0, SecMSGec_1.generateSecMSGecParam)(); | ||
return `https://speech.platform.bing.com/consumer/speech/synthesize/readaloud/voices/list?trustedclienttoken=${MsEdgeTTS.TRUSTED_CLIENT_TOKEN}${param}`; | ||
} | ||
static getSynthUrl() { | ||
const param = (0, SecMSGec_1.generateSecMSGecParam)(); | ||
return `wss://speech.platform.bing.com/consumer/speech/synthesize/readaloud/edge/v1?TrustedClientToken=${MsEdgeTTS.TRUSTED_CLIENT_TOKEN}${param}`; | ||
} | ||
_log(...o) { | ||
@@ -97,4 +91,7 @@ if (this._enableLogger) { | ||
*/ | ||
constructor(agent, enableLogger = false) { | ||
constructor({ agent = undefined, headers = null, enableLogger = false }) { | ||
this._agent = agent; | ||
this._headers = headers || { | ||
headers: Headers_1.WSS_HEADERS | ||
}; | ||
this._enableLogger = enableLogger; | ||
@@ -117,4 +114,4 @@ this._isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined"; | ||
this._ws = this._isBrowser | ||
? new isomorphic_ws_1.default(MsEdgeTTS.SYNTH_URL) | ||
: new isomorphic_ws_1.default(MsEdgeTTS.SYNTH_URL, { agent: this._agent }); | ||
? new isomorphic_ws_1.default(MsEdgeTTS.getSynthUrl()) | ||
: new isomorphic_ws_1.default(MsEdgeTTS.getSynthUrl(), { agent: this._agent, ...this._headers }); | ||
if (this._arraybuffer) | ||
@@ -225,4 +222,17 @@ this._ws.binaryType = "arraybuffer"; | ||
}; | ||
this._ws.onerror = function (error) { | ||
reject("Connect Error: " + error); | ||
this._ws.onerror = (error) => { | ||
this._log(error); | ||
let errorMessage; | ||
if (typeof error === "object" && error !== null) { | ||
try { | ||
errorMessage = JSON.stringify(error); | ||
} | ||
catch (e) { | ||
errorMessage = error + ""; | ||
} | ||
} | ||
else { | ||
errorMessage = error + ""; | ||
} | ||
reject("Connect Error: " + errorMessage); | ||
}; | ||
@@ -254,3 +264,3 @@ }); | ||
return new Promise((resolve, reject) => { | ||
axios_1.default.get(MsEdgeTTS.VOICES_URL) | ||
axios_1.default.get(MsEdgeTTS.getVoicesUrl()) | ||
.then((res) => resolve(res.data)) | ||
@@ -257,0 +267,0 @@ .catch(reject); |
{ | ||
"name": "edge-tts-node", | ||
"version": "1.5.1", | ||
"version": "1.5.5", | ||
"description": "An Azure Speech Service module that uses the Microsoft Edge Read Aloud API.", | ||
@@ -5,0 +5,0 @@ "author": "Migushthe2nd <Migushthe2nd@users.noreply.github.com>", |
36637
21
708