A modern .NET client library for the FakeYou text-to-speech API. This library provides a simple, efficient, and cross-platform way to interact with FakeYou's TTS services.
- Easy-to-use API for text-to-speech generation
- Cross-platform WAV audio processing
- Built-in format conversion to 16-bit PCM
- Engine-agnostic design (works with Unity, Godot, and other frameworks)
- Configurable retry policies for improved reliability
- Full async/await support
- Comprehensive logging capabilities
- Strong type safety
Install FakeYou.NET via NuGet:
dotnet add package FakeYou.NET
using FakeYou.NET.Client;
// Create a client instance
var client = new FakeYouClient(options =>
{
options.ApiKey = "your_api_key"; // Optional
options.Timeout = TimeSpan.FromMinutes(2);
});
// Generate speech
var modelToken = "TM:1234"; // Replace with actual model token
var text = "Hello, world!";
byte[] audioData = await client.GenerateAudioAsync(modelToken, text);
// List available voice models
var models = await client.GetVoiceModelsAsync();
foreach (var model in models)
{
Console.WriteLine($"Voice: {model.Title} ({model.ModelToken})");
}
FakeYou.NET automatically handles audio format conversion. The library:
- Accepts various input formats from FakeYou API
- Automatically converts to 16-bit PCM WAV
- Preserves original sample rate (typically 32kHz, 44.1kHz, or 48kHz)
- Maintains channel configuration (mono/stereo)
byte[] audioData = await client.GenerateAudioAsync(modelToken, text);
// Convert to Unity AudioClip
var audioClip = AudioClip.Create("TTS", /* samples */ ...);
audioClip.SetData(/* your conversion code */);
byte[] audioData = await client.GenerateAudioAsync(modelToken, text);
// Convert to Godot AudioStreamWav
var stream = new AudioStreamWav();
stream.Data = audioData;
stream.Format = AudioStreamWav.FormatEnum.Format16Bits;
// Set other properties as needed
byte[] audioData = await client.GenerateAudioAsync(modelToken, text);
// Get format information
var wavProcessor = new WavProcessor();
var format = wavProcessor.GetWavFormat(audioData);
Console.WriteLine($"Sample Rate: {format.SampleRate}Hz");
Console.WriteLine($"Bits Per Sample: {format.BitsPerSample}");
Console.WriteLine($"Channels: {format.Channels}");
var client = new FakeYouClient(options =>
{
options.ApiKey = "your_api_key";
options.MaxRetryAttempts = 3;
options.RetryDelay = TimeSpan.FromSeconds(2);
options.Logger = yourLoggerInstance;
options.ValidateResponseData = true;
});
client.OnProgress += (progress) =>
{
switch (progress.State)
{
case FakeYouProgressState.Starting:
Console.WriteLine("Starting generation...");
break;
case FakeYouProgressState.Processing:
Console.WriteLine($"Processing: {progress.Message}");
break;
case FakeYouProgressState.Complete:
Console.WriteLine("Generation complete!");
break;
}
};
try
{
var audioData = await client.GenerateAudioAsync(modelToken, text);
}
catch (FakeYouException ex)
{
Console.WriteLine($"FakeYou API error: {ex.Message}");
if (ex.StatusCode.HasValue)
{
Console.WriteLine($"Status code: {ex.StatusCode}");
}
}
catch (Exception ex)
{
Console.WriteLine($"General error: {ex.Message}");
}
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
Please see CONTRIBUTING.md for details on:
- How to publish to NuGet
- Development guidelines
- Code style
- Testing requirements
- Pull request process
For issues and feature requests, please use the GitHub issues page.