'My Uvicorn HTTP Server's Errors'
INFO:     127.0.0.1:56294 - "GET / HTTP/1.1" 404 Not Found
INFO:     127.0.0.1:56294 - "GET /favicon.ico HTTP/1.1" 404 Not Found
INFO:     127.0.0.1:56364 - "POST /generate-audio HTTP/1.1" 422 Unprocessable Entity

"My Uvicorn HTTP Server Python Script'
import torch
import torchaudio
from fastapi import FastAPI, UploadFile, File
from fastapi.responses import JSONResponse
from zonos.model import Zonos, DEFAULT_BACKBONE_CLS as ZonosBackbone
from zonos.conditioning import make_cond_dict
from zonos.utils import DEFAULT_DEVICE as device

app = FastAPI()

CURRENT_MODEL_TYPE = None
CURRENT_MODEL = None
SPEAKER_EMBEDDING = None
SPEAKER_AUDIO_PATH = None


def load_model_if_needed(model_choice: str):
    global CURRENT_MODEL_TYPE, CURRENT_MODEL
    if CURRENT_MODEL_TYPE != model_choice:
        if CURRENT_MODEL is not None:
            del CURRENT_MODEL
            torch.cuda.empty_cache()
        CURRENT_MODEL = Zonos.from_pretrained(model_choice, device=device)
        CURRENT_MODEL.requires_grad_(False).eval()
        CURRENT_MODEL_TYPE = model_choice
    return CURRENT_MODEL


@app.post("/generate-audio")
async def generate_audio(
    model_choice: str,
    text: str,
    language: str,
    emotions: list,
    vq_single: float,
    fmax: float,
    pitch_std: float,
    speaking_rate: float,
    dnsmos_ovrl: float,
    speaker_noised: bool,
    cfg_scale: float,
    min_p: float,
    seed: int,
    randomize_seed: bool,
    unconditional_keys: list,
    speaker_audio: UploadFile = File(...),
    prefix_audio: UploadFile = File(...)
):
    selected_model = load_model_if_needed(model_choice)

    # Load and process speaker audio
    global SPEAKER_EMBEDDING, SPEAKER_AUDIO_PATH

    speaker_audio_path = f"temp_speaker_audio.wav"
    with open(speaker_audio_path, "wb") as f:
        f.write(await speaker_audio.read())

    wav, sr = torchaudio.load(speaker_audio_path)
    SPEAKER_EMBEDDING = selected_model.make_speaker_embedding(wav, sr).to(device, dtype=torch.bfloat16)
    SPEAKER_AUDIO_PATH = speaker_audio_path

    # Load and process prefix audio
    prefix_audio_path = f"temp_prefix_audio.wav"
    with open(prefix_audio_path, "wb") as f:
        f.write(await prefix_audio.read())

    wav_prefix, sr_prefix = torchaudio.load(prefix_audio_path)
    wav_prefix = wav_prefix.mean(0, keepdim=True)
    wav_prefix = selected_model.autoencoder.preprocess(wav_prefix, sr_prefix).to(device, dtype=torch.float32)
    audio_prefix_codes = selected_model.autoencoder.encode(wav_prefix.unsqueeze(0))

    emotion_tensor = torch.tensor(emotions, device=device)

    cond_dict = make_cond_dict(
        text=text,
        language=language,
        speaker=SPEAKER_EMBEDDING,
        emotion=emotion_tensor,
        vqscore_8=torch.tensor([vq_single]*8, device=device).unsqueeze(0),
        fmax=fmax,
        pitch_std=pitch_std,
        speaking_rate=speaking_rate,
        dnsmos_ovrl=dnsmos_ovrl,
        speaker_noised=speaker_noised,
        device=device,
        unconditional_keys=unconditional_keys
    )
    
    conditioning = selected_model.prepare_conditioning(cond_dict)

    max_new_tokens = 86 * 30  # or derived based on the input text length

    codes = selected_model.generate(
        prefix_conditioning=conditioning,
        audio_prefix_codes=audio_prefix_codes,
        max_new_tokens=max_new_tokens,
        cfg_scale=cfg_scale,
        batch_size=1,
        sampling_params=dict(min_p=min_p),
        callback=None  # can implement progress callback if needed
    )

    wav_out = selected_model.autoencoder.decode(codes).cpu().detach().numpy()
    sr_out = selected_model.autoencoder.sampling_rate

    return JSONResponse(content={"audio": wav_out.tolist(), "sampling_rate": sr_out})

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)

'My C# Class'
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

public class LocosTTS
{
    private readonly string url;

    public LocosTTS(string url)
    {
        this.url = url;
    }

    public async Task<(bool success, string message)> GenerateAudio(
        string modelChoice,
        string text,
        string language,
        List<float> emotions,
        float vqSingle,
        float fmax,
        float pitchStd,
        float speakingRate,
        float dnsmosOvrl,
        bool speakerNoised,
        float cfgScale,
        float minP,
        int seed = 0,
        bool randomizeSeed = false,
        List<string> unconditionalKeys = null,
        byte[] speakerAudio = null,
        byte[] prefixAudio = null)
    {
        using (var client = new HttpClient())
        {
            var formContent = new MultipartFormDataContent();

            // Adding audio file parts
            if (speakerAudio != null)
            {
                var speakerContent = new ByteArrayContent(speakerAudio);
                speakerContent.Headers.ContentType = MediaTypeHeaderValue.Parse("audio/wav");
                formContent.Add(speakerContent, "speaker_audio", "speaker_audio.wav");
            }

            if (prefixAudio != null)
            {
                var prefixContent = new ByteArrayContent(prefixAudio);
                prefixContent.Headers.ContentType = MediaTypeHeaderValue.Parse("audio/wav");
                formContent.Add(prefixContent, "prefix_audio", "prefix_audio.wav");
            }

            // Adding other params as JSON
            var jsonBody = new
            {
                model_choice = modelChoice,
                text,
                language,
                emotions,
                vq_single = vqSingle,
                fmax,
                pitch_std = pitchStd,
                speaking_rate = speakingRate,
                dnsmos_ovrl = dnsmosOvrl,
                speaker_noised = speakerNoised,
                cfg_scale = cfgScale,
                min_p = minP,
                seed,
                randomizeSeed,
                unconditional_keys = unconditionalKeys
            };

            var jsonString = JsonConvert.SerializeObject(jsonBody);
            var jsonContent = new StringContent(jsonString, Encoding.UTF8, "application/json");
            formContent.Add(jsonContent, "data");

            // Send the request
            var response = await client.PostAsync(url, formContent);

            if (response.IsSuccessStatusCode)
            {
                var responseData = await response.Content.ReadAsStringAsync();
                return (true, responseData);
            }
            else
            {
                var errorMessage = await response.Content.ReadAsStringAsync();
                MessageBox.Show($"Error: {errorMessage}");
                return (false, errorMessage);
            }
        }
    }
}