Sitelet https://github.com/feuyeux/hello-edge-tts
Skip to content

Repository files navigation

Hello Edge TTS

A comprehensive multi-language demonstration suite showcasing text-to-speech functionality using Microsoft Edge's TTS service. This project provides production-ready examples in Python, Dart, Rust, and Java, each implementing advanced TTS features including voice synthesis, SSML support, batch processing, and cross-platform audio playback.

🎯 Overview

The hello-edge-tts project demonstrates how to integrate with Microsoft Edge's text-to-speech service across different programming languages and paradigms. Each implementation follows consistent API patterns while leveraging language-specific best practices, performance optimizations, and idiomatic code styles.

Perfect for:

  • Learning TTS integration across different languages
  • Comparing async programming patterns
  • Understanding cross-platform audio handling
  • Building production TTS applications
  • Educational and research purposes

🎯 Architecture Overview

The hello-edge-tts project demonstrates consistent TTS integration patterns across different programming languages, each following the same core workflow:

sequenceDiagram
    autonumber
    participant APP as Application
    participant LIB as TTS Library
    participant AUTH as Auth Service
    participant WS as TTS WebSocket
    participant OUT as Audio Output

    Note over LIB,WS: Protocol: WebSocket wss://speech.platform.bing.com/consumer/speech/synthesize/readaloud/edge/v1

    APP->>LIB: Start TTS Request
    LIB->>AUTH: GET /translate/auth
    AUTH-->>LIB: 200 OK {token}
    LIB->>WS: Open WebSocket (Bearer token)
    WS-->>LIB: 101 Switching Protocols
    LIB->>WS: speech.config (JSON)
    WS-->>LIB: turn.start
    LIB->>WS: SSML for text A
    WS-->>LIB: audio.metadata
    WS-->>LIB: audio bytes
    WS-->>LIB: turn.end
    LIB-->>OUT: Play audio A
    Note over LIB,WS: Keep connection open for multiple requests
    APP->>LIB: Send text B
    LIB->>WS: SSML for text B
    WS-->>LIB: audio.metadata
    WS-->>LIB: audio bytes
    WS-->>LIB: turn.end
    LIB-->>OUT: Play audio B
    Note over LIB,WS: Send new speech.config only if format/voice changes
    APP->>LIB: Change format or voice
    LIB->>WS: speech.config (new JSON)
    WS-->>LIB: turn.start
    LIB->>WS: SSML for text C
    WS-->>LIB: audio bytes
    WS-->>LIB: turn.end
    LIB-->>OUT: Play audio C
    Note over LIB,WS: Close when batch done, idle, token invalid, or error
    LIB->>WS: Close
    WS-->>LIB: Close Ack
Loading

✨ Features

Core TTS Functionality

  • 🎀 High-quality speech synthesis using Microsoft Edge TTS service
  • 🌍 400+ voices across 140+ languages and locales
  • 🎡 SSML support for advanced speech control (rate, pitch, emphasis, breaks)
  • πŸ“ Multiple audio formats (MP3, WAV, OGG)
  • πŸ”„ Batch processing for multiple texts
  • ⚑ Concurrent processing for improved performance

Advanced Features

  • πŸŽ›οΈ Voice filtering and management by language, gender, and region
  • βš™οΈ Configuration management with JSON/YAML support
  • πŸ”Š Cross-platform audio playback with multiple backend support
  • πŸ›‘οΈ Comprehensive error handling and retry logic
  • πŸ“Š Performance optimization with caching and connection pooling
  • 🎯 Consistent API design across all language implementations

Developer Experience

  • πŸ“š Extensive documentation with examples and troubleshooting
  • πŸ§ͺ Unit and integration tests for reliability
  • πŸš€ Easy setup with package managers
  • πŸ”§ IDE integration support
  • πŸ“ˆ Performance benchmarking tools

πŸš€ Language Implementations

Language Async Pattern Key Libraries Strengths Best For
🐍 Python async/await edge-tts, pygame, aiofiles Rapid development, rich ecosystem Scripting, AI/ML integration, prototyping
🎯 Dart Future/async/await http, args, native audio Cross-platform, strong typing Flutter apps, web development, mobile
πŸ¦€ Rust async/await + tokio reqwest, rodio, serde Memory safety, performance System programming, high-performance apps
β˜• Java CompletableFuture HttpClient, Jackson, javax.sound Enterprise features, JVM ecosystem Enterprise applications, Android apps

