EdgeTTS.DotNet is a C# (.NET) library that allows you to use Microsoft Edge's online text-to-speech service. It is a feature-complete migration of the popular Python edge-tts library, designed for performance, cross-platform compatibility, and ease of use.
- High-Quality Speech: Access Microsoft Edge's neural TTS voices for natural-sounding speech.
- Multilingual Support: Supports over 400 voices across numerous languages and regions.
- Subtitles: Generate SRT formatted subtitles from
WordBoundaryorSentenceBoundaryevents. - Customizable Prosody: Adjust speech rate, volume, and pitch to suit your needs.
- Cross-Platform: Built with .NET 10.0, fully compatible with Windows, macOS, Linux, and mobile platforms like .NET MAUI.
- Robustness: Includes built-in clock skew correction (DRM), automatic 403 retry, WebSocket compression, and comprehensive error handling.
- Voice Metadata: Access voice tags including
ContentCategoriesandVoicePersonalities.
dotnet add package EdgeTTS.DotNetSave text to an MP3 file:
using EdgeTTS.DotNet;
var request = new Communicate("Hello, world!", voice: "en-US-EmmaMultilingualNeural");
await request.SaveAsync("hello.mp3");Use the SubMaker class to create subtitles:
using EdgeTTS.DotNet;
using EdgeTTS.DotNet.Models;
var communicate = new Communicate("Hello world!", rate: "+10%", boundaryType: "WordBoundary");
var subMaker = new SubMaker();
await foreach (var chunk in communicate.StreamAsync())
{
if (chunk is AudioChunk audio)
{
// Handle audio data
}
else if (chunk is MetadataChunk metadata)
{
subMaker.Feed(metadata);
}
}
string srt = subMaker.GetSrt();
File.WriteAllText("hello.srt", srt);using EdgeTTS.DotNet;
var voices = await Voices.ListVoicesAsync();
foreach (var voice in voices)
{
Console.WriteLine($"{voice.ShortName} ({voice.Gender}) - {voice.Locale}");
Console.WriteLine($" Categories: {string.Join(", ", voice.VoiceTag.ContentCategories)}");
Console.WriteLine($" Personalities: {string.Join(", ", voice.VoiceTag.VoicePersonalities)}");
}| Option | Description | Format |
|---|---|---|
voice |
The short name of the voice (e.g., en-US-EmmaMultilingualNeural) |
String |
rate |
The speed of the speech | +0%, -50%, etc. |
volume |
The volume of the speech | +0%, -25%, etc. |
pitch |
The pitch of the speech | +0Hz, -5Hz, etc. |
boundaryType |
Type of metadata events to receive | SentenceBoundary (default) or WordBoundary |
proxy |
Proxy server for network requests | http://proxy:port |
The library provides specific exception types for robust error handling:
| Exception | Description |
|---|---|
NoAudioReceivedException |
No audio was received from the service |
UnexpectedResponseException |
Unexpected response format from the server |
UnknownResponseException |
Unknown response type received |
WebSocketException |
WebSocket connection or communication error |
SkewAdjustmentException |
Clock skew correction failed (missing server date) |
The project includes a comprehensive test suite using xUnit:
dotnet testThis project is licensed under the MIT License. See the Python project edge-tts for more details on the original implementation.