DeutschLernen/GermanApp/Infrastructure/Configuration/CoquiConfig.cs
Lasse Rune Hansen 9e753d9b40 feat(backend/ai-services): Phase 3 - Model validation and setup guide
Phase 3 Tasks Completed:
- Added model directory validation to VoskService constructor
- Added configuration validation to TtsService constructor
- Added comprehensive setup instructions to VoskConfig and CoquiConfig
- Added AI Model Setup Guide to docs/features/ai-services.md with:
  - Vosk model download and setup instructions
  - Coqui TTS model download and setup instructions
  - Mistral API configuration guide
  - Verification commands
  - Troubleshooting table
- Updated appsettings.json and appsettings.Development.json with comments

All configuration is now validated on service startup with helpful error messages
that guide users to download and configure the required models.

Build: Success
Tests: 296 passing (148 unit + 148 integration)

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-06-13 10:47:02 +02:00

140 lines
4.2 KiB
C#

namespace GermanApp.Infrastructure.Configuration;
/// <summary>
/// Configuration settings for Coqui TTS service.
/// This is part of the Infrastructure layer.
///
/// Setup Instructions:
/// 1. Install Python 3.8+: https://www.python.org/downloads/
/// 2. Install Coqui TTS: pip install TTS
/// 3. Coqui will automatically download the model on first use based on ModelName
/// 4. Recommended German model: tts_models/de/deu/fairseq/vits
/// 5. Set AudioStoragePath to a directory with write permissions
///
/// Note: Models require ~1.5GB disk space. First run will download the model automatically.
/// Alternative: Pre-download with: python -m TTS.server --model_name tts_models/de/deu/fairseq/vits
/// </summary>
public class CoquiConfig
{
/// <summary>
/// Path to the Python executable.
/// Default: python3
/// </summary>
public string PythonPath { get; set; } = "python3";
/// <summary>
/// Name of the Coqui TTS model to use.
/// Example: tts_models/de/deu/fairseq/vits
/// </summary>
public string ModelName { get; set; } = "tts_models/de/deu/fairseq/vits";
/// <summary>
/// Path to the TTS Python package/module.
/// Default: TTS
/// </summary>
public string ModulePath { get; set; } = "TTS";
/// <summary>
/// Output audio format.
/// Supported: wav, mp3, ogg, flac
/// Default: wav
/// </summary>
public string OutputFormat { get; set; } = "wav";
/// <summary>
/// Output audio sample rate in Hz.
/// Default: 22050
/// </summary>
public int SampleRate { get; set; } = 22050;
/// <summary>
/// Voice speaker ID for the model.
/// Default: (empty - uses model default)
/// </summary>
public string Speaker { get; set; } = string.Empty;
/// <summary>
/// Language code for TTS.
/// Default: de
/// </summary>
public string Language { get; set; } = "de";
/// <summary>
/// Maximum text length in characters for a single TTS request.
/// Longer texts will be split.
/// Default: 500 characters
/// </summary>
public int MaxTextLength { get; set; } = 500;
/// <summary>
/// Timeout in seconds for TTS processing.
/// Default: 60 seconds
/// </summary>
public int TimeoutSeconds { get; set; } = 60;
/// <summary>
/// Path to store generated audio files.
/// Default: /var/audio/tts
/// </summary>
public string AudioStoragePath { get; set; } = "/var/audio/tts";
/// <summary>
/// Whether to use GPU acceleration if available.
/// Default: false
/// </summary>
public bool UseGPU { get; set; } = false;
/// <summary>
/// Validates the configuration.
/// </summary>
/// <exception cref="ArgumentException">Thrown when configuration is invalid</exception>
public void Validate()
{
if (string.IsNullOrWhiteSpace(PythonPath))
{
throw new ArgumentException("Coqui PythonPath is required");
}
if (string.IsNullOrWhiteSpace(ModelName))
{
throw new ArgumentException("Coqui ModelName is required");
}
if (string.IsNullOrWhiteSpace(ModulePath))
{
throw new ArgumentException("Coqui ModulePath is required");
}
if (string.IsNullOrWhiteSpace(OutputFormat))
{
throw new ArgumentException("Coqui OutputFormat is required");
}
var validFormats = new[] { "wav", "mp3", "ogg", "flac" };
if (!validFormats.Contains(OutputFormat.ToLower()))
{
throw new ArgumentException(
$"Invalid OutputFormat '{OutputFormat}'. Valid formats: {string.Join(", ", validFormats)}");
}
if (SampleRate <= 0)
{
throw new ArgumentException("SampleRate must be greater than 0");
}
if (MaxTextLength <= 0)
{
throw new ArgumentException("MaxTextLength must be greater than 0");
}
if (TimeoutSeconds <= 0)
{
throw new ArgumentException("TimeoutSeconds must be greater than 0");
}
if (string.IsNullOrWhiteSpace(AudioStoragePath))
{
throw new ArgumentException("AudioStoragePath is required");
}
}
}