'my c# code'
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

public class TTSClient
{
    private string Url { get; }
    private string Text { get; }
    private string ApiKey { get; }
    private string Format { get; }
    private int ChunkLength { get; }
    private float TopP { get; }
    private float Temperature { get; }
    private int? Seed { get; }
    private int MaxNewTokens { get; }
    private float RepetitionPenalty { get; }
    private List<string> ReferenceTexts { get; }
    private List<byte[]> ReferenceAudios { get; }
    private readonly HttpClient HttpClient;

    public TTSClient(
        string url,
        string text,
        string apiKey,
        List<string> referenceTexts,
        List<byte[]> referenceAudios,
        string format = "wav",
        int chunkLength = 200,
        float topP = 0.7f,
        float temperature = 0.7f,
        int? seed = null,
        int maxNewTokens = 1024,
        float repetitionPenalty = 1.2f)
    {
        Url = url ?? throw new ArgumentNullException(nameof(url));
        Text = text ?? throw new ArgumentNullException(nameof(text));
        ApiKey = apiKey ?? throw new ArgumentNullException(nameof(apiKey));
        ReferenceTexts = referenceTexts ?? throw new ArgumentNullException(nameof(referenceTexts));
        ReferenceAudios = referenceAudios ?? throw new ArgumentNullException(nameof(referenceAudios));
        Format = format;
        ChunkLength = chunkLength;
        TopP = topP;
        Temperature = temperature;
        Seed = seed;
        MaxNewTokens = maxNewTokens;
        RepetitionPenalty = repetitionPenalty;
        HttpClient = new HttpClient { DefaultRequestHeaders = { Authorization = new AuthenticationHeaderValue("Bearer", ApiKey) } };
    }

    public async Task<(bool success, string message)> SendRequestAndSaveAudio()
    {
        var referenceObjects = CreateReferenceObjects();
        var data = CreateRequestData(referenceObjects);
        var jsonData = JsonSerializer.Serialize(data);
        var content = new StringContent(jsonData, Encoding.UTF8, "application/json");

        HttpResponseMessage response = await HttpClient.PostAsync(Url, content);
        return response.IsSuccessStatusCode
            ? await SaveAudioAndReturnResult(response)
            : await HandleError(response);
    }

    private List<object> CreateReferenceObjects()
    {
        var referenceObjects = new List<object>();

        for (int i = 0; i < ReferenceTexts.Count; i++)
        {
            var referenceObject = new
            {
                text = ReferenceTexts[i],
                audio = ReferenceAudios[i] != null ? Convert.ToBase64String(ReferenceAudios[i]) : null
            };
            referenceObjects.Add(referenceObject);
        }

        return referenceObjects;
    }

    private object CreateRequestData(List<object> referenceObjects)
    {
        return new
        {
            text = Text,
            references = referenceObjects,
            normalize = false,
            format = Format,
            max_new_tokens = MaxNewTokens,
            chunk_length = ChunkLength,
            top_p = TopP,
            repetition_penalty = RepetitionPenalty,
            temperature = Temperature,
            streaming = false,
            use_memory_cache = "on",
            seed = Seed
        };
    }

    private async Task<(bool success, string message)> SaveAudioAndReturnResult(HttpResponseMessage response)
    {
        var audioPath = $@"C:\Users\DjZaN\OneDrive\Desktop\FP\output.{Format}";
        try
        {
            if (File.Exists(audioPath))
            {
                File.Delete(audioPath);
            }
        }
        catch
        {
        }
        var responseContent = await response.Content.ReadAsByteArrayAsync();
        await File.WriteAllBytesAsync(audioPath, responseContent);

        return (true, audioPath);
    }

    private async Task<(bool success, string message)> HandleError(HttpResponseMessage response)
    {
        try
        {
            var errorContent = await response.Content.ReadAsStringAsync();
            return (false, $"{response.StatusCode}: {errorContent}");
        }
        catch (Exception ex)
        {
            // Ideally log the exception here
            return (false, $"An error occurred while processing the response: {ex.Message}");
        }
    }
}

'my python code'