@andresaya/edge-tts 1.2.7 → 1.3.0
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 +256 -28
- package/dist/cli/edge-tts.d.ts +2 -0
- package/dist/cli/edge-tts.js +1 -1
- package/dist/commands/SynthesizeCommand.d.ts +2 -0
- package/dist/commands/VoiceListCommand.d.ts +2 -0
- package/dist/config/constants.d.ts +5 -0
- package/dist/index.d.ts +1 -0
- package/dist/services/EdgeTTS.d.ts +31 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,13 +6,16 @@
|
|
|
6
6
|
|
|
7
7
|
- **Text-to-Speech**: Convert text into natural-sounding speech using Microsoft Edge's TTS capabilities.
|
|
8
8
|
- **Multiple Voices**: Access a variety of voices to suit your project's needs.
|
|
9
|
+
- **Voice Filtering**: Filter voices by language and gender for better selection.
|
|
10
|
+
- **Audio Information**: Get detailed information about generated audio (size, duration, format).
|
|
9
11
|
- **Audio Export Options**: Export synthesized audio in different formats (raw, base64, or directly to a file).
|
|
12
|
+
- **Streaming Support**: Stream audio data in real-time for better performance.
|
|
10
13
|
- **Command-Line Interface**: Use a simple CLI for easy access to functionality.
|
|
11
14
|
- **Easy Integration**: Modular structure allows for easy inclusion in existing projects.
|
|
12
15
|
|
|
13
16
|
## Installation
|
|
14
17
|
|
|
15
|
-
You can install Edge TTS via npm
|
|
18
|
+
You can install Edge TTS via npm or bun:
|
|
16
19
|
|
|
17
20
|
```bash
|
|
18
21
|
bun add @andresaya/edge-tts
|
|
@@ -21,63 +24,288 @@ bun add @andresaya/edge-tts
|
|
|
21
24
|
npm install @andresaya/edge-tts
|
|
22
25
|
```
|
|
23
26
|
|
|
24
|
-
|
|
25
27
|
## Usage
|
|
26
|
-
Command-Line Interface
|
|
27
28
|
|
|
28
|
-
|
|
29
|
+
### Command-Line Interface
|
|
30
|
+
|
|
31
|
+
Install globally to use the CLI:
|
|
29
32
|
|
|
30
33
|
```bash
|
|
31
34
|
npm install -g @andresaya/edge-tts
|
|
32
35
|
```
|
|
33
36
|
|
|
34
|
-
To synthesize speech from text
|
|
37
|
+
To synthesize speech from text:
|
|
35
38
|
```bash
|
|
36
39
|
edge-tts synthesize -t "Hello, world!" -o hello_world_audio
|
|
37
40
|
```
|
|
38
41
|
|
|
39
|
-
To list available voices
|
|
40
|
-
|
|
42
|
+
To list available voices:
|
|
41
43
|
```bash
|
|
42
44
|
edge-tts voice-list
|
|
43
45
|
```
|
|
44
46
|
|
|
45
|
-
Integration into Your Project
|
|
46
|
-
To use Edge TTS in your Bun project, you can import it like this:
|
|
47
|
+
### Integration into Your Project
|
|
47
48
|
|
|
48
49
|
```js
|
|
49
50
|
import { EdgeTTS } from '@andresaya/edge-tts';
|
|
50
51
|
|
|
51
52
|
// Initialize the EdgeTTS service
|
|
52
53
|
const tts = new EdgeTTS();
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## API Reference
|
|
53
57
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
58
|
+
### Voice Management
|
|
59
|
+
|
|
60
|
+
#### Get All Voices
|
|
61
|
+
```js
|
|
62
|
+
const voices = await tts.getVoices();
|
|
63
|
+
console.log(`Found ${voices.length} voices`);
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
#### Filter Voices by Language
|
|
67
|
+
```js
|
|
68
|
+
// Get all English voices
|
|
69
|
+
const englishVoices = await tts.getVoicesByLanguage('en');
|
|
70
|
+
|
|
71
|
+
// Get specific locale voices
|
|
72
|
+
const usEnglishVoices = await tts.getVoicesByLanguage('en-US');
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
#### Filter Voices by Gender
|
|
76
|
+
```js
|
|
77
|
+
// Get all female voices
|
|
78
|
+
const femaleVoices = await tts.getVoicesByGender('Female');
|
|
79
|
+
|
|
80
|
+
// Get all male voices
|
|
81
|
+
const maleVoices = await tts.getVoicesByGender('Male');
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Text Synthesis
|
|
85
|
+
|
|
86
|
+
#### Basic Synthesis
|
|
87
|
+
```js
|
|
88
|
+
// Simple synthesis with default voice
|
|
89
|
+
await tts.synthesize("Hello, world!");
|
|
57
90
|
|
|
58
|
-
//
|
|
91
|
+
// Synthesis with specific voice
|
|
92
|
+
await tts.synthesize("Hello, world!", 'en-US-AriaNeural');
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
#### Advanced Synthesis with Options
|
|
96
|
+
```js
|
|
59
97
|
await tts.synthesize("Hello, world!", 'en-US-AriaNeural', {
|
|
60
|
-
rate: '
|
|
61
|
-
volume: '
|
|
62
|
-
pitch: '
|
|
98
|
+
rate: '50%', // Speech rate: -100% to +200% (or number)
|
|
99
|
+
volume: '90%', // Speech volume: -100% to +100% (or number)
|
|
100
|
+
pitch: '+20Hz' // Voice pitch: -100Hz to +100Hz (or number)
|
|
63
101
|
});
|
|
102
|
+
```
|
|
64
103
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
await tts.
|
|
104
|
+
#### Streaming Synthesis
|
|
105
|
+
```js
|
|
106
|
+
// Stream audio data in real-time
|
|
107
|
+
for await (const chunk of tts.synthesizeStream("Long text to stream...", 'en-US-AriaNeural')) {
|
|
108
|
+
// Process each audio chunk as it arrives
|
|
109
|
+
console.log(`Received chunk: ${chunk.length} bytes`);
|
|
110
|
+
}
|
|
69
111
|
```
|
|
70
112
|
|
|
71
|
-
|
|
72
|
-
After synthesizing speech, you can export the audio in various formats:
|
|
113
|
+
### Audio Information
|
|
73
114
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
115
|
+
#### Get Audio Details
|
|
116
|
+
```js
|
|
117
|
+
await tts.synthesize("Hello, world!");
|
|
77
118
|
|
|
78
|
-
|
|
79
|
-
|
|
119
|
+
const audioInfo = tts.getAudioInfo();
|
|
120
|
+
console.log(`Size: ${audioInfo.size} bytes`);
|
|
121
|
+
console.log(`Format: ${audioInfo.format}`);
|
|
122
|
+
console.log(`Duration: ${audioInfo.estimatedDuration} seconds`);
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
#### Get Duration Only
|
|
126
|
+
```js
|
|
127
|
+
const duration = tts.getDuration();
|
|
128
|
+
console.log(`Audio duration: ${duration} seconds`);
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Export Options
|
|
132
|
+
|
|
133
|
+
#### Export as Base64
|
|
134
|
+
```js
|
|
135
|
+
await tts.synthesize("Hello, world!");
|
|
136
|
+
const base64Audio = tts.toBase64();
|
|
137
|
+
console.log(`Base64 length: ${base64Audio.length}`);
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
#### Export as Raw Buffer
|
|
141
|
+
```js
|
|
142
|
+
const rawAudio = tts.toRaw(); // Alias for toBase64()
|
|
143
|
+
const buffer = tts.toBuffer(); // Get as Buffer object
|
|
144
|
+
```
|
|
80
145
|
|
|
146
|
+
#### Export to File
|
|
147
|
+
```js
|
|
148
|
+
const filePath = await tts.toFile("output_audio");
|
|
149
|
+
console.log(`Audio saved to: ${filePath}`);
|
|
150
|
+
// Creates: output_audio.mp3
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Examples
|
|
154
|
+
|
|
155
|
+
### Complete Example with Voice Selection
|
|
156
|
+
```js
|
|
157
|
+
import { EdgeTTS } from '@andresaya/edge-tts';
|
|
158
|
+
|
|
159
|
+
async function textToSpeechExample() {
|
|
160
|
+
const tts = new EdgeTTS();
|
|
161
|
+
|
|
162
|
+
// Get available English voices
|
|
163
|
+
const englishVoices = await tts.getVoicesByLanguage('en-US');
|
|
164
|
+
console.log(`Available English voices: ${englishVoices.length}`);
|
|
165
|
+
|
|
166
|
+
// Use the first available voice
|
|
167
|
+
const voice = englishVoices[0];
|
|
168
|
+
console.log(`Using voice: ${voice.FriendlyName}`);
|
|
169
|
+
|
|
170
|
+
// Synthesize with custom options
|
|
171
|
+
await tts.synthesize(
|
|
172
|
+
"This is a test of the Edge TTS system with custom voice parameters.",
|
|
173
|
+
voice.ShortName,
|
|
174
|
+
{
|
|
175
|
+
pitch: '+10Hz',
|
|
176
|
+
rate: '-10%',
|
|
177
|
+
volume: '90%'
|
|
178
|
+
}
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
// Get audio information
|
|
182
|
+
const info = tts.getAudioInfo();
|
|
183
|
+
console.log(`Generated audio: ${info.size} bytes, ${info.estimatedDuration.toFixed(2)}s`);
|
|
184
|
+
|
|
185
|
+
// Save to file
|
|
186
|
+
const outputPath = await tts.toFile('./output/speech');
|
|
187
|
+
console.log(`Audio saved to: ${outputPath}`);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
textToSpeechExample().catch(console.error);
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Streaming Example
|
|
194
|
+
```js
|
|
195
|
+
import { EdgeTTS } from '@andresaya/edge-tts';
|
|
196
|
+
import { createWriteStream } from 'fs';
|
|
197
|
+
|
|
198
|
+
async function streamingExample() {
|
|
199
|
+
const tts = new EdgeTTS();
|
|
200
|
+
const writeStream = createWriteStream('streaming_output.mp3');
|
|
201
|
+
|
|
202
|
+
const longText = "This is a very long text that will be streamed...";
|
|
203
|
+
|
|
204
|
+
for await (const chunk of tts.synthesizeStream(longText, 'en-US-AriaNeural')) {
|
|
205
|
+
writeStream.write(chunk);
|
|
206
|
+
console.log(`Streamed ${chunk.length} bytes`);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
writeStream.end();
|
|
210
|
+
console.log('Streaming completed!');
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
streamingExample().catch(console.error);
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Voice Exploration Example
|
|
217
|
+
```js
|
|
218
|
+
import { EdgeTTS } from '@andresaya/edge-tts';
|
|
219
|
+
|
|
220
|
+
async function exploreVoices() {
|
|
221
|
+
const tts = new EdgeTTS();
|
|
222
|
+
|
|
223
|
+
// Get all voices
|
|
224
|
+
const allVoices = await tts.getVoices();
|
|
225
|
+
console.log(`Total voices available: ${allVoices.length}`);
|
|
226
|
+
|
|
227
|
+
// Group by language
|
|
228
|
+
const languages = [...new Set(allVoices.map(v => v.Locale.split('-')[0]))];
|
|
229
|
+
console.log(`Languages available: ${languages.join(', ')}`);
|
|
230
|
+
|
|
231
|
+
// Get Spanish voices
|
|
232
|
+
const spanishVoices = await tts.getVoicesByLanguage('es');
|
|
233
|
+
console.log(`Spanish voices: ${spanishVoices.length}`);
|
|
234
|
+
|
|
235
|
+
// Get female voices
|
|
236
|
+
const femaleVoices = await tts.getVoicesByGender('Female');
|
|
237
|
+
console.log(`Female voices: ${femaleVoices.length}`);
|
|
238
|
+
|
|
239
|
+
// Test different voices
|
|
240
|
+
const testText = "Hola, este es un ejemplo de síntesis de voz.";
|
|
241
|
+
|
|
242
|
+
for (const voice of spanishVoices.slice(0, 3)) {
|
|
243
|
+
console.log(`Testing voice: ${voice.FriendlyName}`);
|
|
244
|
+
|
|
245
|
+
await tts.synthesize(testText, voice.ShortName);
|
|
246
|
+
const filePath = await tts.toFile(`./voices/${voice.ShortName}`);
|
|
247
|
+
|
|
248
|
+
console.log(`Saved: ${filePath}`);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
exploreVoices().catch(console.error);
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
## Voice Options
|
|
256
|
+
|
|
257
|
+
### Synthesis Parameters
|
|
258
|
+
|
|
259
|
+
| Parameter | Type | Range | Description |
|
|
260
|
+
|-----------|------|-------|-------------|
|
|
261
|
+
| `pitch` | `string \| number` | `-100Hz` to `+100Hz` | Voice pitch adjustment |
|
|
262
|
+
| `rate` | `string \| number` | `-100%` to `+200%` | Speech rate adjustment |
|
|
263
|
+
| `volume` | `string \| number` | `-100%` to `+100%` | Volume adjustment |
|
|
264
|
+
|
|
265
|
+
### Parameter Examples
|
|
266
|
+
```js
|
|
267
|
+
// Using numbers (recommended)
|
|
268
|
+
{ pitch: 20, rate: -10, volume: 90 }
|
|
269
|
+
|
|
270
|
+
// Using strings
|
|
271
|
+
{ pitch: '+20Hz', rate: '-10%', volume: '90%' }
|
|
272
|
+
|
|
273
|
+
// Mixed usage
|
|
274
|
+
{ pitch: 15, rate: '25%', volume: 85 }
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
## Error Handling
|
|
278
|
+
|
|
279
|
+
```js
|
|
280
|
+
import { EdgeTTS } from '@andresaya/edge-tts';
|
|
281
|
+
|
|
282
|
+
async function handleErrors() {
|
|
283
|
+
const tts = new EdgeTTS();
|
|
284
|
+
|
|
285
|
+
try {
|
|
286
|
+
await tts.synthesize("Test text", 'invalid-voice-name');
|
|
287
|
+
} catch (error) {
|
|
288
|
+
console.error('Synthesis failed:', error.message);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
try {
|
|
292
|
+
// This will throw an error - no audio data
|
|
293
|
+
const duration = tts.getDuration();
|
|
294
|
+
} catch (error) {
|
|
295
|
+
console.error('No audio data available:', error.message);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
try {
|
|
299
|
+
// Invalid volume range
|
|
300
|
+
await tts.synthesize("Test", 'en-US-AriaNeural', { volume: -150 });
|
|
301
|
+
} catch (error) {
|
|
302
|
+
console.error('Invalid parameter:', error.message);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
## PHP Version
|
|
308
|
+
If you want to use Edge TTS with PHP, you can check out the PHP version of this package: [Edge TTS PHP](https://github.com/andresayac/edge-tts-php)
|
|
81
309
|
|
|
82
310
|
## License
|
|
83
311
|
This project is licensed under the GNU General Public License v3 (GPLv3).
|
|
@@ -88,4 +316,4 @@ We would like to extend our gratitude to the developers and contributors of the
|
|
|
88
316
|
|
|
89
317
|
* https://github.com/rany2/edge-tts/tree/master/examples
|
|
90
318
|
* https://github.com/rany2/edge-tts/blob/master/src/edge_tts/util.py
|
|
91
|
-
* https://github.com/hasscc/hass-edge-tts/blob/main/custom_components/edge_tts/tts.py
|
|
319
|
+
* https://github.com/hasscc/hass-edge-tts/blob/main/custom_components/edge_tts/tts.py
|
package/dist/cli/edge-tts.js
CHANGED
|
@@ -6,7 +6,7 @@ const VoiceListCommand_1 = require("../commands/VoiceListCommand");
|
|
|
6
6
|
const commander_1 = require("commander");
|
|
7
7
|
const program = new commander_1.Command();
|
|
8
8
|
program
|
|
9
|
-
.version('1.2.
|
|
9
|
+
.version('1.2.7')
|
|
10
10
|
.addCommand(SynthesizeCommand_1.SynthesizeCommand)
|
|
11
11
|
.addCommand(VoiceListCommand_1.VoiceListCommand);
|
|
12
12
|
try {
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { EdgeTTS, type Voice, type SynthesisOptions } from './services/EdgeTTS';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Buffer } from 'buffer';
|
|
2
|
+
export interface Voice {
|
|
3
|
+
Name: string;
|
|
4
|
+
ShortName: string;
|
|
5
|
+
Gender: string;
|
|
6
|
+
Locale: string;
|
|
7
|
+
FriendlyName: string;
|
|
8
|
+
}
|
|
9
|
+
export interface SynthesisOptions {
|
|
10
|
+
pitch?: string | number;
|
|
11
|
+
rate?: string | number;
|
|
12
|
+
volume?: string | number;
|
|
13
|
+
}
|
|
14
|
+
export declare class EdgeTTS {
|
|
15
|
+
private audio_stream;
|
|
16
|
+
private audio_format;
|
|
17
|
+
private ws;
|
|
18
|
+
getVoices(): Promise<Voice[]>;
|
|
19
|
+
private generateUUID;
|
|
20
|
+
private validatePitch;
|
|
21
|
+
private validateRate;
|
|
22
|
+
private validateVolume;
|
|
23
|
+
synthesize(text: string, voice?: string, options?: SynthesisOptions): Promise<void>;
|
|
24
|
+
private getSSML;
|
|
25
|
+
private buildTTSConfigMessage;
|
|
26
|
+
private processAudioData;
|
|
27
|
+
toFile(outputPath: string): Promise<string>;
|
|
28
|
+
toRaw(): string;
|
|
29
|
+
toBase64(): string;
|
|
30
|
+
toBuffer(): Buffer;
|
|
31
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@andresaya/edge-tts",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
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": [
|