@andresaya/edge-tts 1.6.2 → 1.7.1

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.
@@ -27,6 +27,7 @@ function ensureBuffer(data) {
27
27
  class EdgeTTS {
28
28
  audio_stream = [];
29
29
  audio_format = 'mp3';
30
+ output_format = 'audio-24khz-48kbitrate-mono-mp3';
30
31
  word_boundaries = [];
31
32
  ws;
32
33
  async getVoices() {
@@ -119,6 +120,8 @@ class EdgeTTS {
119
120
  rejectUnauthorized: false
120
121
  });
121
122
  const SSML_text = this.getSSML(text, voice, options);
123
+ const outputFormat = options.outputFormat || 'audio-24khz-48kbitrate-mono-mp3';
124
+ this.output_format = outputFormat;
122
125
  let timedOut = false;
123
126
  let inactivityTimeout;
124
127
  const resetInactivityTimeout = () => {
@@ -133,7 +136,7 @@ class EdgeTTS {
133
136
  };
134
137
  this.ws.on('open', () => {
135
138
  resetInactivityTimeout(); // start the inactivity timeout
136
- const message = this.buildTTSConfigMessage();
139
+ const message = this.buildTTSConfigMessage(outputFormat);
137
140
  this.ws.send(message);
138
141
  const timestamp = this.nowRFC1123();
139
142
  const speechMessage = `X-RequestId:${reqId}\r\nContent-Type:application/ssml+xml\r\nX-Timestamp:${timestamp}\r\nPath:ssml\r\n\r\n${SSML_text}`;
@@ -254,10 +257,10 @@ class EdgeTTS {
254
257
  parseRFC1123(rfcStr) {
255
258
  return new Date(rfcStr);
256
259
  }
257
- buildTTSConfigMessage() {
260
+ buildTTSConfigMessage(outputFormat = 'audio-24khz-48kbitrate-mono-mp3') {
258
261
  const timestamp = this.nowRFC1123();
259
262
  return `X-Timestamp:${timestamp}\r\nContent-Type:application/json; charset=utf-8\r\nPath:speech.config\r\n\r\n` +
260
- `{"context":{"synthesis":{"audio":{"metadataoptions":{"sentenceBoundaryEnabled":false,"wordBoundaryEnabled":true},"outputFormat":"audio-24khz-48kbitrate-mono-mp3"}}}}`;
263
+ `{"context":{"synthesis":{"audio":{"metadataoptions":{"sentenceBoundaryEnabled":false,"wordBoundaryEnabled":true},"outputFormat":"${outputFormat}"}}}}`;
261
264
  }
262
265
  async *synthesizeStream(text, voice = 'en-US-AnaNeural', options = {}) {
263
266
  this.audio_stream = [];
@@ -269,6 +272,8 @@ class EdgeTTS {
269
272
  rejectUnauthorized: false
270
273
  });
271
274
  const SSML_text = this.getSSML(text, voice, options);
275
+ const outputFormat = options.outputFormat || 'audio-24khz-48kbitrate-mono-mp3';
276
+ this.output_format = outputFormat;
272
277
  const queue = [];
273
278
  let done = false;
274
279
  let error = null;
@@ -299,7 +304,7 @@ class EdgeTTS {
299
304
  };
300
305
  this.ws.on('open', () => {
301
306
  resetInactivityTimeout(); // start the inactivity timeout
302
- const message = this.buildTTSConfigMessage();
307
+ const message = this.buildTTSConfigMessage(outputFormat);
303
308
  this.ws.send(message);
304
309
  const timestamp = this.nowRFC1123();
305
310
  const speechMessage = `X-RequestId:${reqId}\r\nContent-Type:application/ssml+xml\r\nX-Timestamp:${timestamp}\r\nPath:ssml\r\n\r\n${SSML_text}`;
@@ -429,17 +434,41 @@ class EdgeTTS {
429
434
  const estimatedDuration = bufferSize / (24000 * 3); // 24000 Hz sample rate, 3 bytes per sample (16-bit stereo)
430
435
  return estimatedDuration;
431
436
  }
437
+ getFileExtension(format) {
438
+ if (format.includes('mp3'))
439
+ return 'mp3';
440
+ if (format.includes('opus') && format.includes('webm'))
441
+ return 'webm';
442
+ if (format.includes('opus') && format.includes('ogg'))
443
+ return 'ogg';
444
+ if (format.includes('wav') || format.includes('riff'))
445
+ return 'wav';
446
+ if (format.includes('pcm') && format.includes('raw'))
447
+ return 'pcm';
448
+ if (format.includes('alaw'))
449
+ return 'alaw';
450
+ if (format.includes('mulaw'))
451
+ return 'mulaw';
452
+ if (format.includes('truesilk'))
453
+ return 'silk';
454
+ if (format.includes('g722'))
455
+ return 'g722';
456
+ if (format.includes('amr'))
457
+ return 'amr';
458
+ return 'audio';
459
+ }
432
460
  getAudioInfo() {
433
461
  const buffer = this.toBuffer();
434
462
  return {
435
463
  size: buffer.length,
436
- format: this.audio_format,
464
+ format: this.getFileExtension(this.output_format),
437
465
  estimatedDuration: this.getDuration()
438
466
  };
439
467
  }
440
- async toFile(outputPath, format = this.audio_format) {
441
- if (!format || typeof format !== 'string')
442
- format = this.audio_format;
468
+ async toFile(outputPath, format) {
469
+ if (!format) {
470
+ format = this.getFileExtension(this.output_format);
471
+ }
443
472
  const audioBuffer = this.toBuffer();
444
473
  const finalPath = `${outputPath}.${format}`;
445
474
  await (0, promises_1.writeFile)(finalPath, new Uint8Array(audioBuffer));
package/package.json CHANGED
@@ -1,54 +1,54 @@
1
- {
2
- "name": "@andresaya/edge-tts",
3
- "version": "1.6.2",
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
- "main": "dist/index.js",
6
- "browser": "dist/browser/edge-tts.esm.js",
7
- "unpkg": "dist/browser/edge-tts.umd.min.js",
8
- "jsdelivr": "dist/browser/edge-tts.umd.min.js",
9
- "keywords": [
10
- "edge",
11
- "tts",
12
- "text-to-speech",
13
- "microsoft",
14
- "microsoft edge",
15
- "speech-synthesis"
16
- ],
17
- "author": "Andres Aya",
18
- "license": "GPL-3.0-only",
19
- "homepage": "https://github.com/andresayac/edge-tts",
20
- "bugs": {
21
- "url": "https://github.com/andresayac/edge-tts/issues"
22
- },
23
- "scripts": {
24
- "build": "tsc",
25
- "build:bin": "bun scripts/build.ts",
26
- "build:browser": "bun scripts/build-browser.ts",
27
- "prepublishOnly": "npm run build && npm run build:bin && npm run build:browser"
28
- },
29
- "devDependencies": {
30
- "@types/bun": "latest",
31
- "@types/ws": "^8.18.1",
32
- "esbuild": "^0.25.12",
33
- "typescript": "^5.6.2"
34
- },
35
- "dependencies": {
36
- "@types/uuid": "^10.0.0",
37
- "commander": "^12.1.0",
38
- "events": "^3.3.0",
39
- "fs": "^0.0.1-security",
40
- "ws": "^8.18.3"
41
- },
42
- "peerDependencies": {
43
- "typescript": "^5.0.0"
44
- },
45
- "files": [
46
- "dist"
47
- ],
48
- "bin": {
49
- "edge-tts": "./dist/cli/edge-tts.js"
50
- },
51
- "engines": {
52
- "bun": ">=0.5.0"
53
- }
54
- }
1
+ {
2
+ "name": "@andresaya/edge-tts",
3
+ "version": "1.7.1",
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
+ "main": "dist/index.js",
6
+ "browser": "dist/browser/edge-tts.esm.js",
7
+ "unpkg": "dist/browser/edge-tts.umd.min.js",
8
+ "jsdelivr": "dist/browser/edge-tts.umd.min.js",
9
+ "keywords": [
10
+ "edge",
11
+ "tts",
12
+ "text-to-speech",
13
+ "microsoft",
14
+ "microsoft edge",
15
+ "speech-synthesis"
16
+ ],
17
+ "author": "Andres Aya",
18
+ "license": "GPL-3.0-only",
19
+ "homepage": "https://github.com/andresayac/edge-tts",
20
+ "bugs": {
21
+ "url": "https://github.com/andresayac/edge-tts/issues"
22
+ },
23
+ "scripts": {
24
+ "build": "tsc",
25
+ "build:bin": "bun scripts/build.ts",
26
+ "build:browser": "bun scripts/build-browser.ts",
27
+ "prepublishOnly": "npm run build && npm run build:bin && npm run build:browser"
28
+ },
29
+ "devDependencies": {
30
+ "@types/bun": "latest",
31
+ "@types/ws": "^8.18.1",
32
+ "esbuild": "^0.25.12",
33
+ "typescript": "^5.6.2"
34
+ },
35
+ "dependencies": {
36
+ "@types/uuid": "^10.0.0",
37
+ "commander": "^12.1.0",
38
+ "events": "^3.3.0",
39
+ "fs": "^0.0.1-security",
40
+ "ws": "^8.18.3"
41
+ },
42
+ "peerDependencies": {
43
+ "typescript": "^5.0.0"
44
+ },
45
+ "files": [
46
+ "dist"
47
+ ],
48
+ "bin": {
49
+ "edge-tts": "./dist/cli/edge-tts.js"
50
+ },
51
+ "engines": {
52
+ "bun": ">=0.5.0"
53
+ }
54
+ }
package/dist/browser.d.ts DELETED
@@ -1 +0,0 @@
1
- export { EdgeTTS, type Voice, type SynthesisOptions, type WordBoundary } from './browser/EdgeTTS.browser';
package/dist/browser.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EdgeTTS = void 0;
4
- var EdgeTTS_browser_1 = require("./browser/EdgeTTS.browser");
5
- Object.defineProperty(exports, "EdgeTTS", { enumerable: true, get: function () { return EdgeTTS_browser_1.EdgeTTS; } });