Skip to content

Edge TTS is a Node or Bun 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.

License

Notifications You must be signed in to change notification settings

YILS-LIN/edge-tts

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Edge TTS Enhanced

Edge TTS Enhanced is an improved version of the Edge TTS package that provides access to Microsoft Edge's text-to-speech service without requiring Microsoft Edge, Windows, or an API key. This package is forked and developed from Andres Aya's edge-tts with significant improvements and enhancements.

✨ New Features & Improvements

  • 🚀 New API with SynthesisResult Pattern: synthesize() returns an object with convenient methods
  • 🔒 Thread-Safe & Immutable: Synthesis results are not affected by multiple calls
  • 📝 Full TypeScript Support: Complete types for all APIs
  • 🧪 Comprehensive Unit Tests: 100% test coverage with Bun test framework
  • ⚡ Better Error Handling: Clear validation and helpful error messages
  • 📊 Audio Metadata: Direct access to size, format, and buffer information
  • 🔄 Backward Compatibility: Migration support from old API

🎯 Original Features

  • Text-to-Speech: Convert text to natural-sounding speech using Microsoft Edge's TTS capabilities
  • Multiple Voices: Access a variety of voices to suit your project needs
  • Audio Export Options: Export synthesized audio in multiple formats (raw, base64, or directly to file)
  • Command-Line Interface: Simple CLI for easy access to functionality
  • Easy Integration: Modular structure allows easy integration into existing projects

📦 Installation

You can install Edge TTS Enhanced via npm or bun:

bun add @duyquangnvx/edge-tts
npm install @duyquangnvx/edge-tts

Global Installation (CLI)

npm install -g @duyquangnvx/edge-tts

🚀 Usage

Command-Line Interface

To synthesize speech from text, use the following command:

edge-tts synthesize -t "Hello, world!" -o hello_world_audio

To list available voices:

edge-tts voice-list

Project Integration

New API (Recommended - v2.0.0+):

import { EdgeTTS, SynthesisResult } from '@duyquangnvx/edge-tts';

// Initialize EdgeTTS service
const tts = new EdgeTTS();

// Get available voices
const voices = await tts.getVoices();  
console.log(voices);

// Synthesize with new API - returns SynthesisResult object
const result: SynthesisResult = await tts.synthesize("Hello, world!", 'en-US-AriaNeural', {
    rate: 0,          // Speech rate (range: -100 to 100)
    volume: 0,        // Volume (range: -100 to 100)
    pitch: 0          // Voice pitch (range: -100 to 100)
});

// Use result object methods
const base64Audio = result.toBase64();         // Get audio as base64
await result.toFile("output_audio");           // Save audio to file
const rawAudio = result.toRaw();               // Get raw audio buffer
const audioBuffer = result.getBuffer();        // Get Buffer directly
const audioSize = result.getSize();            // Get audio size in bytes
const audioFormat = result.getFormat();        // Get audio format (mp3)

console.log(`Generated audio: ${audioSize} bytes, format: ${audioFormat}`);

📋 Export Options

The SynthesisResult object provides various methods to work with generated audio:

  • toBase64(): Returns audio as a Base64 string
  • toFile(outputPath): Saves audio to file (automatically adds .mp3 extension)
  • toRaw(): Returns raw audio buffer (identical to toBase64())
  • getBuffer(): Returns Buffer object directly for advanced manipulation
  • getSize(): Returns audio size in bytes
  • getFormat(): Returns audio format (currently 'mp3')

🧪 Testing

This package includes comprehensive unit tests with Bun test framework:

bun test                    # Run all tests
bun test --watch           # Watch mode
bun test --coverage        # Coverage report

🔄 Migration from Old API

If you're using the old API, here's how to migrate:

// ❌ Old API (deprecated)
await tts.synthesize(text, voice, options);
const base64 = tts.toBase64();
await tts.toFile("output");

// ✅ New API (recommended)
const result = await tts.synthesize(text, voice, options);
const base64 = result.toBase64();
await result.toFile("output");

🙏 Credits & Acknowledgments

Original Author

Special thanks to Andres Aya - the author of the original edge-tts who created the excellent foundation for this project. This package is forked and developed based on his work.

Inspirations

We would also like to extend our gratitude to the developers and contributors of the following projects for their inspiration and groundwork:

📝 License

This project is licensed under the GNU General Public License v3 (GPLv3), same as the original project.

🔗 Related Projects

About

Edge TTS is a Node or Bun 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.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 78.7%
  • JavaScript 21.3%