Implementation Highlights

🐍 Python Implementation

  • Runtime: Python 3.7+ (3.9+ recommended)
  • Async Model: Native async/await with asyncio
  • Audio Backends: pygame (primary), playsound (fallback)
  • Unique Features: Rich CLI with argparse, extensive SSML utilities
  • Performance: Excellent for I/O-bound operations, GIL limitations for CPU-bound tasks

🎯 Dart Implementation

  • Runtime: Dart SDK 2.17+ (3.0+ recommended)
  • Async Model: Future-based with isolates support
  • Audio Backends: Platform-specific native audio
  • Unique Features: Strong null safety, Flutter integration ready
  • Performance: Fast startup, efficient memory usage, good concurrency

πŸ¦€ Rust Implementation

  • Runtime: Rust 1.60+ (1.70+ recommended)
  • Async Model: tokio runtime with zero-cost abstractions
  • Audio Backends: rodio with multiple platform backends
  • Unique Features: Memory safety, zero-cost abstractions, excellent error handling
  • Performance: Highest performance, lowest memory footprint, no GC overhead

β˜• Java Implementation

  • Runtime: Java 21+ (LTS with modern features and performance improvements)
  • Async Model: CompletableFuture with virtual threads and structured concurrency
  • Audio Backends: javax.sound.sampled (built-in)
  • Unique Features: Enterprise-grade features, extensive tooling, JVM optimization, modern Java features
  • Performance: Excellent JIT optimization, mature profiling tools, good scalability, enhanced GC

πŸš€ Quick Start

Prerequisites

  • Internet connection for TTS service access
  • Audio playback capabilities (speakers/headphones)
  • Language-specific runtime (see individual sections)

πŸ†• Recent Updates (August 2025)

  • Java Implementation: Upgraded to Java 21 LTS with enhanced performance and modern features
  • Build System: Eliminated all Maven warnings and improved JAR packaging
  • Dependencies: Updated to latest stable versions for security and performance
  • Documentation: Comprehensive guides updated with latest requirements

Choose Your Language

🐍 Python (Recommended for Beginners)

# Navigate to Python directory
cd hello-edge-tts-python
# Create virtual environment (recommended)
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Run basic example
python hello_tts.py
python hello_tts.py --text 'Hello from Python!' --voice 'en-US-JennyNeural'
python advanced_tts.py --demo ssml

🎯 Dart (Great for Cross-Platform)

# Navigate to Dart directory
cd hello-edge-tts-dart 

# Get dependencies
dart pub get

# Run basic example
dart run bin/main.dart
dart run bin/main.dart --text 'Hello from Dart!' --voice 'en-US-JennyNeural'
dart compile exe bin/main.dart -o hello_tts
./hello_tts --list-voices

πŸ¦€ Rust (Best Performance)

# Navigate to Rust directory
cd rust

# Build project
cargo build

# Run basic example
cargo run

# Try with arguments
cargo run -- --text 'Hello from Rust!' --voice 'en-US-AriaNeural'

# Build optimized release
cargo build --release
./target/release/hello-edge-tts --help

β˜• Java (Enterprise Ready - Java 21 LTS)

# Navigate to Java directory
cd hello-edge-tts-java
mvn compile

# Run basic example
mvn exec:java -Dexec.mainClass='com.example.hellotts.HelloTTS'
mvn exec:java -Dexec.mainClass='com.example.hellotts.HelloTTS' \
  -Dexec.args='--text '\''Hello from Java 21!'\'' --voice en-US-GuyNeural'
mvn package
java -jar target/hello-edge-tts-standalone.jar --help

🎯 One-Liner Examples

# Python: Quick synthesis
python python/hello_tts.py --text 'Welcome to TTS!' --output welcome.mp3

# Dart: List available voices
dart run dart/bin/main.dart --list-voices | head -20

# Rust: Batch processing
echo 'Hello\nWorld\nFrom Rust' | cargo run --manifest-path rust/Cargo.toml -- --batch

# Java: SSML example
mvn exec:java -f java/pom.xml -Dexec.args='--ssml "<speak>Hello <break time=\"1s\"/> World!</speak>"'

For detailed setup instructions and advanced usage, see the language-specific README files:

πŸ“ Project Structure

