Skip to content

SpongeEngine/FakeYou.NET

Repository files navigation

FakeYou.NET

NuGet NuGet Downloads License .NET Tests

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.

📦 View Package on NuGet

Features

  • 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

Installation

Install FakeYou.NET via NuGet:

dotnet add package FakeYou.NET

Quick Start

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})");
}

Audio Format

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)

Using with Different Frameworks

Unity

byte[] audioData = await client.GenerateAudioAsync(modelToken, text);

// Convert to Unity AudioClip
var audioClip = AudioClip.Create("TTS", /* samples */ ...);
audioClip.SetData(/* your conversion code */);

Godot

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

Raw Audio Processing

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}");

Advanced Usage

Custom Configuration

var client = new FakeYouClient(options =>
{
    options.ApiKey = "your_api_key";
    options.MaxRetryAttempts = 3;
    options.RetryDelay = TimeSpan.FromSeconds(2);
    options.Logger = yourLoggerInstance;
    options.ValidateResponseData = true;
});

Progress Tracking

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;
    }
};

Error Handling

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}");
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

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

Support

For issues and feature requests, please use the GitHub issues page.