@andresaya/edge-tts 1.2.6 → 1.2.7

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.
@@ -1,12 +1,14 @@
1
1
  #!/usr/bin/env node
2
- import { SynthesizeCommand } from '../commands/SynthesizeCommand';
3
- import { VoiceListCommand } from '../commands/VoiceListCommand';
4
- import { Command } from 'commander';
5
- const program = new Command();
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const SynthesizeCommand_1 = require("../commands/SynthesizeCommand");
5
+ const VoiceListCommand_1 = require("../commands/VoiceListCommand");
6
+ const commander_1 = require("commander");
7
+ const program = new commander_1.Command();
6
8
  program
7
9
  .version('1.2.6')
8
- .addCommand(SynthesizeCommand)
9
- .addCommand(VoiceListCommand);
10
+ .addCommand(SynthesizeCommand_1.SynthesizeCommand)
11
+ .addCommand(VoiceListCommand_1.VoiceListCommand);
10
12
  try {
11
13
  program.parse();
12
14
  }
@@ -1,6 +1,9 @@
1
- import { Command } from 'commander';
2
- import { EdgeTTS } from '../services/EdgeTTS';
3
- export const SynthesizeCommand = new Command('synthesize')
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SynthesizeCommand = void 0;
4
+ const commander_1 = require("commander");
5
+ const EdgeTTS_1 = require("../services/EdgeTTS");
6
+ exports.SynthesizeCommand = new commander_1.Command('synthesize')
4
7
  .description('Edge TTS: synthesize text to audio')
5
8
  .option('-t, --text <text>', 'Text to convert to audio')
6
9
  .option('-v, --voice [voice]', 'Voice to use for the audio synthesis', 'en-US-AriaNeural')
@@ -14,7 +17,7 @@ export const SynthesizeCommand = new Command('synthesize')
14
17
  console.error('Text is required');
15
18
  process.exit(1);
16
19
  }
17
- const tts = new EdgeTTS();
20
+ const tts = new EdgeTTS_1.EdgeTTS();
18
21
  await tts.synthesize(text, voice, { pitch, rate, volume });
19
22
  await tts.toFile(`${output}`);
20
23
  console.log(`Audio file generated: ${output}.mp3`);
@@ -1,9 +1,12 @@
1
- import { Command } from 'commander';
2
- import { EdgeTTS } from '../services/EdgeTTS';
3
- export const VoiceListCommand = new Command('voice-list')
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VoiceListCommand = void 0;
4
+ const commander_1 = require("commander");
5
+ const EdgeTTS_1 = require("../services/EdgeTTS");
6
+ exports.VoiceListCommand = new commander_1.Command('voice-list')
4
7
  .description('Get the list of available voices')