hello-edge-tts/
β”œβ”€β”€ πŸ“„ README.md                    # This comprehensive guide
β”œβ”€β”€ 🐍 hello-edge-tts-python/       # Python implementation
β”‚   β”œβ”€β”€ πŸ“„ README.md               # Python-specific documentation
β”‚   β”œβ”€β”€ 🎯 hello_tts.py            # Basic CLI application
β”‚   β”œβ”€β”€ ⚑ advanced_tts.py         # Advanced features demo
β”‚   β”œβ”€β”€ πŸ”§ tts_client.py           # Core TTS client
β”‚   β”œβ”€β”€ 🎡 audio_player.py         # Audio playback handling
β”‚   β”œβ”€β”€ πŸŽ›οΈ config.py               # Configuration management
β”‚   β”œβ”€β”€ πŸ“ ssml_examples.py        # SSML demonstrations
β”‚   └── πŸ“¦ requirements.txt        # Python dependencies
β”œβ”€β”€ 🎯 hello-edge-tts-dart/         # Dart implementation
β”‚   β”œβ”€β”€ πŸ“„ README.md               # Dart-specific documentation
β”‚   β”œβ”€β”€ πŸ“¦ pubspec.yaml            # Dart dependencies
β”‚   β”œβ”€β”€ 🎯 bin/main.dart           # CLI application
β”‚   β”œβ”€β”€ πŸ“š lib/                    # Library modules
β”‚   β”‚   β”œβ”€β”€ hello_tts.dart         # Main TTS functionality
β”‚   β”‚   β”œβ”€β”€ tts_service.dart       # TTS service implementation
β”‚   β”‚   β”œβ”€β”€ audio_player.dart      # Audio playback
β”‚   β”‚   └── config_manager.dart    # Configuration handling
β”‚   └── πŸ§ͺ test/                   # Test files
β”œβ”€β”€ πŸ¦€ hello-edge-tts-rust/         # Rust implementation
β”‚   β”œβ”€β”€ πŸ“„ README.md               # Rust-specific documentation
β”‚   β”œβ”€β”€ πŸ“¦ Cargo.toml              # Rust dependencies
β”‚   β”œβ”€β”€ 🎯 src/                    # Source code
β”‚   β”‚   β”œβ”€β”€ main.rs                # CLI application
β”‚   β”‚   β”œβ”€β”€ tts_client.rs          # TTS client implementation
β”‚   β”‚   β”œβ”€β”€ audio_player.rs        # Audio playback
β”‚   β”‚   └── config_manager.rs      # Configuration management
β”‚   └── πŸ“š examples/               # Usage examples
β”‚       β”œβ”€β”€ basic_usage.rs         # Simple examples
β”‚       β”œβ”€β”€ batch_examples.rs      # Batch processing
β”‚       └── ssml_examples.rs       # SSML demonstrations
β”œβ”€β”€ β˜• hello-edge-tts-java/         # Java implementation
β”‚   β”œβ”€β”€ πŸ“„ README.md               # Java-specific documentation
β”‚   β”œβ”€β”€ πŸ“¦ pom.xml                 # Maven configuration
β”‚   β”œβ”€β”€ 🎯 src/main/java/          # Main source code
β”‚   β”‚   └── com/example/hellotts/
β”‚   β”‚       β”œβ”€β”€ HelloTTS.java      # Main application
β”‚   β”‚       β”œβ”€β”€ TTSClient.java     # TTS client
β”‚   β”‚       β”œβ”€β”€ AudioPlayer.java   # Audio playback
β”‚   β”‚       β”œβ”€β”€ Voice.java         # Voice model
β”‚   β”‚       └── TTSConfig.java     # Configuration
β”‚   └── πŸ§ͺ src/test/java/          # Test files
β”œβ”€β”€ πŸ”§ scripts/                     # Build and utility scripts
β”‚   β”œβ”€β”€ update-dependencies.sh     # Automated dependency updates
β”‚   └── dependency-config.json     # Dependency update configuration
β”œβ”€β”€ πŸ—οΈ .github/                    # GitHub Actions and workflows
β”‚   β”œβ”€β”€ workflows/ci.yml           # CI/CD pipeline
β”‚   β”œβ”€β”€ workflows/dependency-update.yml # Automated dependency updates
β”‚   └── dependabot.yml             # Dependabot configuration
β”œβ”€β”€ πŸ› οΈ build.sh                    # Cross-platform build script
β”œβ”€β”€ πŸ“¦ Makefile                     # Make-based build automation
└── πŸš€ deploy.sh                    # Deployment script

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages