A comprehensive .NET library for Text-to-Speech synthesis with multiple providers, circuit breaker pattern, and automatic fallback support.
- Multiple TTS Providers: Azure Cognitive Services, EdgeTTS (WebSocket & HTTP), Google TTS, VoiceRSS, and Piper (offline)
- Circuit Breaker Pattern: Automatic failure detection with exponential backoff using Polly
- Provider Fallback Chain: Automatic failover to backup providers when primary fails
- Configurable Priority: Define provider priority order via configuration
- FREE Edge TTS: Direct WebSocket communication with Microsoft Edge TTS API - no API key or server required
- Offline Support: Piper provider works completely offline with ONNX neural voice models
- Voice Profiles: Configure different voice settings per use case
# Core abstractions
dotnet add package Olbrasoft.TextToSpeech.Core
# Cloud providers (Azure, EdgeTTS-HTTP, Google, VoiceRSS)
dotnet add package Olbrasoft.TextToSpeech.Providers
# EdgeTTS WebSocket (FREE - direct Microsoft API, no server)
dotnet add package Olbrasoft.TextToSpeech.Providers.EdgeTTS
# Offline Piper provider
dotnet add package Olbrasoft.TextToSpeech.Providers.Piper
# Orchestration with circuit breaker
dotnet add package Olbrasoft.TextToSpeech.Orchestration// Program.cs
using Olbrasoft.TextToSpeech.Providers.Extensions;
using Olbrasoft.TextToSpeech.Providers.Piper.Extensions;
using Olbrasoft.TextToSpeech.Orchestration.Extensions;
builder.Services.AddTtsProviders(configuration); // Azure, EdgeTTS-HTTP, Google, VoiceRSS
builder.Services.AddPiperTts(configuration); // Piper (offline)
// Optional: Add EdgeTTS WebSocket (FREE, no server needed)
builder.Services.AddSingleton<ITtsProvider, Olbrasoft.TextToSpeech.Providers.EdgeTTS.EdgeTtsProvider>();
builder.Services.AddTtsOrchestration(configuration); // Circuit breaker & fallback chain{
"TTS": {
"Orchestration": {
"Providers": [
{ "Name": "EdgeTTS-WebSocket", "Priority": 1, "Enabled": true },
{ "Name": "AzureTTS", "Priority": 2, "Enabled": true },
{ "Name": "GoogleTTS", "Priority": 3, "Enabled": true },
{ "Name": "Piper", "Priority": 4, "Enabled": true }
]
},
"EdgeTTS": {
"Voice": "cs-CZ-AntoninNeural",
"Rate": "+10%",
"Volume": "+0%",
"Pitch": "+0Hz"
},
"AzureTTS": {
"SubscriptionKey": "your-key-here",
"Region": "westeurope",
"Voice": "cs-CZ-AntoninNeural"
},
"Google": {
"Language": "cs",
"Voice": "cs-CZ-Standard-A"
},
"Piper": {
"ModelPath": "/path/to/model.onnx",
"PiperPath": "piper"
}
}
}public class SpeechService
{
private readonly ITtsProviderChain _ttsChain;
public SpeechService(ITtsProviderChain ttsChain)
{
_ttsChain = ttsChain;
}
public async Task<byte[]?> SpeakAsync(string text, CancellationToken ct = default)
{
var request = new TtsRequest
{
Text = text,
Voice = "cs-CZ-AntoninNeural",
Rate = 10, // +10%
Pitch = 0 // default
};
var result = await _ttsChain.SynthesizeAsync(request, ct);
if (result.Success)
{
Console.WriteLine($"Audio generated by: {result.ProviderUsed}");
return result.Audio?.ToArray();
}
Console.WriteLine($"TTS failed: {result.ErrorMessage}");
return null;
}
}| Provider | Type | API Key | Features |
|---|---|---|---|
| Azure Cognitive Services | Cloud API | ✅ Required | High quality neural voices, SSML support, low latency |
| EdgeTTS WebSocket | Direct API | ❌ FREE | Microsoft voices, no server needed, WebSocket communication |
| EdgeTTS HTTP | HTTP Server | ❌ FREE | Requires edge-tts-server running on localhost |
| Google TTS (gTTS) | Cloud API | ❌ FREE | Google Translate TTS, simple and reliable |
| VoiceRSS | Cloud API | ✅ Required | Free tier (350 req/day), Czech voice "Josef" |
| Piper | Local ONNX | ❌ FREE | Completely offline, privacy-friendly, custom voice models |
{
"CircuitBreaker": {
"FailureThreshold": 3,
"ResetTimeout": "00:05:00",
"UseExponentialBackoff": true,
"MaxResetTimeout": "01:00:00"
}
}A comprehensive demo console application is available in the examples/ directory:
cd examples/TextToSpeech.Demo
dotnet runFeatures:
- Interactive menu for testing all TTS providers
- Real-time timestamp in speech (proves it's not pre-recorded)
- Automatic audio playback using PipeWire/PulseAudio/ALSA
- Demonstrates automatic fallback mechanism
- No configuration required for EdgeTTS WebSocket and Google TTS
See examples/TextToSpeech.Demo/README.md for detailed documentation.
TextToSpeech/
├── src/ # Library packages (published to NuGet)
│ ├── TextToSpeech.Core/ # Core interfaces and models
│ ├── TextToSpeech.Providers/ # Cloud providers (Azure, EdgeTTS-HTTP, Google, VoiceRSS)
│ ├── TextToSpeech.Providers.EdgeTTS/ # EdgeTTS WebSocket provider
│ ├── TextToSpeech.Providers.Piper/ # Piper offline provider
│ └── TextToSpeech.Orchestration/ # Circuit breaker and fallback chain
├── tests/ # Unit tests
│ ├── TextToSpeech.Core.Tests/
│ ├── TextToSpeech.Providers.Tests/
│ └── TextToSpeech.Orchestration.Tests/
└── examples/ # Demo applications (not published)
└── TextToSpeech.Demo/ # Interactive console demo
git clone https://github.com/Olbrasoft/TextToSpeech.git
cd TextToSpeech
dotnet build
dotnet test- .NET 10.0 or later
- EdgeTTS WebSocket: No requirements - works out of the box (FREE)
- EdgeTTS HTTP: edge-tts-server running on localhost:5555 (optional)
- Piper: piper-tts binary and ONNX voice model file
- Azure/VoiceRSS: API key from respective services
MIT License - see LICENSE for details.
Jiri Tuma | Olbrasoft
Copyright 2024-2025 Olbrasoft