5
8
  .action(async () => {
6
- const tts = new EdgeTTS();
9
+ const tts = new EdgeTTS_1.EdgeTTS();
7
10
  const voices = await tts.getVoices();
8
11
  console.log('Lista de voces disponibles:');
9
12
  voices.forEach((voice) => {
@@ -1,4 +1,7 @@
1
- export const Constants = {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Constants = void 0;
4
+ exports.Constants = {
2
5
  TRUSTED_CLIENT_TOKEN: '6A5AA1D4EAFF4E9FB37E23D68491D6F4',
3
6
  WSS_URL: 'wss://speech.platform.bing.com/consumer/speech/synthesize/readaloud/edge/v1',
4
7
  VOICES_URL: 'https://speech.platform.bing.com/consumer/speech/synthesize/readaloud/voices/list',
package/dist/index.js CHANGED
@@ -1 +1,5 @@
1
- export { EdgeTTS } from './services/EdgeTTS';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EdgeTTS = void 0;
4
+ var EdgeTTS_1 = require("./services/EdgeTTS");
5
+ Object.defineProperty(exports, "EdgeTTS", { enumerable: true, get: function () { return EdgeTTS_1.EdgeTTS; } });
@@ -1,28 +1,34 @@
1
- import WebSocket, {} from 'ws';
2
- import { Constants } from '../config/constants';
3
- import { writeFile } from 'fs/promises';
4
- import { Buffer } from 'buffer';
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.EdgeTTS = void 0;
7
+ const ws_1 = __importDefault(require("ws"));
8
+ const constants_1 = require("../config/constants");
9
+ const promises_1 = require("fs/promises");
10
+ const buffer_1 = require("buffer");
5
11
  function ensureBuffer(data) {
6
- if (Buffer.isBuffer(data)) {
12
+ if (buffer_1.Buffer.isBuffer(data)) {
7
13
  return data;
8
14
  }
9
15
  if (data instanceof ArrayBuffer) {
10
- return Buffer.from(data);
16
+ return buffer_1.Buffer.from(data);
11
17
  }
12
18
  if (Array.isArray(data)) {
13
- return Buffer.concat(data);
19
+ return buffer_1.Buffer.concat(data);
14
20
  }
15
21
  if (typeof data === 'string') {
16
- return Buffer.from(data, 'utf-8');
22
+ return buffer_1.Buffer.from(data, 'utf-8');
17
23
  }
18
24
  throw new Error(`Unsupported RawData type: ${typeof data}`);
19
25
  }
20
- export class EdgeTTS {
26
+ class EdgeTTS {
21
27
  audio_stream = [];
22
28
  audio_format = 'mp3';
23
29
  ws;
24
30
  async getVoices() {
25
- const response = await fetch(`${Constants.VOICES_URL}?trustedclienttoken=${Constants.TRUSTED_CLIENT_TOKEN}`);
31
+ const response = await fetch(`${constants_1.Constants.VOICES_URL}?trustedclienttoken=${constants_1.Constants.TRUSTED_CLIENT_TOKEN}`);
26
32
  const data = await response.json();
27
33
  return data.map((voice) => {
28
34
  delete voice.VoiceTag;
@@ -81,10 +87,10 @@ export class EdgeTTS {
81
87
  return new Promise((resolve, reject) => {
82
88
  this.audio_stream = [];
83
89
  const req_id = this.generateUUID();
84
- this.ws = new WebSocket(`${Constants.WSS_URL}?trustedclienttoken=${Constants.TRUSTED_CLIENT_TOKEN}&ConnectionId=${req_id}`);
90
+ this.ws = new ws_1.default(`${constants_1.Constants.WSS_URL}?trustedclienttoken=${constants_1.Constants.TRUSTED_CLIENT_TOKEN}&ConnectionId=${req_id}`);
85
91
  const SSML_text = this.getSSML(text, voice, options);
86
92
  const timeout = setTimeout(() => {
87
- if (this.ws && this.ws.readyState === WebSocket.OPEN) {
93
+ if (this.ws && this.ws.readyState === ws_1.default.OPEN) {
88
94
  this.ws.close();
89
95
  }
90
96
  reject(new Error("Synthesis timeout"));
@@ -100,7 +106,7 @@ export class EdgeTTS {
100
106
  });
101
107
  this.ws.on('error', (err) => {
102
108
  clearTimeout(timeout);
103
- if (this.ws && this.ws.readyState === WebSocket.OPEN) {
109
+ if (this.ws && this.ws.readyState === ws_1.default.OPEN) {
104
110
  this.ws.close();
105
111
  }
106
112
  reject(err);
@@ -126,7 +132,7 @@ export class EdgeTTS {
126
132
  }
127
133
  processAudioData(data) {
128
134
  const buffer = ensureBuffer(data);
129
- const needle = Buffer.from("Path:audio\r\n");
135
+ const needle = buffer_1.Buffer.from("Path:audio\r\n");
130
136
  const audioStartIndex = buffer.indexOf(new Uint8Array(needle));
131
137
  if (audioStartIndex !== -1) {
132
138
  const audioChunk = buffer.subarray(audioStartIndex + needle.length);
@@ -139,7 +145,7 @@ export class EdgeTTS {
139
145
  async toFile(outputPath) {
140
146
  const audioBuffer = this.toBuffer();
141
147
  const finalPath = `${outputPath}.${this.audio_format}`;
142
- await writeFile(finalPath, new Uint8Array(audioBuffer));
148
+ await (0, promises_1.writeFile)(finalPath, new Uint8Array(audioBuffer));
143
149
  return finalPath;
144
150
  }
145
151
  toRaw() {
@@ -152,6 +158,7 @@ export class EdgeTTS {
152
158
  if (this.audio_stream.length === 0) {
153
159
  throw new Error("No audio data available. Did you run synthesize() first?");
154
160
  }
155
- return Buffer.concat(this.audio_stream);
161
+ return buffer_1.Buffer.concat(this.audio_stream);
156
162
  }
157
163
  }
164
+ exports.EdgeTTS = EdgeTTS;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andresaya/edge-tts",
3
- "version": "1.2.6",
3
+ "version": "1.2.7",
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
  "keywords": [