optimize what you can of this and send it back

public async Task PlayAudio(InputSimulator ISim, TimeSpan duration, bool bypass, bool Combo)
{
    bool wascombo = false;
    if (Combo)
    {
        if (ChatCombo)
        {
            ChatCombo = false;
            wascombo = true;
        }
    }
    if (ChatCombo)
    {
        if (!PartyMode)
        {
            ISim.Keyboard.KeyPress(VirtualKeyCode.RETURN);
            Thread.Sleep(65);
            ISim.Keyboard.TextEntry("/team");
            Thread.Sleep(65);
            ISim.Keyboard.ModifiedKeyStroke(VirtualKeyCode.LCONTROL, VirtualKeyCode.VK_V);
            Thread.Sleep(65);
            ISim.Keyboard.KeyPress(VirtualKeyCode.RETURN);
        }
        else
        {
            ISim.Keyboard.KeyPress(VirtualKeyCode.RETURN);
            Thread.Sleep(65);
            ISim.Keyboard.TextEntry("/party");
            Thread.Sleep(65);
            ISim.Keyboard.ModifiedKeyStroke(VirtualKeyCode.LCONTROL, VirtualKeyCode.VK_V);
            Thread.Sleep(65);
            ISim.Keyboard.KeyPress(VirtualKeyCode.RETURN);
        }
    }
    if (_isPlaying)
    {
        // Cancel the previous audio task but don't end the PTT key yet
        _cancellationTokenSource.Cancel();
        _cancellationTokenSource.Dispose();
        _cancellationTokenSource = new CancellationTokenSource();
    }

    _isPlaying = true;

    try
    {
        CancellationToken token = _cancellationTokenSource.Token;

        // Check if the audio is already playing and stop it if so
        if (_waveOut != null && _waveOut.PlaybackState == PlaybackState.Playing)
        {
            _waveOut.Stop();
            _audioFileReader?.Dispose();
            _waveOut.Dispose();
        }

        // Initialize new audio playback
        _waveOut = new WaveOutEvent
        {
            DeviceNumber = OutDev,
            Volume = vol
        };
        _audioFileReader = new AudioFileReader(audioFilePath);
        _waveOut.Init(_audioFileReader);
        _waveOut.Play();

        // Handle push-to-talk key if needed
        if (!bypass)
        {
            keyToPress = PartyMode ? VirtualKeyCode.VK_0 : VirtualKeyCode.VK_9;

            if (P2T)
            {
                ISim.Keyboard.KeyDown(keyToPress);
            }
        }
        TimeSpan updatedDuration = duration.Add(TimeSpan.FromMilliseconds(200));
        // Wait for the duration of the audio clip
        await Task.Delay(updatedDuration, token);

        // After the audio clip is done, release the push-to-talk key
        if (P2T && !bypass)
        {
            ISim.Keyboard.KeyUp(keyToPress);
        }

        // Wait until playback is complete and clean up resources
        while (_waveOut.PlaybackState == PlaybackState.Playing && !token.IsCancellationRequested)
        {
            await Task.Delay(166, token);
        }

        // Clean up resources if not cancelled
        if (!token.IsCancellationRequested)
        {
            _audioFileReader?.Dispose();
            _waveOut.Stop();
            _waveOut.Dispose();
        }

        // Handle additional actions based on configuration
        if (!P2T && ConfMode && !token.IsCancellationRequested)
        {
            PlayWavFile(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\SFX\Ready.wav");
        }
        if (wascombo)
        {
            ChatCombo = true;
            wascombo = false;
        }
    }
    catch (TaskCanceledException)
    {
        // Handle any cancellation appropriately
        Console.WriteLine("Playback was cancelled.");
    }
    catch (Exception ex)
    {
        // Handle any other exceptions
        Console.WriteLine($"An error occurred: {ex.Message}");
    }
    finally
    {
        _isPlaying = false; // Reset the flag
        if (RealisticVolume)
        {
            volumeSlider1.Volume = vol;
        }
    }
}