this has problems all over the place please fix them just don't change naming of things ty

public async Task ConvertVocals(string selectedVoicePath, string singingVoiceFile, int qualityValue)
{
    const string outputsDir = @"C:\AI\UVR5_UI\outputs";
    const string finalOutputPath = @"C:\output\folder\NewVoice.wav";

    // Clear output directory
    foreach (var file in Directory.GetFiles(outputsDir))
    {
        try
        {
            File.Delete(file);
        }
        catch (Exception ex)
        {
            MessageBox.Show($"Failed to delete file '{file}': {ex.Message}");
        }
    }

    using var client = new HttpClient { Timeout = Timeout.InfiniteTimeSpan };

    try
    {
        // Open file streams
        using var sourceStream = File.OpenRead(singingVoiceFile);
        using var referenceStream = File.OpenRead(selectedVoicePath);

        // Create StreamContent instances
        using var sourceContent = new StreamContent(sourceStream);
        sourceContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
        {
            Name = "\"source_file\"",
            FileName = "\"source.wav\""
        };

        using var referenceContent = new StreamContent(referenceStream);
        referenceContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
        {
            Name = "\"reference_file\"",
            FileName = "\"reference.wav\""
        };

        using var form = new MultipartFormDataContent
{
    { sourceContent, "source_file", "source.wav" },
    { referenceContent, "reference_file", "reference.wav" },
    { new StringContent(qualityValue.ToString()), "diffusion_steps" },
    { new StringContent("1.0"), "length_adjust" },
    { new StringContent("0.7"), "inference_cfg_rate" },
    { new StringContent("true"), "auto_f0_adjust" },
    { new StringContent("0"), "pitch_shift" }
};

        HttpResponseMessage response = await client.PostAsync("http://localhost:6576/convert", form);

        if (!response.IsSuccessStatusCode)
        {
            MessageBox.Show($"Server error: {response.StatusCode}");
            return;
        }

        var jsonString = await response.Content.ReadAsStringAsync();
        using var jsonDoc = JsonDocument.Parse(jsonString);
        var root = jsonDoc.RootElement;

        if (!root.TryGetProperty("windows_path", out var pathElem) && !root.TryGetProperty("file_path", out pathElem))
        {
            MessageBox.Show("Server response missing 'windows_path' or 'file_path'");
            return;
        }

        string serverFilePath = pathElem.GetString();
        if (string.IsNullOrWhiteSpace(serverFilePath) || !File.Exists(serverFilePath))
        {
            MessageBox.Show("Output file from server not found.");
            return;
        }

        // Delete old vocals file (if exists)
        var oldFile = GetFirstVocalsWavFile(Path.GetDirectoryName(finalOutputPath));
        if (!string.IsNullOrEmpty(oldFile) && File.Exists(oldFile))
        {
            try
            {
                File.Delete(oldFile);
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Failed to delete old vocal file '{oldFile}': {ex.Message}");
                // Optionally return or continue depending on your logic
            }
        }

        // Also delete the file at finalOutputPath if it exists to avoid locks during copy
        if (File.Exists(finalOutputPath))
        {
            try
            {
                File.Delete(finalOutputPath);
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Failed to delete existing final output file '{finalOutputPath}': {ex.Message}");
                return;
            }
        }

        // Copy new converted vocals
        File.Copy(serverFilePath, finalOutputPath);

        MessageBox.Show($"Conversion succeeded. File saved to:\n{finalOutputPath}");

        // Short pause if really needed, consider replacing with await Task.Delay(...)
        await Task.Delay(2000);

        CombineWavs();
    }
    catch (TaskCanceledException)
    {
        MessageBox.Show("Request was canceled. It may have taken too long.");
    }
    catch (System.Text.Json.JsonException jEx)
    {
        MessageBox.Show($"Failed to parse server response: {jEx.Message}");
    }
    catch (Exception ex)
    {
        MessageBox.Show($"Error during conversion: {ex.Message}");
    }
}