@andresaya/edge-tts 1.6.0 → 1.6.2
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 +72 -1
- package/dist/browser/edge-tts.esm.js +185 -11
- package/dist/browser/edge-tts.esm.js.map +2 -2
- package/dist/browser/edge-tts.esm.min.js +13 -7
- package/dist/browser/edge-tts.esm.min.js.map +3 -3
- package/dist/browser/edge-tts.umd.js +187 -12
- package/dist/browser/edge-tts.umd.js.map +2 -2
- package/dist/browser/edge-tts.umd.min.js +14 -7
- package/dist/browser/edge-tts.umd.min.js.map +3 -3
- package/dist/cli/edge-tts.js +1 -1
- package/dist/services/EdgeTTS.js +40 -16
- package/package.json +1 -1
package/dist/services/EdgeTTS.js
CHANGED
|
@@ -114,19 +114,25 @@ class EdgeTTS {
|
|
|
114
114
|
this.audio_stream = [];
|
|
115
115
|
const reqId = this.generateUUID();
|
|
116
116
|
const url = `${constants_1.Constants.WSS_URL}?Ocp-Apim-Subscription-Key=${constants_1.Constants.TRUSTED_CLIENT_TOKEN}&Sec-MS-GEC=${secMsGEC}&Sec-MS-GEC-Version=${constants_1.Constants.VERSION_MS_GEC}&ConnectionId=${reqId}`;
|
|
117
|
-
console.log('WebSocket URL:', url);
|
|
118
117
|
this.ws = new ws_1.default(url, {
|
|
119
118
|
headers: constants_1.Constants.getBaseHeaders(),
|
|
120
119
|
rejectUnauthorized: false
|
|
121
120
|
});
|
|
122
121
|
const SSML_text = this.getSSML(text, voice, options);
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
122
|
+
let timedOut = false;
|
|
123
|
+
let inactivityTimeout;
|
|
124
|
+
const resetInactivityTimeout = () => {
|
|
125
|
+
clearTimeout(inactivityTimeout);
|
|
126
|
+
inactivityTimeout = setTimeout(() => {
|
|
127
|
+
timedOut = true;
|
|
128
|
+
if (this.ws && this.ws.readyState === ws_1.default.OPEN) {
|
|
129
|
+
this.ws.close();
|
|
130
|
+
}
|
|
131
|
+
reject(new Error("WebSocket inactivity timeout - no response from server"));
|
|
132
|
+
}, 30000); // 30 seconds of inactivity
|
|
133
|
+
};
|
|
129
134
|
this.ws.on('open', () => {
|
|
135
|
+
resetInactivityTimeout(); // start the inactivity timeout
|
|
130
136
|
const message = this.buildTTSConfigMessage();
|
|
131
137
|
this.ws.send(message);
|
|
132
138
|
const timestamp = this.nowRFC1123();
|
|
@@ -134,18 +140,21 @@ class EdgeTTS {
|
|
|
134
140
|
this.ws.send(speechMessage);
|
|
135
141
|
});
|
|
136
142
|
this.ws.on('message', (data) => {
|
|
143
|
+
resetInactivityTimeout(); // restart inactivity timeout
|
|
137
144
|
this.processAudioData(data);
|
|
138
145
|
});
|
|
139
146
|
this.ws.on('error', (err) => {
|
|
140
|
-
clearTimeout(
|
|
147
|
+
clearTimeout(inactivityTimeout);
|
|
141
148
|
if (this.ws && this.ws.readyState === ws_1.default.OPEN) {
|
|
142
149
|
this.ws.close();
|
|
143
150
|
}
|
|
144
151
|
reject(err);
|
|
145
152
|
});
|
|
146
153
|
this.ws.on('close', () => {
|
|
147
|
-
clearTimeout(
|
|
148
|
-
|
|
154
|
+
clearTimeout(inactivityTimeout);
|
|
155
|
+
if (!timedOut) {
|
|
156
|
+
resolve();
|
|
157
|
+
}
|
|
149
158
|
});
|
|
150
159
|
});
|
|
151
160
|
}
|
|
@@ -271,12 +280,25 @@ class EdgeTTS {
|
|
|
271
280
|
notify = null;
|
|
272
281
|
}
|
|
273
282
|
};
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
283
|
+
let timedOut = false;
|
|
284
|
+
let inactivityTimeout;
|
|
285
|
+
const resetInactivityTimeout = () => {
|
|
286
|
+
clearTimeout(inactivityTimeout);
|
|
287
|
+
inactivityTimeout = setTimeout(() => {
|
|
288
|
+
timedOut = true;
|
|
289
|
+
error = new Error("WebSocket inactivity timeout - no response from server");
|
|
290
|
+
done = true;
|
|
291
|
+
if (this.ws && this.ws.readyState === ws_1.default.OPEN) {
|
|
292
|
+
this.ws.close();
|
|
293
|
+
}
|
|
294
|
+
if (notify) {
|
|
295
|
+
notify();
|
|
296
|
+
notify = null;
|
|
297
|
+
}
|
|
298
|
+
}, 30000); // 30 seconds of inactivity
|
|
299
|
+
};
|
|
279
300
|
this.ws.on('open', () => {
|
|
301
|
+
resetInactivityTimeout(); // start the inactivity timeout
|
|
280
302
|
const message = this.buildTTSConfigMessage();
|
|
281
303
|
this.ws.send(message);
|
|
282
304
|
const timestamp = this.nowRFC1123();
|
|
@@ -284,6 +306,7 @@ class EdgeTTS {
|
|
|
284
306
|
this.ws.send(speechMessage);
|
|
285
307
|
});
|
|
286
308
|
this.ws.on('message', (data) => {
|
|
309
|
+
resetInactivityTimeout(); // restart inactivity timeout
|
|
287
310
|
const buffer = ensureBuffer(data);
|
|
288
311
|
const needle = buffer_1.Buffer.from('Path:audio\r\n');
|
|
289
312
|
const audioStartIndex = buffer.indexOf(new Uint8Array(needle));
|
|
@@ -307,6 +330,7 @@ class EdgeTTS {
|
|
|
307
330
|
}
|
|
308
331
|
});
|
|
309
332
|
this.ws.on('error', (err) => {
|
|
333
|
+
clearTimeout(inactivityTimeout);
|
|
310
334
|
error = err;
|
|
311
335
|
done = true;
|
|
312
336
|
if (notify) {
|
|
@@ -315,7 +339,7 @@ class EdgeTTS {
|
|
|
315
339
|
}
|
|
316
340
|
});
|
|
317
341
|
this.ws.on('close', () => {
|
|
318
|
-
clearTimeout(
|
|
342
|
+
clearTimeout(inactivityTimeout);
|
|
319
343
|
done = true;
|
|
320
344
|
if (notify) {
|
|
321
345
|
notify();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@andresaya/edge-tts",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.2",
|
|
4
4
|
"description": "Edge TTS is a package that allows access to the online text-to-speech service used by Microsoft Edge without the need for Microsoft Edge, Windows, or an API key.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"browser": "dist/browser/edge-tts.esm.js",
|