Make this have way better graphics and visuals return entir ecode

using Kane.GlobalHook;
using NAudio.Wave;
using WindowsInput;
using WindowsInput.Native;
using Clowd.Clipboard;
using System.Net.Http.Headers;
using System.Diagnostics;
using Newtonsoft.Json;
using System.Text;
using OllamaSharp;
using System.Security.Cryptography;
using System.Threading.Tasks;
using System.Text.Json;
using System.Media;

namespace ByteBreath
{
    public partial class Form1 : Form
    {
        int seedCount = 0;
        public bool ISeed = false;
        public bool IndexTTSBool = false;
        public bool UseChatbox = false;
        public static string Texting;
        ChatBox chatBox;
        DataSetMaker dataSetMaker;
        Form2 RecentPlayaz;
        AudioEditorForm audioEditorForm;
        bool SpeechToText = false;
        bool LongerGenMode = false;
        bool TranslationMode = false;
        string MainModel = string.Empty;
        string TranslationModel = string.Empty;
        string SpellCheckModel = string.Empty;
        string TranslationLang = string.Empty;
        bool spellcheck = false;
        string MyOutput = string.Empty;
        private Uri OllamaURI;
        public OllamaApiClient OllamaClient;
        string cacheDir = string.Empty;
        bool cacheout = false;
        private float targetOpacity = 0.97f; // maximum opacity (100%)
        private float opacityStep = 0.10f; // change this to adjust speed
        public List<string> CurrentPresets;
        public List<string> UncondKeys;
        bool Male = true;
        bool CanSkip = false;
        string VoiceIDBCK;
        string[] KeyStrings = new string[28];
        // MAIN DECLAR SECTION // // MAIN DECLAR SECTION // // MAIN DECLAR SECTION // // MAIN DECLAR SECTION // 
        private const string Quote = "\"";
        bool ConstructiveTokens = false;
        private static WaveOutEvent _waveOut;
        private static AudioFileReader _audioFileReader;
        private WaveInEvent waveSource;
        private WaveFileWriter waveFile;
        private bool AutoP2T = false;
        int PrevHack = 0;
        private bool ChatCombo = false;
        public bool P2T = true;
        private bool Recording = false;
        private bool TopBool = false;
        bool ConstructiveChunks = false;
        public bool PartyMode = false;
        public InputSimulator ISim = new InputSimulator();
        public TimeSpan duration;
        string audioFilePath = string.Empty;
        string outputFilePath = @"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\Process\Recording.wav";
        KeyboardHook keyboardHook = new KeyboardHook();
        public static string liveText;
        string Reference_Voice;
        string Reference_Text;
        List<byte[]> cat;
        int Max_Tokens = 0;
        int Chunk_Length = 200;
        float Top_P = 0.7f;
        float Repetition_Penalty = 1.1f;
        float Temperature = 0.7f;
        int Seed = 0;
        string GlobalOutput;
        private string RefAudioFile;
        private static readonly HttpClient client = new HttpClient();
        float vol;
        public int OutDev;
        bool numTog = false;
        bool DeleteTriggered = false;
        bool RealisticVolume = false;
        public bool ReuseSeed = false;
        private static readonly HttpClient clientseed = new HttpClient();
        bool enterPressed = false;
        string backup = string.Empty;
        bool ConfMode = false;
        public bool FishSpeechMode = false;
        public bool ZonosTTSMode = false;
        public bool Speaker_Prefix = false;
        Point PE1 = new Point(3, 215);
        Point PE2 = new Point(196, 215);
        Point PE3 = new Point(3, 227);
        bool Search = false;
        VirtualKeyCode keyToPress;
        //NUMPADSHIT
        bool runonce = false;
        int Num_Slash = 1;
        int Num_Multi = 2;
        int Num_Sub = 3;
        int Num_7 = 4;
        int Num_8 = 5;
        int Num_9 = 6;
        int Num_Plus = 7;
        int Num_4 = 8;
        int Num_5 = 9;
        int Num_6 = 10;
        int Num_1 = 11;
        int Num_2 = 12;
        int Num_3 = 13;
        int Num_0 = 14;
        int F5_Key = 15;
        int F6_Key = 0;
        int F7_Key = 16;
        int F8_Key = 17;
        int F9_Key = 18;
        int F10_Key = 19;
        int F11_Key = 20;
        int F12_Key = 21;
        int F3_Key = 22;
        int F4_Key = 23;
        int F1_Key = 24;
        int F2_Key = 25;
        int OMinus = 26;
        int OPlus = 27;
        //NUMPADSHIT
        // MAIN DECLAR SECTION // // MAIN DECLAR SECTION // // MAIN DECLAR SECTION // // MAIN DECLAR SECTION // 

        private static readonly HttpClient httpClient = new HttpClient();

        private Random _rand = new Random();

        private Color _lastMainStart;
        private Color _lastMainEnd;
        private Color _lastAccentsStart;
        private Color _lastAccentsEnd;
        private Color _lastTextColor;

        private Color RandomColor(int min = 0, int max = 255)
        {
            return Color.FromArgb(
                255,
                _rand.Next(min, max + 1),
                _rand.Next(min, max + 1),
                _rand.Next(min, max + 1));
        }

        private Color RandomVibrantColor()
        {
            // Generate a vibrant color with high saturation and brightness via HSV conversion
            double hue = _rand.NextDouble() * 360; // Hue between 0-360
            double saturation = _rand.NextDouble() * 0.5 + 0.5; // Saturation between 0.5-1.0
            double value = _rand.NextDouble() * 0.5 + 0.7;      // Brightness between 0.7-1.0
            return ColorFromHSV(hue, saturation, value);
        }

        private Color ColorFromHSV(double hue, double saturation, double value)
        {
            int hi = Convert.ToInt32(Math.Floor(hue / 60)) % 6;
            double f = hue / 60 - Math.Floor(hue / 60);

            value = Math.Max(0, Math.Min(1, value));       // clamp value to [0,1]
            saturation = Math.Max(0, Math.Min(1, saturation)); // clamp saturation to [0,1]
            hue = hue % 360;                               // hue in [0,360)

            int v = Clamp((int)(value * 255), 0, 255);
            int p = Clamp((int)(v * (1 - saturation)), 0, 255);
            int q = Clamp((int)(v * (1 - f * saturation)), 0, 255);
            int t = Clamp((int)(v * (1 - (1 - f) * saturation)), 0, 255);

            return hi switch
            {
                0 => Color.FromArgb(255, v, t, p),
                1 => Color.FromArgb(255, q, v, p),
                2 => Color.FromArgb(255, p, v, t),
                3 => Color.FromArgb(255, p, q, v),
                4 => Color.FromArgb(255, t, p, v),
                _ => Color.FromArgb(255, v, p, q),
            };
        }

        private Color DarkenColor(Color color, float factor)
        {
            int r = (int)(color.R * (1 - factor));
            int g = (int)(color.G * (1 - factor));
            int b = (int)(color.B * (1 - factor));
            return Color.FromArgb(255, Clamp(r, 0, 255), Clamp(g, 0, 255), Clamp(b, 0, 255));
        }

        private int Clamp(int val, int min, int max) => val < min ? min : (val > max ? max : val);

        public void CheckInstalls()
        {
            bool gitInstalled = IsProgramInstalled("git", "--version");
            bool condaInstalled = IsProgramInstalled("conda", "--version");

            MessageBox.Show($"Git installed: {gitInstalled}");
            MessageBox.Show($"Conda installed: {condaInstalled}");
        }

        private bool IsProgramInstalled(string command, string args)
        {
            try
            {
                ProcessStartInfo startInfo = new ProcessStartInfo
                {
                    FileName = command,
                    Arguments = args,
                    RedirectStandardOutput = true,
                    RedirectStandardError = true,
                    UseShellExecute = false,
                    CreateNoWindow = true,
                };

                using (Process process = Process.Start(startInfo))
                {
                    process.WaitForExit(3000);  // Wait max 3 seconds
                    string output = process.StandardOutput.ReadToEnd();
                    string error = process.StandardError.ReadToEnd();

                    if (process.ExitCode == 0)
                    {
                        // Optionally check output contains version info or expected text
                        return true;
                    }
                }
            }
            catch (Exception)
            {
                // Could not start process, assumed not installed
            }

            return false;
        }

        private enum ThemeStyle
        {
            Classic,
            Vibrant,
            Epic,
            Neon,
            Pastel,
            DarkGlow,
            Oceanic,
            Sunset,
            Cyberpunk,
            Forest,
            Retro,
            Metallic,
            Candy,
            Space,
            Vintage,
            Aurora,
            PrismBurst,
            TechnoWave,
            SolarFlare,
            ElectricDream,
            MysticRainbow,
            TwilightPulse
        }

        private static int SafeRandomRange(Random rand, int minValue, int maxValue)
        {
            if (minValue > maxValue)
            {
                var temp = minValue;
                minValue = maxValue;
                maxValue = temp;
            }
            return rand.Next(minValue, maxValue + 1);
        }

        private Color RandomHueColor(int hMin, int hMax, double sMin, double sMax, double vMin, double vMax)
        {
            int hue = SafeRandomRange(_rand, hMin, hMax);
            double saturation = _rand.NextDouble() * (sMax - sMin) + sMin;
            double value = _rand.NextDouble() * (vMax - vMin) + vMin;
            return ColorFromHSV(hue, saturation, value);
        }

        private List<Color> GenerateUniqueColorsDistinct(int count, double sMin, double sMax, double vMin, double vMax)
        {
            var colors = new List<Color>();
            var usedHues = new HashSet<int>();
            int attempts = 0;

            int minHueDist = 360 / (count + 1);
            int baseHue = _rand.Next(0, 360);

            while (colors.Count < count && attempts < 10000)
            {
                int hue = (baseHue + colors.Count * minHueDist + _rand.Next(-minHueDist / 3, minHueDist / 3)) % 360;
                if (usedHues.Any(h => Math.Abs(h - hue) < minHueDist / 2 || Math.Abs(h - hue) > 360 - minHueDist / 2))
                {
                    attempts++;
                    baseHue = _rand.Next(0, 360);
                    continue;
                }
                usedHues.Add(hue);

                double sat = _rand.NextDouble() * (sMax - sMin) + sMin;
                double val = _rand.NextDouble() * (vMax - vMin) + vMin;
                Color c = ColorFromHSV(hue, sat, val);
                colors.Add(c);
                attempts++;
            }

            // If not enough unique, fill with random colors anyway
            while (colors.Count < count)
                colors.Add(RandomHueColor(0, 360, sMin, sMax, vMin, vMax));

            return colors;
        }

        private Color GenerateUniqueLightColorExcluding(List<Color> exclude)
        {
            int attempts = 0;
            while (attempts < 1000)
            {
                double hue = _rand.NextDouble() * 360;
                double saturation = _rand.NextDouble() * 0.3 + 0.2;
                double value = _rand.NextDouble() * 0.4 + 0.6;
                Color c = ColorFromHSV(hue, saturation, value);

                bool isUnique = true;
                foreach (var ex in exclude)
                {
                    if (Math.Abs(ex.R - c.R) < 15 && Math.Abs(ex.G - c.G) < 15 && Math.Abs(ex.B - c.B) < 15)
                    {
                        isUnique = false;
                        break;
                    }
                }

                if (isUnique)
                    return c;

                attempts++;
            }

            return Color.White;
        }

        private void GenerateRandomTheme(bool reapply = false)
        {
            if (!reapply || _lastMainStart == Color.Empty)
            {
                var styles = Enum.GetValues(typeof(ThemeStyle)).Cast<ThemeStyle>().ToList();

                // Shuffle styles for better random distribution
                for (int i = styles.Count - 1; i > 0; i--)
                {
                    int j = _rand.Next(i + 1);
                    (styles[i], styles[j]) = (styles[j], styles[i]);
                }
                var style = styles[0];

                switch (style)
                {
                    case ThemeStyle.Classic:
                        _lastMainStart = RandomHueColor(15, 45, 0.6, 0.8, 0.6, 0.9);
                        _lastMainEnd = RandomHueColor(35, 55, 0.7, 0.9, 0.7, 1.0);
                        _lastAccentsStart = RandomHueColor(150, 180, 0.5, 0.7, 0.6, 0.9);
                        _lastAccentsEnd = RandomHueColor(180, 210, 0.5, 0.7, 0.6, 0.9);
                        _lastTextColor = ColorFromHSV(0, 0, 0.1);
                        break;

                    case ThemeStyle.Vibrant:
                        {
                            var bases = GenerateUniqueColorsDistinct(5, 0.8, 1.0, 0.7, 0.9);
                            _lastMainStart = bases[0];
                            _lastMainEnd = bases[1];
                            _lastAccentsStart = bases[2];
                            _lastAccentsEnd = bases[3];
                            _lastTextColor = bases[4].GetBrightness() < 0.5 ? Color.White : Color.Black;
                        }
                        break;

                    case ThemeStyle.Epic:
                        _lastMainStart = RandomHueColor(0, 360, 0.75, 0.95, 0.1, 0.3);
                        _lastMainEnd = RandomHueColor(0, 360, 0.75, 0.95, 0.4, 0.6);
                        _lastAccentsStart = RandomHueColor(0, 360, 0.85, 1.0, 0.8, 1.0);
                        _lastAccentsEnd = RandomHueColor(0, 360, 0.65, 0.85, 0.6, 0.85);
                        _lastTextColor = Color.WhiteSmoke;
                        break;

                    case ThemeStyle.Neon:
                        _lastMainStart = Color.Black;
                        _lastMainEnd = ColorFromHSV(SafeRandomRange(_rand, 280, 320), 0.85, 0.3);
                        _lastAccentsStart = ColorFromHSV(SafeRandomRange(_rand, 150, 190), 0.95, 0.9);
                        _lastAccentsEnd = ColorFromHSV(SafeRandomRange(_rand, 200, 240), 0.9, 0.8);
                        _lastTextColor = Color.White;
                        break;

                    case ThemeStyle.Pastel:
                        {
                            var pastels = GenerateUniqueColorsDistinct(5, 0.25, 0.4, 0.85, 1.0);
                            _lastMainStart = pastels[0];
                            _lastMainEnd = pastels[1];
                            _lastAccentsStart = pastels[2];
                            _lastAccentsEnd = pastels[3];
                            _lastTextColor = pastels[4].GetBrightness() > 0.7 ? Color.FromArgb(255, 50, 50, 50) : Color.WhiteSmoke;
                        }
                        break;

                    case ThemeStyle.DarkGlow:
                        {
                            var darks = GenerateUniqueColorsDistinct(4, 0.7, 1.0, 0.05, 0.25);
                            _lastMainStart = darks[0];
                            _lastMainEnd = darks[1];
                            _lastAccentsStart = darks[2];
                            _lastAccentsEnd = darks[3];
                            _lastTextColor = GenerateUniqueLightColorExcluding(darks);
                        }
                        break;

                    case ThemeStyle.Oceanic:
                        {
                            var ocean = GenerateUniqueColorsDistinct(5, 0.6, 0.85, 0.4, 0.7);
                            for (int i = 0; i < ocean.Count; i++)
                            {
                                double h, s, v;
                                ColorToHSV(ocean[i], out h, out s, out v);
                                h = (h + 160) % 360;
                                ocean[i] = ColorFromHSV(h, s, v);
                            }
                            _lastMainStart = ocean[0];
                            _lastMainEnd = ocean[1];
                            _lastAccentsStart = ocean[2];
                            _lastAccentsEnd = ocean[3];
                            _lastTextColor = ocean[4].GetBrightness() < 0.5 ? Color.White : Color.Black;
                        }
                        break;

                    case ThemeStyle.Sunset:
                        {
                            var sunset = GenerateUniqueColorsDistinct(5, 0.6, 0.9, 0.4, 0.7);
                            for (int i = 0; i < sunset.Count; i++)
                            {
                                double h, s, v;
                                ColorToHSV(sunset[i], out h, out s, out v);
                                h = (h + 35) % 60 + 10;
                                sunset[i] = ColorFromHSV(h, s, v);
                            }
                            _lastMainStart = sunset[0];
                            _lastMainEnd = sunset[1];
                            _lastAccentsStart = sunset[2];
                            _lastAccentsEnd = sunset[3];
                            _lastTextColor = sunset[4].GetBrightness() < 0.5 ? Color.White : Color.Black;
                        }
                        break;

                    case ThemeStyle.Cyberpunk:
                        {
                            var cyber = GenerateUniqueColorsDistinct(5, 0.75, 1.0, 0.05, 0.35);
                            double[] cyberHueTargets = { 270, 300, 210, 240, 280 };
                            for (int i = 0; i < cyberHueTargets.Length; i++)
                            {
                                if (i < cyber.Count)
                                {
                                    double h, s, v;
                                    ColorToHSV(cyber[i], out h, out s, out v);
                                    h = cyberHueTargets[i];
                                    cyber[i] = ColorFromHSV(h, s, v);
                                }
                            }
                            _lastMainStart = cyber[0];
                            _lastMainEnd = cyber[1];
                            _lastAccentsStart = cyber[2];
                            _lastAccentsEnd = cyber[3];
                            _lastTextColor = cyber[4].GetBrightness() < 0.5 ? Color.White : Color.Black;
                        }
                        break;

                    case ThemeStyle.Forest:
                        {
                            var forest = GenerateUniqueColorsDistinct(5, 0.5, 0.8, 0.3, 0.55);
                            for (int i = 0; i < forest.Count; i++)
                            {
                                double h, s, v;
                                ColorToHSV(forest[i], out h, out s, out v);
                                h = (h + 90) % 140 + 40;
                                forest[i] = ColorFromHSV(h, s, v);
                            }
                            _lastMainStart = forest[0];
                            _lastMainEnd = forest[1];
                            _lastAccentsStart = forest[2];
                            _lastAccentsEnd = forest[3];
                            _lastTextColor = forest[4].GetBrightness() > 0.7 ? Color.FromArgb(255, 20, 20, 20) : Color.White;
                        }
                        break;

                    case ThemeStyle.Retro:
                        {
                            var retro = GenerateUniqueColorsDistinct(5, 0.4, 0.7, 0.3, 0.6);
                            double[] retroHueTargets = { 290, 20, 40, 30, 350 };
                            for (int i = 0; i < retroHueTargets.Length; i++)
                            {
                                if (i < retro.Count)
                                {
                                    double h, s, v;
                                    ColorToHSV(retro[i], out h, out s, out v);
                                    h = retroHueTargets[i];
                                    retro[i] = ColorFromHSV(h, s, v);
                                }
                            }
                            _lastMainStart = retro[0];
                            _lastMainEnd = retro[1];
                            _lastAccentsStart = retro[2];
                            _lastAccentsEnd = retro[3];
                            _lastTextColor = retro[4].GetBrightness() < 0.5 ? Color.White : Color.Black;
                        }
                        break;

                    case ThemeStyle.Metallic:
                        {
                            var metallic = GenerateUniqueColorsDistinct(5, 0.05, 0.15, 0.3, 0.55);
                            for (int i = 0; i < metallic.Count; i++)
                            {
                                double h, s, v;
                                ColorToHSV(metallic[i], out h, out s, out v);
                                s *= 0.1;
                                metallic[i] = ColorFromHSV(h, s, v);
                            }
                            _lastMainStart = metallic[0];
                            _lastMainEnd = metallic[1];
                            _lastAccentsStart = metallic[2];
                            _lastAccentsEnd = metallic[3];
                            _lastTextColor = metallic[4].GetBrightness() < 0.5 ? Color.White : Color.Black;
                        }
                        break;

                    case ThemeStyle.Candy:
                        {
                            var candy = GenerateUniqueColorsDistinct(5, 0.7, 0.95, 0.7, 1.0);
                            double[] candyHueTargets = { 320, 350, 330, 310, 300 };
                            for (int i = 0; i < candyHueTargets.Length; i++)
                            {
                                if (i < candy.Count)
                                {
                                    double h, s, v;
                                    ColorToHSV(candy[i], out h, out s, out v);
                                    h = candyHueTargets[i];
                                    candy[i] = ColorFromHSV(h, s, v);
                                }
                            }
                            _lastMainStart = candy[0];
                            _lastMainEnd = candy[1];
                            _lastAccentsStart = candy[2];
                            _lastAccentsEnd = candy[3];
                            _lastTextColor = candy[4].GetBrightness() < 0.5 ? Color.White : Color.Black;
                        }
                        break;

                    case ThemeStyle.Space:
                        {
                            var space = GenerateUniqueColorsDistinct(5, 0.7, 0.9, 0.05, 0.35);
                            double[] spaceHueTargets = { 240, 260, 250, 220, 280 };
                            for (int i = 0; i < spaceHueTargets.Length; i++)
                            {
                                if (i < space.Count)
                                {
                                    double h, s, v;
                                    ColorToHSV(space[i], out h, out s, out v);
                                    h = spaceHueTargets[i];
                                    space[i] = ColorFromHSV(h, s, v);
                                }
                            }
                            _lastMainStart = space[0];
                            _lastMainEnd = space[1];
                            _lastAccentsStart = space[2];
                            _lastAccentsEnd = space[3];
                            _lastTextColor = space[4].GetBrightness() < 0.5 ? Color.White : Color.Black;
                        }
                        break;

                    case ThemeStyle.Vintage:
                        {
                            var vintage = GenerateUniqueColorsDistinct(5, 0.4, 0.65, 0.3, 0.55);
                            double[] vintageHueTargets = { 40, 50, 30, 20, 10 };
                            for (int i = 0; i < vintageHueTargets.Length; i++)
                            {
                                if (i < vintage.Count)
                                {
                                    double h, s, v;
                                    ColorToHSV(vintage[i], out h, out s, out v);
                                    h = vintageHueTargets[i];
                                    vintage[i] = ColorFromHSV(h, s, v);
                                }
                            }
                            _lastMainStart = vintage[0];
                            _lastMainEnd = vintage[1];
                            _lastAccentsStart = vintage[2];
                            _lastAccentsEnd = vintage[3];
                            _lastTextColor = vintage[4].GetBrightness() < 0.5 ? Color.White : Color.Black;
                        }
                        break;

                    case ThemeStyle.Aurora:
                        {
                            var aurora = GenerateUniqueColorsDistinct(5, 0.7, 1.0, 0.25, 0.55);
                            double[] auroraHueTargets = { 150, 180, 130, 220, 200 };
                            for (int i = 0; i < auroraHueTargets.Length; i++)
                            {
                                if (i < aurora.Count)
                                {
                                    double h, s, v;
                                    ColorToHSV(aurora[i], out h, out s, out v);
                                    h = auroraHueTargets[i];
                                    aurora[i] = ColorFromHSV(h, s, v);
                                }
                            }
                            _lastMainStart = aurora[0];
                            _lastMainEnd = aurora[1];
                            _lastAccentsStart = aurora[2];
                            _lastAccentsEnd = aurora[3];
                            _lastTextColor = aurora[4].GetBrightness() < 0.5 ? Color.White : Color.Black;
                        }
                        break;

                    case ThemeStyle.PrismBurst:
                        {
                            var baseColors = GenerateUniqueColorsDistinct(5, 0.8, 1.0, 0.7, 1.0);
                            _lastMainStart = baseColors[0];
                            _lastMainEnd = baseColors[1];
                            _lastAccentsStart = baseColors[2];
                            _lastAccentsEnd = baseColors[3];
                            _lastTextColor = baseColors[4].GetBrightness() < 0.4 ? Color.White : Color.Black;
                        }
                        break;

                    case ThemeStyle.TechnoWave:
                        {
                            _lastMainStart = ColorFromHSV(_rand.Next(200, 240), 0.95, 0.1);
                            _lastMainEnd = ColorFromHSV(_rand.Next(220, 260), 0.95, 0.3);
                            _lastAccentsStart = ColorFromHSV(_rand.Next(280, 320), 0.9, 0.8);
                            _lastAccentsEnd = ColorFromHSV(_rand.Next(300, 340), 0.9, 0.9);
                            _lastTextColor = Color.White;
                        }
                        break;

                    case ThemeStyle.SolarFlare:
                        {
                            _lastMainStart = ColorFromHSV(_rand.Next(10, 40), 0.9, 0.3);
                            _lastMainEnd = ColorFromHSV(_rand.Next(20, 50), 0.9, 0.5);
                            _lastAccentsStart = ColorFromHSV(_rand.Next(30, 60), 1.0, 0.95);
                            _lastAccentsEnd = ColorFromHSV(_rand.Next(15, 45), 1.0, 0.85);
                            _lastTextColor = Color.FromArgb(255, 30, 30, 30);
                        }
                        break;

                    case ThemeStyle.ElectricDream:
                        {
                            var colors = GenerateUniqueColorsDistinct(5, 0.5, 0.85, 0.6, 0.85);
                            double[] targetHues = { 280, 190, 320, 350, 300 };
                            for (int i = 0; i < targetHues.Length; i++)
                            {
                                if (i < colors.Count)
                                {
                                    double h, s, v;
                                    ColorToHSV(colors[i], out h, out s, out v);
                                    h = targetHues[i];
                                    colors[i] = ColorFromHSV(h, s, v);
                                }
                            }
                            _lastMainStart = colors[0];
                            _lastMainEnd = colors[1];
                            _lastAccentsStart = colors[2];
                            _lastAccentsEnd = colors[3];
                            _lastTextColor = colors[4].GetBrightness() < 0.5 ? Color.WhiteSmoke : Color.Black;
                        }
                        break;

                    case ThemeStyle.MysticRainbow:
                        {
                            _lastMainStart = ColorFromHSV(_rand.Next(0, 360), 0.2, 0.15);
                            _lastMainEnd = ColorFromHSV((_rand.Next(0, 360) + 180) % 360, 0.3, 0.25);
                            var accents = GenerateUniqueColorsDistinct(3, 0.85, 1.0, 0.8, 1.0);
                            _lastAccentsStart = accents[0];
                            _lastAccentsEnd = accents[1];
                            _lastTextColor = accents[2].GetBrightness() < 0.5 ? Color.White : Color.Black;
                        }
                        break;

                    case ThemeStyle.TwilightPulse:
                        {
                            _lastMainStart = ColorFromHSV(_rand.Next(250, 280), 0.6, 0.45);
                            _lastMainEnd = ColorFromHSV(_rand.Next(230, 260), 0.65, 0.6);
                            _lastAccentsStart = ColorFromHSV(_rand.Next(310, 350), 0.9, 0.95);
                            _lastAccentsEnd = ColorFromHSV(_rand.Next(270, 310), 0.9, 0.8);
                            _lastTextColor = Color.FromArgb(255, 240, 240, 250);
                        }
                        break;
                }
            }

            Theme(_lastMainStart, _lastMainEnd, _lastAccentsStart, _lastAccentsEnd, _lastTextColor);
        }

        // Helper method to convert Color to HSV (Hue, Saturation, Value)
        private void ColorToHSV(Color color, out double hue, out double saturation, out double value)
        {
            double r = color.R / 255.0;
            double g = color.G / 255.0;
            double b = color.B / 255.0;

            double max = Math.Max(r, Math.Max(g, b));
            double min = Math.Min(r, Math.Min(g, b));

            hue = 0;
            saturation = (max == 0) ? 0 : (max - min) / max;
            value = max;

            if (max == min)
            {
                hue = 0; // undefined
            }
            else if (max == r)
            {
                hue = 60 * ((g - b) / (max - min));
            }
            else if (max == g)
            {
                hue = 60 * (2 + (b - r) / (max - min));
            }
            else if (max == b)
            {
                hue = 60 * (4 + (r - g) / (max - min));
            }

            if (hue < 0)
                hue += 360;
        }

        private void Theme(Color mainStart, Color mainEnd, Color accentsStart, Color accentsEnd, Color textcolor)
        {
            void SetGradient(Control control, Color startColor, Color endColor)
            {
                if (control == null || control.Width == 0 || control.Height == 0)
                    return;

                Bitmap bmp = new Bitmap(control.Width, control.Height);
                using (Graphics g = Graphics.FromImage(bmp))
                {
                    using (var brush = new System.Drawing.Drawing2D.LinearGradientBrush(
                        new Rectangle(0, 0, bmp.Width, bmp.Height),
                        startColor,
                        endColor,
                        System.Drawing.Drawing2D.LinearGradientMode.Vertical))
                    {
                        g.FillRectangle(brush, 0, 0, bmp.Width, bmp.Height);
                    }
                }
                control.BackgroundImage = bmp;
                control.BackgroundImageLayout = ImageLayout.Stretch;
            }

            Color GetContrastingTextColor(Color background, Color fallback)
            {
                double luminance = (0.2126 * background.R + 0.7152 * background.G + 0.0722 * background.B) / 255;

                if (luminance > 0.7)
                    return Color.FromArgb(255, 30, 30, 30);
                else if (luminance < 0.15)
                    return Color.White;
                else
                    return fallback;
            }

            // Clear all backgrounds and images first

            var allPanels = new Panel[]
            {
        panel1, panel2, panel3, panel4, panel5, panel6, panel7, panel8, panel9, panel10, indexpnl
            };
            foreach (var pnl in allPanels)
            {
                if (pnl != null)
                {
                    pnl.BackgroundImage = null;
                    pnl.BackColor = Color.Transparent;
                }
            }

            var labels = new Label[]
            {
        label1, label2, label3, label4, label5, label6, label7, label8,
        label9, label10, label11, label12, label13, label14, label15,
        label16, label17, label18, label19, label20, label21, label22,
        label23, label24, label25, label26, label27, label28, label29,
        label30, label31, label32, label33, label34, label35, label36,
        label41, MyLink
            };
            foreach (var lbl in labels)
            {
                if (lbl != null)
                {
                    lbl.BackgroundImage = null;
                    lbl.BackColor = Color.Transparent;
                }
            }

            var pictures = new PictureBox[]
            {
        pictureBox1, pictureBox2, pictureBox3, pictureBox4, pictureBox5,
        pictureBox6, pictureBox7, pictureBox8, pictureBox9, pictureBox10, OffMap
            };
            foreach (var pb in pictures)
            {
                if (pb != null)
                {
                    pb.Image = null;
                    pb.BackgroundImage = null;
                    pb.BackColor = Color.Transparent;
                }
            }

            if (menuStrip1 != null)
            {
                menuStrip1.BackgroundImage = null;
                menuStrip1.BackColor = Color.Transparent;
            }

            var menuItems = new ToolStripMenuItem[]
            {
        fileToolStripMenuItem, serverToolStripMenuItem, fishSpeechToolStripMenuItem, sTARTToolStripMenuItem,
        whisperTurboToolStripMenuItem, sTARTToolStripMenuItem1, editToolStripMenuItem, settingsToolStripMenuItem,
        formSettingsToolStripMenuItem, topmostToolStripMenuItem, yESToolStripMenuItem, nOToolStripMenuItem,
        commSettingsToolStripMenuItem, chatComboToolStripMenuItem, oNToolStripMenuItem, oFFToolStripMenuItem,
        partyModeToolStripMenuItem, oNToolStripMenuItem1, oFFToolStripMenuItem1, helpToolStripMenuItem,
        pushToTalkToolStripMenuItem, enableToolStripMenuItem, disableToolStripMenuItem, aboutToolStripMenuItem,
        toolsToolStripMenuItem, importToolStripMenuItem, voiceToolStripMenuItem, matchRecordToolStripMenuItem,
        voiceToolStripMenuItem1, recordToolStripMenuItem, stopRecordToolStripMenuItem, keypadderToolStripMenuItem,
        confirmModeToolStripMenuItem, tTSBaseToolStripMenuItem, fishSpeechToolStripMenuItem1, zonosToolStripMenuItem,
        viewToolStripMenuItem, tTSToolStripMenuItem, fishSpeechToolStripMenuItem2, zonosToolStripMenuItem1,
        constructiveChunksToolStripMenuItem, constructiveTokensToolStripMenuItem, ollamaToolStripMenuItem,
        longGenerationsModeToolStripMenuItem, translationModeToolStripMenuItem, spellCheckModeToolStripMenuItem,
        debugToolStripMenuItem, sTTToolStripMenuItem, oNToolStripMenuItem2, oFFToolStripMenuItem2,
        portableChatboxToolStripMenuItem, oNToolStripMenuItem3, oFFToolStripMenuItem3, indexTTSToolStripMenuItem,
        sTARTToolStripMenuItem2, recentPlayersToolStripMenuItem, incrementalSeedingToolStripMenuItem,
        stateToolStripMenuItem, oFFToolStripMenuItem4, previewModeToolStripMenuItem, oNToolStripMenuItem4,
        oFFToolStripMenuItem5, finetuneModelToolStripMenuItem, fishSpeechToolStripMenuItem3, toolStripMenuItem3,
        makeToolStripMenuItem, startTrainToolStripMenuItem, outputsToolStripMenuItem, cacheOutputsToolStripMenuItem,
        setDirectorytToolStripMenuItem,extrasToolStripMenuItem, themeToolStripMenuItem, rollDiceToolStripMenuItem, customizeToolStripMenuItem,
            };
            foreach (var item in menuItems)
            {
                if (item != null)
                {
                    item.BackgroundImage = null;
                    item.BackColor = Color.Transparent;
                }
            }

            if (statusStrip1 != null)
            {
                statusStrip1.BackgroundImage = null;
                statusStrip1.BackColor = Color.Transparent;
            }
            if (toolStripStatusLabel1 != null)
                toolStripStatusLabel1.BackgroundImage = null;
            if (toolStripStatusLabel2 != null)
                toolStripStatusLabel2.BackgroundImage = null;
            if (toolStripProgressBar1 != null)
                toolStripProgressBar1.BackgroundImage = null;

            if (VoicesList != null)
            {
                VoicesList.BackgroundImage = null;
            }

            var textBoxes = new TextBox[]
            {
        textBox1, textBox2, textBox3, RepBox, TopPBox, MaxTokenBox, ChunkBox, TempBox,
        HappyBox, AngryBox, ShockedBox, ScaredBox, GrossBox, SadBox, NeutralBox,
        OtherBox, SpeechSpeedBox, CFGBox, SearchBox
            };
            foreach (var tb in textBoxes)
            {
                if (tb != null)
                {
                    tb.BackgroundImage = null;
                    tb.BackColor = Color.White;
                }
            }

            var combos = new ComboBox[]
            {
        Previews, comboBox1, comboBox2, comboBox4, comboBoxModels, TranslationMdl, SpellCheckMdl, comboBoxOutputDevices, comboBoxInputDevices
            };
            foreach (var cb in combos)
            {
                if (cb != null)
                {
                    cb.BackgroundImage = null;
                    cb.BackColor = Color.White;
                }
            }

            var buttons = new Button[]
            {
        F3B, button2, button4, button3, ListenButton, button7, button6,
        Key_1_NUM, F2B, Key_16_ZERO, Key_15, Key_8_PLUS, Key_14_THREE,
        Key_13_TWO, Key_12_ONE, Key_11_SIX, Key_FIVE, Key_9_FOUR,
        Key_7_NINE, Key_6_EIGHT, Key_5_SEVEN, Key_4_MIN, Key_3_MULTI,
        Key_2_SLASH, button5, F3BB, F8B, F7B, F6B, F5B, F4B, F12B,
        F11B, F10B, F9B, F1B, button1, button13, button12, button8,
        button10, button11, HP, SP, SN, HN, SHN, SHP, GN, GP, NN,
        NP, AN, AP, SCN, SCP, ON, OP, button9, CFGN, CFGP, SPSN,
        SPSP, button16, button17, SpeakerAP, Bum, button14, LookButton
            };
            foreach (var btn in buttons)
            {
                if (btn != null)
                {
                    btn.BackgroundImage = null;
                    btn.Image = null;
                    btn.FlatAppearance.BorderColor = Color.Empty;
                    btn.FlatAppearance.BorderSize = 0;
                    btn.BackColor = Color.Transparent;
                }
            }

            var checkBoxes = new CheckBox[]
            {
        EnabPrefix, AutoEmote, checkBox3
            };
            foreach (var cb in checkBoxes)
            {
                if (cb != null)
                {
                    cb.BackgroundImage = null;
                    cb.BackColor = Color.Transparent;
                }
            }

            // Re-apply colors and gradients

            foreach (var lbl in labels)
            {
                if (lbl != null)
                {
                    lbl.ForeColor = textcolor;
                }
            }

            foreach (var pnl in allPanels)
            {
                if (pnl != null)
                {
                    SetGradient(pnl, mainStart, mainEnd);
                }
            }

            foreach (var pb in pictures)
            {
                if (pb != null)
                {
                    pb.BackColor = Color.Transparent;
                }
            }

            if (menuStrip1 != null)
            {
                menuStrip1.BackColor = accentsStart;
                menuStrip1.ForeColor = GetContrastingTextColor(accentsStart, textcolor);
            }
            foreach (var item in menuItems)
            {
                if (item != null)
                {
                    item.BackColor = accentsStart;
                    item.ForeColor = GetContrastingTextColor(accentsStart, textcolor);
                }
            }

            if (statusStrip1 != null)
            {
                statusStrip1.BackColor = accentsEnd;
                statusStrip1.ForeColor = GetContrastingTextColor(accentsEnd, textcolor);
            }
            if (toolStripStatusLabel1 != null)
                toolStripStatusLabel1.ForeColor = textcolor;
            if (toolStripStatusLabel2 != null)
                toolStripStatusLabel2.ForeColor = textcolor;
            if (toolStripProgressBar1 != null)
            {
                toolStripProgressBar1.BackColor = accentsStart;
                toolStripProgressBar1.ForeColor = textcolor;
            }

            if (VoicesList != null)
            {
                VoicesList.BackColor = mainStart;
                VoicesList.ForeColor = GetContrastingTextColor(mainStart, textcolor);
            }

            foreach (var tb in textBoxes)
            {
                if (tb != null)
                {
                    tb.BackColor = mainEnd;
                    tb.ForeColor = GetContrastingTextColor(mainEnd, textcolor);
                    tb.BorderStyle = BorderStyle.FixedSingle;
                }
            }

            foreach (var cb in combos)
            {
                if (cb != null)
                {
                    cb.BackColor = mainEnd;
                    cb.ForeColor = GetContrastingTextColor(mainEnd, textcolor);
                }
            }

            foreach (var btn in buttons)
            {
                if (btn == null) continue;

                var btnStart = ShiftColorRandomly(accentsStart, 10);
                var btnEnd = ShiftColorRandomly(accentsEnd, 20);
                SetGradient(btn, btnStart, btnEnd);

                Color midColor = Color.FromArgb(
                    (btnStart.R + btnEnd.R) / 2,
                    (btnStart.G + btnEnd.G) / 2,
                    (btnStart.B + btnEnd.B) / 2);

                btn.ForeColor = GetContrastingTextColor(midColor, textcolor);
                btn.FlatAppearance.BorderColor = DarkenColor(midColor, 0.3f);
                btn.FlatAppearance.BorderSize = 1;
                btn.FlatStyle = FlatStyle.Flat;
            }

            foreach (var cb in checkBoxes)
            {
                if (cb != null)
                {
                    cb.ForeColor = textcolor;
                    cb.BackColor = Color.Transparent;
                }
            }

            Bitmap formBmp = new Bitmap(this.Width, this.Height);
            using (Graphics g = Graphics.FromImage(formBmp))
            {
                var angleOptions = new[]
                {
            System.Drawing.Drawing2D.LinearGradientMode.Vertical,
            System.Drawing.Drawing2D.LinearGradientMode.Horizontal,
            System.Drawing.Drawing2D.LinearGradientMode.ForwardDiagonal,
            System.Drawing.Drawing2D.LinearGradientMode.BackwardDiagonal
        };
                var angle = angleOptions[_rand.Next(angleOptions.Length)];
                Color start = ShiftColorRandomly(mainStart, 15);
                Color end = ShiftColorRandomly(accentsStart, 25);

                using (var brush = new System.Drawing.Drawing2D.LinearGradientBrush(
                    new Rectangle(0, 0, formBmp.Width, formBmp.Height),
                    start,
                    end,
                    angle))
                {
                    g.FillRectangle(brush, 0, 0, formBmp.Width, formBmp.Height);
                }
            }
            this.BackgroundImage = formBmp;
            this.BackgroundImageLayout = ImageLayout.Stretch;
        }

        private Color ShiftColorRandomly(Color baseColor, int maxShift)
        {
            int ShiftChannel(int channel) => Clamp(channel + _rand.Next(-maxShift, maxShift + 1), 0, 255);
            return Color.FromArgb(baseColor.A, ShiftChannel(baseColor.R), ShiftChannel(baseColor.G), ShiftChannel(baseColor.B));
        }

        public async Task<string> WhisperTurbo(string fileToTranscribe)
        {
            var url = "http://localhost:21421/transcribe";

            try
            {
                using var multipart = new MultipartFormDataContent();

                var fileStream = File.OpenRead(fileToTranscribe);
                var streamContent = new StreamContent(fileStream);
                streamContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");

                multipart.Add(streamContent, "audio_file", Path.GetFileName(fileToTranscribe));
                multipart.Add(new StringContent("transcribe"), "task");

                var request = new HttpRequestMessage(HttpMethod.Post, url)
                {
                    Content = multipart
                };

                using var response = await httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false);
                response.EnsureSuccessStatusCode();

                using var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
                using var jsonDoc = await JsonDocument.ParseAsync(responseStream).ConfigureAwait(false);

                if (jsonDoc.RootElement.TryGetProperty("text", out var textElement))
                {
                    return textElement.GetString() ?? string.Empty;
                }
                else
                {
                    throw new Exception("Response JSON does not contain 'text' property.");
                }
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException("WhisperTurbo request failed", ex);
            }
        }

        private void StartOpacityTimer()
        {
            opacityTimer.Interval = 90; // 100 milliseconds; adjust this to change the ticking speed
            opacityTimer.Enabled = true;
        }

        // RECORDING FUNCTIONALITY // // RECORDING FUNCTIONALITY // // RECORDING FUNCTIONALITY // // RECORDING FUNCTIONALITY //
        private void OnDataAvailable(object sender, WaveInEventArgs e)
        {
            if (waveFile != null)
            {
                waveFile.Write(e.Buffer, 0, e.BytesRecorded);
                waveFile.Flush();
            }
        }

        private void InitializeAudio()
        {
            // Set up the WaveInEvent to record from a specific microphone
            waveSource = new WaveInEvent();
            waveSource.WaveFormat = new WaveFormat(44100, 1); // 44.1kHz, mono
            waveSource.DataAvailable += OnDataAvailable;
        }
        // RECORDING FUNCTIONALITY // // RECORDING FUNCTIONALITY // // RECORDING FUNCTIONALITY // // RECORDING FUNCTIONALITY //

        //WHISPER HERE // WHISPER HERE WHISPER HERE // WHISPER HERE WHISPER HERE // WHISPER HERE WHISPER HERE // WHISPER HERE WHISPER HERE // WHISPER HERE 

        static async Task Whispered(string fileToTranscribe)
        {
            string baseUrl = "http://localhost:8123"; // Change this to your FastAPI server URL

            // Example to transcribe an audio file
            string audioFilePath = fileToTranscribe; // Change this to your audio file path
            var transcriptionResult = await TranscribeAudioFile(baseUrl, audioFilePath, "transcribe");
            string JustText = transcriptionResult.Replace("{" + Quote + "text" + Quote + ":" + Quote + " ", string.Empty);
            JustText = JustText.Replace("}", string.Empty);
            JustText = JustText.Replace(Quote, string.Empty);
            liveText = JustText;
        }

        static async Task<string> TranscribeAudioFile(string baseUrl, string audioFilePath, string task)
        {
            using var form = new MultipartFormDataContent();
            using var fileStream = new FileStream(audioFilePath, FileMode.Open);
            using var fileContent = new StreamContent(fileStream);

            fileContent.Headers.ContentType = new MediaTypeHeaderValue("audio/wav"); // Change according to your file type

            form.Add(fileContent, "file", Path.GetFileName(audioFilePath));
            form.Add(new StringContent(task), "task");

            var response = await client.PostAsync($"{baseUrl}/transcribe/", form);
            response.EnsureSuccessStatusCode(); // Throw if not a 2xx response

            var result = await response.Content.ReadAsStringAsync();
            return result; // The response is a JSON string
        }

        static async Task<string> TranscribeYouTubeVideo(string baseUrl, string ytUrl, string task)
        {
            using var form = new MultipartFormDataContent();
            form.Add(new StringContent(ytUrl), "yt_url");
            form.Add(new StringContent(task), "task");

            var response = await client.PostAsync($"{baseUrl}/yt_transcribe/", form);
            response.EnsureSuccessStatusCode(); // Throw if not a 2xx response

            var result = await response.Content.ReadAsStringAsync();
            return result; // The response is a JSON string
        }
        //WHISPER HERE // WHISPER HERE WHISPER HERE // WHISPER HERE WHISPER HERE // WHISPER HERE WHISPER HERE // WHISPER HERE WHISPER HERE // WHISPER HERE 

        static float CalculateTokenLength(string inputText)
        {
            // Define the range of values
            const float minChunkLength = 66f;
            const float maxChunkLength = 2048f;

            // Get the length of the input text
            int textLength = inputText.Length;

            // Define the minimum and maximum lengths of text for scaling
            const int minLength = 0; // Minimum length of OutText, can adjust based on use case
            const int maxLength = 1000; // Maximum length of OutText, can adjust based on use case

            // Clamp the text length to the defined range
            if (textLength < minLength)
                textLength = minLength;
            else if (textLength > maxLength)
                textLength = maxLength;

            // Calculate the chunk length
            float chunkLength = (textLength - minLength) / (float)(maxLength - minLength) * (maxChunkLength - minChunkLength) + minChunkLength;

            return chunkLength - 33;
        }

        static float CalculateChunkLength(string inputText)
        {
            // Define the range of values
            const float minChunkLength = 66f;
            const float maxChunkLength = 2048f;

            // Get the length of the input text
            int textLength = inputText.Length;

            // Define the minimum and maximum lengths of text for scaling
            const int minLength = 0; // Minimum length of OutText, can adjust based on use case
            const int maxLength = 1000; // Maximum length of OutText, can adjust based on use case

            // Clamp the text length to the defined range
            if (textLength < minLength)
                textLength = minLength;
            else if (textLength > maxLength)
                textLength = maxLength;

            // Calculate the chunk length
            float chunkLength = (textLength - minLength) / (float)(maxLength - minLength) * (maxChunkLength - minChunkLength) + minChunkLength;

            return chunkLength;
        }

        public string TextBoxText
        {
            get { return textBox1.Text; }
            set { textBox3.Text = value; }
        }

        private void PopulateAudioDevices()
        {
            // Clear any existing items
            comboBoxInputDevices.Items.Clear();
            comboBoxOutputDevices.Items.Clear();
            Previews.Items.Clear();

            // Get the number of output devices and add them to output ComboBox
            int outputDeviceCount = WaveOut.DeviceCount;
            for (int i = 0; i < outputDeviceCount; i++)
            {
                var deviceInfo = WaveOut.GetCapabilities(i);
                comboBoxOutputDevices.Items.Add(deviceInfo.ProductName);
                Previews.Items.Add(deviceInfo.ProductName);
            }

            // Get the number of input devices and add them to input ComboBox
            int inputDeviceCount = WaveIn.DeviceCount;
            for (int i = 0; i < inputDeviceCount; i++)
            {
                var deviceInfo = WaveIn.GetCapabilities(i);
                comboBoxInputDevices.Items.Add(deviceInfo.ProductName);
            }
        }

        string LocationKey = string.Empty;

        private async void OnKeyPressEvent(object sender, KeyboardHookEventArgs e)
        {
            if (e.VirtualKeyCode == (int)VirtualKeyCode.VK_4)
            {
                if (SpeechToText)
                {
                    Recording = !Recording;

                    if (Recording)
                    {
                        PlayWavFile(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\SFX\Click.wav");
                        // Start recording
                        waveFile = new WaveFileWriter(outputFilePath, waveSource.WaveFormat);
                        waveSource.DeviceNumber = comboBoxInputDevices.SelectedIndex;
                        waveSource.StartRecording();
                    }
                    else
                    {
                        PlayWavFile(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\SFX\Click.wav");
                        // Stop recording
                        waveSource.StopRecording();
                        waveFile.Dispose();
                        waveFile = null;
                        if (IndexTTSBool)
                        {
                            await IndexAPI(WhisperTurbo(outputFilePath).Result);
                        }
                        if (FishSpeechMode)
                        {
                            await GimmieFish(WhisperTurbo(outputFilePath).Result, false);
                        }
                    }
                }
            }

            if (e.VirtualKeyCode == (int)VirtualKeyCode.INSERT)
            {
                if (!Recording)
                {
                    if (spellcheck)
                    {
                        OllamaClient.SelectedModel = SpellCheckModel;
                        OutDev = comboBoxOutputDevices.SelectedIndex;

                        WaitForSecondsAsync();

                        string speak = await ClipboardWpf.GetTextAsync();

                        await SendToken("Fix the grammar in the string in quotes based on the mood of the text as well as de-abbreviating and abbreviations, only reply the raw result. " + Quote + speak + Quote);
                    }
                    if (TranslationMode)
                    {
                        spellcheck = false;
                        OllamaClient.SelectedModel = SpellCheckModel;
                        OutDev = comboBoxOutputDevices.SelectedIndex;

                        WaitForSecondsAsync();

                        string speak = await ClipboardWpf.GetTextAsync();

                        await SendToken("translate the string in quotes to " + comboBox4.SelectedItem.ToString() + ". " + Quote + speak + Quote + ". Do not reply special characters that have nothing to do with translation just simply raw output.");
                    }
                    else
                    {
                        OutDev = comboBoxOutputDevices.SelectedIndex;

                        WaitForSecondsAsync();

                        string speak = await ClipboardWpf.GetTextAsync();
                        backup = speak;

                        if (FishSpeechMode)
                        {
                            await GimmieFish(speak, false);
                        }
                        if (ZonosTTSMode)
                        {
                            await GimmieLocoz(speak);
                        }
                        if (IndexTTSBool)
                        {
                            await IndexAPI(speak);
                        }
                    }
                }
                else
                {
                    TopMost = false;
                    MessageBox.Show("Cannot preform this action while recording.");
                    TopMost = true;
                }
            }
            if (e.VirtualKeyCode == (int)VirtualKeyCode.RETURN)
            {
                if (UseChatbox)
                {
                    if (!chatBox.Visible)
                    {
                        chatBox.Show(this);
                        chatBox.Poop();
                    }
                    else
                    {
                        // If chatBox is already visible, just bring it to front and focus the textbox
                        chatBox.BringToFront();
                    }
                    chatBox.textBox1.Focus();
                    chatBox.textBox1.Select();

                    textBox1.Select();
                }
            }
            if (e.VirtualKeyCode == (int)VirtualKeyCode.F5)
            {
                WipeAss();
                if (ConfMode)
                {
                    P2T = !P2T;
                    if (!P2T)
                    {
                        PlayWavFile(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\SFX\beep.wav");
                    }
                }
                audioFilePath = KeyStrings[F5_Key];
                if (File.Exists(audioFilePath))
                {
                    OutDev = comboBoxOutputDevices.SelectedIndex;
                    duration = GetWaveFileDuration(KeyStrings[F5_Key]);
                    PlayAudio(ISim, duration, false, ChatCombo);
                }
            }
            if (e.VirtualKeyCode == (int)VirtualKeyCode.F1)
            {
                WipeAss();
                if (ConfMode)
                {
                    P2T = !P2T;
                    if (!P2T)
                    {
                        PlayWavFile(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\SFX\beep.wav");
                    }
                }
                audioFilePath = KeyStrings[F1_Key];
                if (File.Exists(audioFilePath))
                {
                    OutDev = comboBoxOutputDevices.SelectedIndex;
                    duration = GetWaveFileDuration(KeyStrings[F1_Key]);
                    PlayAudio(ISim, duration, false, ChatCombo);
                }
            }
            if (e.VirtualKeyCode == (int)VirtualKeyCode.F2)
            {
                WipeAss();
                if (ConfMode)
                {
                    P2T = !P2T;
                    if (!P2T)
                    {
                        PlayWavFile(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\SFX\beep.wav");
                    }
                }
                audioFilePath = KeyStrings[F2_Key];
                if (File.Exists(audioFilePath))
                {
                    OutDev = comboBoxOutputDevices.SelectedIndex;
                    duration = GetWaveFileDuration(KeyStrings[F2_Key]);
                    PlayAudio(ISim, duration, false, ChatCombo);
                }
            }
            if (e.VirtualKeyCode == (int)VirtualKeyCode.F6)
            {
                WipeAss();
                if (ConfMode)
                {
                    P2T = !P2T;
                    if (!P2T)
                    {
                        PlayWavFile(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\SFX\beep.wav");
                    }
                }
                audioFilePath = KeyStrings[F6_Key];
                if (File.Exists(audioFilePath))
                {
                    OutDev = comboBoxOutputDevices.SelectedIndex;
                    duration = GetWaveFileDuration(KeyStrings[F6_Key]);
                    PlayAudio(ISim, duration, false, ChatCombo);
                }
            }
            if (e.VirtualKeyCode == (int)VirtualKeyCode.F7)
            {
                WipeAss();
                if (ConfMode)
                {
                    P2T = !P2T;
                    if (!P2T)
                    {
                        PlayWavFile(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\SFX\beep.wav");
                    }
                }
                audioFilePath = KeyStrings[F7_Key];
                if (File.Exists(audioFilePath))
                {
                    OutDev = comboBoxOutputDevices.SelectedIndex;
                    duration = GetWaveFileDuration(KeyStrings[F7_Key]);
                    PlayAudio(ISim, duration, false, ChatCombo);
                }
            }
            if (e.VirtualKeyCode == (int)VirtualKeyCode.F8)
            {
                WipeAss();
                if (ConfMode)
                {
                    P2T = !P2T;
                    if (!P2T)
                    {
                        PlayWavFile(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\SFX\beep.wav");
                    }
                }
                audioFilePath = KeyStrings[F8_Key];
                if (File.Exists(audioFilePath))
                {
                    OutDev = comboBoxOutputDevices.SelectedIndex;
                    duration = GetWaveFileDuration(KeyStrings[F8_Key]);
                    PlayAudio(ISim, duration, false, ChatCombo);
                }
            }
            if (e.VirtualKeyCode == (int)VirtualKeyCode.F9)
            {
                WipeAss();
                if (ConfMode)
                {
                    P2T = !P2T;
                    if (!P2T)
                    {
                        PlayWavFile(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\SFX\beep.wav");
                    }
                }
                audioFilePath = KeyStrings[F9_Key];
                if (File.Exists(audioFilePath))
                {
                    OutDev = comboBoxOutputDevices.SelectedIndex;
                    duration = GetWaveFileDuration(KeyStrings[F9_Key]);
                    PlayAudio(ISim, duration, false, ChatCombo);
                }
            }
            if (e.VirtualKeyCode == (int)VirtualKeyCode.F10)
            {
                WipeAss();
                if (ConfMode)
                {
                    P2T = !P2T;
                    if (!P2T)
                    {
                        PlayWavFile(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\SFX\beep.wav");
                    }
                }
                audioFilePath = KeyStrings[F10_Key];
                if (File.Exists(audioFilePath))
                {
                    OutDev = comboBoxOutputDevices.SelectedIndex;
                    duration = GetWaveFileDuration(KeyStrings[F10_Key]);
                    PlayAudio(ISim, duration, false, ChatCombo);
                }
            }
            if (e.VirtualKeyCode == (int)VirtualKeyCode.F11)
            {
                WipeAss();
                if (ConfMode)
                {
                    P2T = !P2T;
                    if (!P2T)
                    {
                        PlayWavFile(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\SFX\beep.wav");
                    }
                }
                audioFilePath = KeyStrings[F11_Key];
                if (File.Exists(audioFilePath))
                {
                    OutDev = comboBoxOutputDevices.SelectedIndex;
                    duration = GetWaveFileDuration(KeyStrings[F11_Key]);
                    PlayAudio(ISim, duration, false, ChatCombo);
                }
            }
            if (e.VirtualKeyCode == (int)VirtualKeyCode.F12)
            {
                WipeAss();
                if (ConfMode)
                {
                    P2T = !P2T;
                    if (!P2T)
                    {
                        PlayWavFile(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\SFX\beep.wav");
                    }
                }
                audioFilePath = KeyStrings[F12_Key];
                if (File.Exists(audioFilePath))
                {
                    OutDev = comboBoxOutputDevices.SelectedIndex;
                    duration = GetWaveFileDuration(KeyStrings[F12_Key]);
                    PlayAudio(ISim, duration, false, ChatCombo);
                }
            }
            if (e.VirtualKeyCode == (int)VirtualKeyCode.PAUSE)
            {
                ReuseSeed = !ReuseSeed;
                if (ReuseSeed)
                {
                    PlayWavFile(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\SFX\Keep_Seed.wav");
                }
                else
                {
                    PlayWavFile(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\SFX\Random_Seed.wav");
                }
            }
            if (e.VirtualKeyCode == (int)VirtualKeyCode.END)
            {
                string speak = backup;
                if (FishSpeechMode)
                {
                    await GimmieFish(speak, false);
                }
                if (ZonosTTSMode)
                {
                    await GimmieLocoz(speak);
                }
            }
            if (e.VirtualKeyCode == (int)VirtualKeyCode.F4)
            {
                WipeAss();
                if (ConfMode)
                {
                    P2T = !P2T;
                    if (!P2T)
                    {
                        PlayWavFile(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\SFX\beep.wav");
                    }
                }
                audioFilePath = KeyStrings[F4_Key];
                if (File.Exists(audioFilePath))
                {
                    OutDev = comboBoxOutputDevices.SelectedIndex;
                    duration = GetWaveFileDuration(KeyStrings[F4_Key]);
                    PlayAudio(ISim, duration, false, ChatCombo);
                }
            }
            if (e.VirtualKeyCode == (int)VirtualKeyCode.F3)
            {
                WipeAss();
                if (ConfMode)
                {
                    P2T = !P2T;
                    if (!P2T)
                    {
                        PlayWavFile(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\SFX\beep.wav");
                    }
                }
                audioFilePath = KeyStrings[F3_Key];
                if (File.Exists(audioFilePath))
                {
                    OutDev = comboBoxOutputDevices.SelectedIndex;
                    duration = GetWaveFileDuration(KeyStrings[F3_Key]);
                    PlayAudio(ISim, duration, false, ChatCombo);
                }
            }
            if ((e.VirtualKeyCode == (int)VirtualKeyCode.SNAPSHOT))
            {
                if (!Recording)
                {
                    ListenButton.PerformClick();
                }
                else
                {
                    TopMost = false;
                    MessageBox.Show("Cannot preform this action while recording.");
                    TopMost = true;
                }
            }
            if (e.VirtualKeyCode == (int)VirtualKeyCode.DIVIDE)
            {
                WipeAss();
                if (ConfMode)
                {
                    P2T = !P2T;
                    if (!P2T)
                    {
                        PlayWavFile(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\SFX\beep.wav");
                    }
                }
                audioFilePath = KeyStrings[Num_Slash];
                if (File.Exists(audioFilePath))
                {
                    OutDev = comboBoxOutputDevices.SelectedIndex;
                    duration = GetWaveFileDuration(KeyStrings[Num_Slash]);
                    PlayAudio(ISim, duration, false, ChatCombo);
                }
            }
            if (e.VirtualKeyCode == (int)VirtualKeyCode.MULTIPLY)
            {
                WipeAss();
                if (ConfMode)
                {
                    P2T = !P2T;
                    if (!P2T)
                    {
                        PlayWavFile(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\SFX\beep.wav");
                    }
                }
                audioFilePath = KeyStrings[Num_Multi];
                if (File.Exists(audioFilePath))
                {
                    OutDev = comboBoxOutputDevices.SelectedIndex;
                    duration = GetWaveFileDuration(KeyStrings[Num_Multi]);
                    PlayAudio(ISim, duration, false, ChatCombo);
                }
            }
            if (e.VirtualKeyCode == (int)VirtualKeyCode.OEM_MINUS)
            {
                WipeAss();
                if (ConfMode)
                {
                    P2T = !P2T;
                    if (!P2T)
                    {
                        PlayWavFile(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\SFX\beep.wav");
                    }
                }
                audioFilePath = KeyStrings[OMinus];
                if (File.Exists(audioFilePath))
                {
                    OutDev = comboBoxOutputDevices.SelectedIndex;
                    duration = GetWaveFileDuration(KeyStrings[OMinus]);
                    PlayAudio(ISim, duration, false, ChatCombo);
                }
            }
            if (e.VirtualKeyCode == (int)VirtualKeyCode.HOME)
            {
                WipeAss();
                P2T = !P2T;
                PlayWavFile(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\SFX\beep.wav");
            }
            if (e.VirtualKeyCode == (int)VirtualKeyCode.OEM_PLUS)
            {
                WipeAss();
                if (ConfMode)
                {
                    P2T = !P2T;
                    if (!P2T)
                    {
                        PlayWavFile(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\SFX\beep.wav");
                    }
                }
                audioFilePath = KeyStrings[OPlus];
                if (File.Exists(audioFilePath))
                {
                    OutDev = comboBoxOutputDevices.SelectedIndex;
                    duration = GetWaveFileDuration(KeyStrings[OPlus]);
                    PlayAudio(ISim, duration, false, ChatCombo);
                }
            }
            if (e.VirtualKeyCode == (int)VirtualKeyCode.SUBTRACT)
            {
                WipeAss();
                if (ConfMode)
                {
                    P2T = !P2T;
                    if (!P2T)
                    {
                        PlayWavFile(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\SFX\beep.wav");
                    }
                }
                audioFilePath = KeyStrings[Num_Sub];
                if (File.Exists(audioFilePath))
                {
                    OutDev = comboBoxOutputDevices.SelectedIndex;
                    duration = GetWaveFileDuration(KeyStrings[Num_Sub]);
                    PlayAudio(ISim, duration, false, ChatCombo);
                }
            }
            if (e.VirtualKeyCode == (int)VirtualKeyCode.ADD)
            {
                WipeAss();
                if (ConfMode)
                {
                    P2T = !P2T;
                    if (!P2T)
                    {
                        PlayWavFile(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\SFX\beep.wav");
                    }
                }
                audioFilePath = KeyStrings[Num_Plus];
                if (File.Exists(audioFilePath))
                {
                    OutDev = comboBoxOutputDevices.SelectedIndex;
                    duration = GetWaveFileDuration(KeyStrings[Num_Plus]);
                    PlayAudio(ISim, duration, false, ChatCombo);
                }
            }
            if (e.VirtualKeyCode == (int)VirtualKeyCode.NUMPAD0)
            {
                WipeAss();
                if (ConfMode)
                {
                    P2T = !P2T;
                    if (!P2T)
                    {
                        PlayWavFile(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\SFX\beep.wav");
                    }
                }
                audioFilePath = KeyStrings[Num_0];
                if (File.Exists(audioFilePath))
                {
                    OutDev = comboBoxOutputDevices.SelectedIndex;
                    duration = GetWaveFileDuration(KeyStrings[Num_0]);
                    PlayAudio(ISim, duration, false, ChatCombo);
                }
            }
            if (e.VirtualKeyCode == (int)VirtualKeyCode.NUMPAD1)
            {
                WipeAss();
                if (ConfMode)
                {
                    P2T = !P2T;
                    if (!P2T)
                    {
                        PlayWavFile(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\SFX\beep.wav");
                    }
                }
                audioFilePath = KeyStrings[Num_1];
                if (File.Exists(audioFilePath))
                {
                    OutDev = comboBoxOutputDevices.SelectedIndex;
                    duration = GetWaveFileDuration(KeyStrings[Num_1]);
                    PlayAudio(ISim, duration, false, ChatCombo);
                }
            }
            if (e.VirtualKeyCode == (int)VirtualKeyCode.NUMPAD2)
            {
                WipeAss();
                if (ConfMode)
                {
                    P2T = !P2T;
                    if (!P2T)
                    {
                        PlayWavFile(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\SFX\beep.wav");
                    }
                }
                audioFilePath = KeyStrings[Num_2];
                if (File.Exists(audioFilePath))
                {
                    OutDev = comboBoxOutputDevices.SelectedIndex;
                    duration = GetWaveFileDuration(KeyStrings[Num_2]);
                    PlayAudio(ISim, duration, false, ChatCombo);
                }
            }
            if (e.VirtualKeyCode == (int)VirtualKeyCode.NUMPAD3)
            {
                WipeAss();
                if (ConfMode)
                {
                    P2T = !P2T;
                    if (!P2T)
                    {
                        PlayWavFile(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\SFX\beep.wav");
                    }
                }
                audioFilePath = KeyStrings[Num_3];
                if (File.Exists(audioFilePath))
                {
                    OutDev = comboBoxOutputDevices.SelectedIndex;
                    duration = GetWaveFileDuration(KeyStrings[Num_3]);
                    PlayAudio(ISim, duration, false, ChatCombo);
                }
            }
            if (e.VirtualKeyCode == (int)VirtualKeyCode.NUMPAD4)
            {
                WipeAss();
                if (ConfMode)
                {
                    P2T = !P2T;
                    if (!P2T)
                    {
                        PlayWavFile(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\SFX\beep.wav");
                    }
                }
                audioFilePath = KeyStrings[Num_4];
                if (File.Exists(audioFilePath))
                {
                    OutDev = comboBoxOutputDevices.SelectedIndex;
                    duration = GetWaveFileDuration(KeyStrings[Num_4]);
                    PlayAudio(ISim, duration, false, ChatCombo);
                }
            }
            if (e.VirtualKeyCode == (int)VirtualKeyCode.NUMPAD5)
            {
                WipeAss();
                if (ConfMode)
                {
                    P2T = !P2T;
                    if (!P2T)
                    {
                        PlayWavFile(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\SFX\beep.wav");
                    }
                }
                audioFilePath = KeyStrings[Num_5];
                if (File.Exists(audioFilePath))
                {
                    OutDev = comboBoxOutputDevices.SelectedIndex;
                    duration = GetWaveFileDuration(KeyStrings[Num_5]);
                    PlayAudio(ISim, duration, false, ChatCombo);
                }
            }
            if (e.VirtualKeyCode == (int)VirtualKeyCode.NUMPAD6)
            {
                WipeAss();
                if (ConfMode)
                {
                    P2T = !P2T;
                    if (!P2T)
                    {
                        PlayWavFile(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\SFX\beep.wav");
                    }
                }
                audioFilePath = KeyStrings[Num_6];
                if (File.Exists(audioFilePath))
                {
                    OutDev = comboBoxOutputDevices.SelectedIndex;
                    duration = GetWaveFileDuration(KeyStrings[Num_6]);
                    PlayAudio(ISim, duration, false, ChatCombo);
                }
            }
            if (e.VirtualKeyCode == (int)VirtualKeyCode.NUMPAD7)
            {
                WipeAss();
                if (ConfMode)
                {
                    P2T = !P2T;
                    if (!P2T)
                    {
                        PlayWavFile(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\SFX\beep.wav");
                    }
                }
                audioFilePath = KeyStrings[Num_7];
                if (File.Exists(audioFilePath))
                {
                    OutDev = comboBoxOutputDevices.SelectedIndex;
                    duration = GetWaveFileDuration(KeyStrings[Num_7]);
                    PlayAudio(ISim, duration, false, ChatCombo);
                }
            }
            if (e.VirtualKeyCode == (int)VirtualKeyCode.NUMPAD8)
            {
                WipeAss();
                if (ConfMode)
                {
                    P2T = !P2T;
                    if (!P2T)
                    {
                        PlayWavFile(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\SFX\beep.wav");
                    }
                }
                audioFilePath = KeyStrings[Num_8];
                if (File.Exists(audioFilePath))
                {
                    OutDev = comboBoxOutputDevices.SelectedIndex;
                    duration = GetWaveFileDuration(KeyStrings[Num_8]);
                    PlayAudio(ISim, duration, false, ChatCombo);
                }
            }
            if (e.VirtualKeyCode == (int)VirtualKeyCode.NUMPAD9)
            {
                WipeAss();
                if (ConfMode)
                {
                    P2T = !P2T;
                    if (!P2T)
                    {
                        PlayWavFile(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\SFX\beep.wav");
                    }
                }
                audioFilePath = KeyStrings[Num_9];
                if (File.Exists(audioFilePath))
                {
                    OutDev = comboBoxOutputDevices.SelectedIndex;
                    duration = GetWaveFileDuration(KeyStrings[Num_9]);
                    PlayAudio(ISim, duration, false, ChatCombo);
                }
            }
        }

        public Form1()
        {
            InitializeComponent();
        }

        private void PopulateList(string directoryPath)
        {
            // Clear the existing items in the ListBox
            VoicesList.Items.Clear();

            CurrentPresets = new List<string>();

            // Check if the directory exists
            if (Directory.Exists(directoryPath))
            {
                // Get the subdirectories
                string[] subdirectories = Directory.GetDirectories(directoryPath);

                // Add each subdirectory to the ListBox
                foreach (string subdirectory in subdirectories)
                {
                    // Just add the folder name, not the full path
                    VoicesList.Items.Add(Path.GetFileName(subdirectory));
                }
                var sortedItems = VoicesList.Items.OfType<string>().OrderBy(item => item).ToList();
                VoicesList.Items.Clear();
                foreach (var item in sortedItems)
                {
                    VoicesList.Items.Add(item);
                    CurrentPresets.Add(item);
                }
            }
            else
            {
                TopMost = false;
                MessageBox.Show("The specified directory does not exist.",
                                "Directory Not Found",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
                TopMost = true;
            }
        }

        static string RemoveBlankLinesAndJoin(string input)
        {
            // Split the input into lines, remove blank lines, and trim each line
            var lines = input.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries)
                             .Select(line => line.Trim())
                             .Where(line => !string.IsNullOrWhiteSpace(line));

            // Join the lines with a space, ensuring proper spacing
            return string.Join(" ", lines);
        }

        private async void LoadModelsAsync()
        {
            try
            {
                var models = await OllamaClient.ListLocalModelsAsync();

                // Clear existing items
                comboBoxModels.Items.Clear();
                TranslationMdl.Items.Clear();
                SpellCheckMdl.Items.Clear();
                // Assuming models is a list of strings. If it's a different type,
                // adjust the code to match the structure.
                foreach (var model in models)
                {
                    comboBoxModels.Items.Add(model.Name); // Change this if model is a complex object
                    TranslationMdl.Items.Add(model.Name); // Change this if model is a complex object
                    SpellCheckMdl.Items.Add(model.Name); // Change this if model is a complex object
                }
            }
            catch (Exception ex)
            {
                toolStripStatusLabel1.Text = $"Ollama Error: {ex.Message}";
            }
        }

        public async Task SendToken(string usrMessage)
        {
            const string errorMessage = "TokenSend Error.";
            StringBuilder totalTextBuilder = new StringBuilder();

            await foreach (var stream in OllamaClient.GenerateAsync(usrMessage))
            {
                totalTextBuilder.Append(stream.Response);
            }

            string totalText = totalTextBuilder.ToString();
            string globalOutput = RemoveBlankLinesAndJoin(totalText);
            globalOutput = globalOutput.Replace(Quote, string.Empty);

            // Uncomment the following line if you need to display the message box for debugging
            // MessageBox.Show(globalOutput);

            await GimmieFish(globalOutput, false);
            await ClipboardWpf.SetTextAsync(globalOutput);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.StartPosition = FormStartPosition.Manual;
            Size = new Size(1486, 404); // This resizes my form
            Location = new Point(
                (Screen.PrimaryScreen.WorkingArea.Width - this.Width) / 2,
                (Screen.PrimaryScreen.WorkingArea.Height - this.Height) / 2
            );

            chatBox = new ChatBox(this);
            RecentPlayaz = new Form2(this);
            Opacity = 0;
            StartOpacityTimer();
            F3B.Location = PE1;
            button2.Location = PE2;
            vol = volumeSlider1.Volume;
            LookButton.Focus();
            LookButton.Select();
            InitializeAudio();
            keyboardHook.KeyDown += OnKeyPressEvent;
            keyboardHook.Hook();
            PopulateAudioDevices();
            DoubleBuffered = true;
            TopMost = true;

            if (Male)
            {
                PopulateList(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\Presets\MALE");
            }
            else
            {
                PopulateList(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\Presets\FEMALE");
            }

            Previews.SelectedIndex = 1;

            LookButton.Focus();
            LookButton.Select();

            var lines = File.ReadLines(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\Settings.ini").ToArray();

            Max_Tokens = int.Parse(lines[0]);
            Chunk_Length = int.Parse(lines[1]);
            Top_P = float.Parse(lines[2]);
            Repetition_Penalty = float.Parse(lines[3]);
            Temperature = float.Parse(lines[4]);

            MaxTokenBox.Text = lines[0];
            ChunkBox.Text = lines[1];
            TopPBox.Text = lines[2];
            RepBox.Text = lines[3];
            TempBox.Text = lines[4];

            toolStripStatusLabel1.Text = "AI Values Applied!";

            try
            {
                string Content = File.ReadAllText(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\Block.BLK");
                Thread.Sleep(500);
                VoicesList.SelectedItem = Content;
                Thread.Sleep(500);
            }
            catch
            {
                Thread.Sleep(500);
                VoicesList.SelectedItem = 0;
                Thread.Sleep(500);
            }
            button12.Text = "<";

            OllamaURI = new Uri("http://127.0.0.1:11435");
            OllamaClient = new OllamaApiClient(OllamaURI);

            LoadModelsAsync();

            Defaults();

            var savedColors = ColorHelper.LoadColors();
            if (savedColors != null)
            {
                _lastMainStart = savedColors._lastMainStart;
                _lastMainEnd = savedColors._lastMainEnd;
                _lastAccentsStart = savedColors._lastAccentsStart;
                _lastAccentsEnd = savedColors._lastAccentsEnd;
                _lastTextColor = savedColors._lastTextColor;
                GenerateRandomTheme(true);
            }
        }

        private void Form1_Click(object sender, EventArgs e)
        {
            LookButton.Focus();
            LookButton.Select();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            OutDev = Previews.SelectedIndex;

            if (Male)
            {
                string path;
                path = @"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\Presets\MALE\" + VoicesList.SelectedItem + @"\Recording.wav";
                audioFilePath = path;
                LookButton.Focus();
                LookButton.Select();
                PlayAudio(ISim, GetWaveFileDuration(path), true, false);
            }
            else
            {
                string path;
                path = @"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\Presets\FEMALE\" + VoicesList.SelectedItem + @"\Recording.wav";
                audioFilePath = path;
                LookButton.Focus();
                LookButton.Select();
                PlayAudio(ISim, GetWaveFileDuration(path), true, false);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (Male)
            {
                DeleteTriggered = true;
                LookButton.Focus();
                LookButton.Select();
                if (Directory.Exists(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\Presets\MALE\" + VoicesList.SelectedItem))
                {
                    Directory.Delete(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\Presets\MALE\" + VoicesList.SelectedItem, true);
                    VoicesList.Items.Remove(VoicesList.SelectedItem);
                    VoicesList.Refresh();
                }
                DeleteTriggered = false;
            }
            else
            {
                DeleteTriggered = true;
                LookButton.Focus();
                LookButton.Select();
                if (Directory.Exists(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\Presets\FEMALE\" + VoicesList.SelectedItem))
                {
                    Directory.Delete(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\Presets\FEMALE\" + VoicesList.SelectedItem, true);
                    VoicesList.Items.Remove(VoicesList.SelectedItem);
                    VoicesList.Refresh();
                }
                DeleteTriggered = false;
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            using (GenderDialog genderDialog = new GenderDialog())
            {
                if (genderDialog.ShowDialog() == DialogResult.OK || genderDialog.ShowDialog() == DialogResult.Cancel)
                {
                    string selectedGender = genderDialog.SelectedGender;
                    MessageBox.Show($"You selected: {selectedGender}");
                    LookButton.Focus();
                    LookButton.Select();
                    if (!Directory.Exists(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\Presets\" + selectedGender + @"\" + textBox2.Text))
                    {
                        Directory.CreateDirectory(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\Presets\" + selectedGender + @"\" + textBox2.Text);
                        File.WriteAllText(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\Presets\" + selectedGender + @"\" + textBox2.Text + @"\Recording.txt", textBox1.Text);
                        File.Copy(outputFilePath, @"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\Presets\" + selectedGender + @"\" + textBox2.Text + @"\Recording.wav");
                    }
                    VoicesList.Items.Add(textBox2.Text);
                }
            }
        }

        public void BootFish(string condaEnvName, string fishHome, string checkpointName)
        {
            // For Windows, activate conda and run python command in one cmd instance:
            string command = $"conda activate {condaEnvName} && python -m tools.api_server --listen 0.0.0.0:8080 --llama-checkpoint-path \"checkpoints/{checkpointName}\" --decoder-checkpoint-path \"checkpoints/fish-speech-1.5/firefly-gan-vq-fsq-8x1024-21hz-generator.pth\" --decoder-config-name firefly_gan_vq --compile";

            var processInfo = new ProcessStartInfo("cmd.exe", "/C " + command)
            {
                RedirectStandardOutput = false,
                RedirectStandardError = false,
                UseShellExecute = false,
                CreateNoWindow = false,
                WorkingDirectory = fishHome
            };

            using (var process = new Process())
            {
                process.StartInfo = processInfo;

                process.Start();
            }
        }

        static string PrintMostRecentFolderName(string parentDir)
        {
            if (!Directory.Exists(parentDir))
            {
                Console.WriteLine("Directory does not exist.");
                return string.Empty;
            }

            var mostRecentFolder = new DirectoryInfo(parentDir)
                .GetDirectories()
                .OrderByDescending(d => d.LastWriteTime)
                .FirstOrDefault();

            if (mostRecentFolder != null)
            {
                return mostRecentFolder.Name;
            }
            else
            {
                return string.Empty;
            }
        }

        private void CheckForCustomModel()
        {
            string checkpointsPath = @"C:\AI\fish-speech\checkpoints";

            try
            {
                if (Directory.Exists(checkpointsPath))
                {
                    // Get directories excluding "fish-speech-1.5"
                    var otherDirs = Directory.GetDirectories(checkpointsPath)
                        .Select(Path.GetFileName)
                        .Where(d => !string.Equals(d, "fish-speech-1.5", StringComparison.OrdinalIgnoreCase))
                        .ToList();

                    if (otherDirs.Count > 0)
                    {
                        var dialogResult = MessageBox.Show(
                            "Would you like to boot Fish with your custom model?",
                            "Custom Model Found!",
                            MessageBoxButtons.YesNo,
                            MessageBoxIcon.Question);

                        if (dialogResult == DialogResult.Yes)
                        {
                            string FishHome = @"C:\AI\fish-speech";
                            string CheckPoint = checkpointsPath;
                            string MostRecent = PrintMostRecentFolderName(CheckPoint);
                            BootFish("fish-speech", FishHome, MostRecent);
                        }
                        if (dialogResult == DialogResult.No)
                        {
                            string FishHome = @"C:\AI\fish-speech";
                            string CheckPoint = checkpointsPath;
                            string Default = "fish-speech-1.5";
                            BootFish("fish-speech", FishHome, Default);
                        }
                    }
                }
                else
                {
                    MessageBox.Show($"Directory not found: {checkpointsPath}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Error checking directories: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void sTARTToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CheckForCustomModel();
        }

        private void OnApplicationExit(object sender, EventArgs e)
        {
            keyboardHook.Unhook();
            keyboardHook.Dispose();
        }

        async void WaitForSecondsAsync()
        {
            // Create an instance of InputSimulator
            Thread.Sleep(22);
            ISim.Keyboard.ModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_A);
            Thread.Sleep(22);
            ISim.Keyboard.ModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_C);
            Thread.Sleep(22);
            ISim.Keyboard.KeyPress(VirtualKeyCode.BACK);

            ISim.Keyboard.KeyPress(VirtualKeyCode.ESCAPE);
        }

        TimeSpan GetWaveFileDuration(string filePath)
        {
            if (string.IsNullOrWhiteSpace(filePath) || !File.Exists(filePath))
            {
                //throw new FileNotFoundException("The specified file does not exist.", filePath);
            }

            try
            {
                using (var reader = new AudioFileReader(filePath))
                {
                    return reader.TotalTime;
                }
            }
            catch (Exception ex) // Catching specific exceptions can be more useful
            {
                // Log the error message (consider using logging framework)
                Console.WriteLine($"Error while reading the WAV file: {ex.Message}");

                return TimeSpan.Zero; // Return TimeSpan.Zero to indicate failure
            }
        }

        void WipeAss()
        {
            // Clean up existing audio resources
            _audioFileReader?.Dispose();
            _waveOut?.Stop();
            _waveOut?.Dispose();
        }

        private CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource();
        private bool _isPlaying = false;

        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;
                }
            }
        }

        private readonly HttpClient MyClient = new HttpClient();
        private readonly string baseUrl = "http://localhost:8000"; // Change if your server address is different

        public class VoiceResponse
        {
            public string voice_id { get; set; }
            public long created { get; set; }
        }

        async Task CreateVoice(string voiceFilePath, string Text)
        {
            if (!CanSkip)
            {
                // Check if the reference voice file exists
                if (!File.Exists(voiceFilePath))
                {
                    MessageBox.Show($"Error: The voice file at '{voiceFilePath}' does not exist.");
                    return;
                }

                // Prepare the file content for the voice
                var content = new MultipartFormDataContent();
                var fileStream = new FileStream(voiceFilePath, FileMode.Open, FileAccess.Read);
                var fileContent = new StreamContent(fileStream);
                fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse("audio/wav"); // Assuming you're using a WAV file
                content.Add(fileContent, "file", Path.GetFileName(voiceFilePath));

                try
                {
                    // Send a POST request to create voice
                    var response = await MyClient.PostAsync($"{baseUrl}/v1/audio/voice", content);
                    response.EnsureSuccessStatusCode();

                    // Deserialize the response to get the voice ID
                    var voiceResponse = await response.Content.ReadAsStringAsync();
                    var voiceObject = JsonConvert.DeserializeObject<VoiceResponse>(voiceResponse);
                    VoiceIDBCK = voiceObject.voice_id;

                    // Use the voice ID in the TTS request
                    await TTS(VoiceIDBCK, Text);
                }
                catch (HttpRequestException e)
                {
                    MessageBox.Show("Error sending request to create voice:\n" + e.Message);
                }
            }
            else
            {
                await TTS(VoiceIDBCK, Text);
            }
        }

        async Task TTS(string voiceId, string Text)
        {
            byte[] PrefixAudio = null;

            if (EnabPrefix.Checked)
            {
                PrefixAudio = File.ReadAllBytes(MyLink.Text);
                Thread.Sleep(444);
            }
            else
            {
                PrefixAudio = null;
            }

            if (AutoEmote.Checked)
            {
                UncondKeys = new List<string>();
                UncondKeys.Clear();
                Thread.Sleep(77);
                UncondKeys.Add("emotion");
            }

            // Set progress to 10% after preparing the request
            UpdateProgressBar(10);

            var request = new
            {
                model = "Zyphra/Zonos-v0.1-transformer",
                input = Text,
                language = "en-us",
                voice = voiceId,
                emotion = new
                {
                    happiness = float.Parse(HappyBox.Text),
                    sadness = float.Parse(SadBox.Text),
                    disgust = float.Parse(GrossBox.Text),
                    fear = float.Parse(ScaredBox.Text),
                    surprise = float.Parse(ShockedBox.Text),
                    anger = float.Parse(AngryBox.Text),
                    other = float.Parse(OtherBox.Text),
                    neutral = float.Parse(NeutralBox.Text)
                },
                response_format = "wav",
                vq_single = 1.0f,
                fmax = 24000.0f,
                pitch_std = 45f,
                speaking_rate = float.Parse(SpeechSpeedBox.Text),
                dnsmos_ovrl = 0.0f,
                speaker_noised = checkBox3.Checked,
                cfg_scale = float.Parse(CFGBox.Text),
                min_p = 0.5f,
                seed = GenerateRandomSeed(),
                randomize_seed = true,
                unconditional_keys = UncondKeys,
                prefix_audio = PrefixAudio
            };

            var json = JsonConvert.SerializeObject(request);
            var content = new StringContent(json, Encoding.UTF8, "application/json");

            try
            {
                toolStripProgressBar1.Visible = true;
                UpdateProgressBar(30); // Sending request stage
                var response = await MyClient.PostAsync($"{baseUrl}/v1/audio/speech", content);
                response.EnsureSuccessStatusCode();

                UpdateProgressBar(60); // Response received

                var audioStream = await response.Content.ReadAsStreamAsync();

                var outputFilePath = @"H:\Hot\Pookie\Poo\poo\api\zonos.git\app\audio.wav"; // Update this to .wav extension

                using (var fileStream = new FileStream(outputFilePath, FileMode.Create, FileAccess.Write))
                {
                    await audioStream.CopyToAsync(fileStream);
                }

                UpdateProgressBar(90); // Audio saved

                duration = GetWaveFileDuration(outputFilePath);
                audioFilePath = outputFilePath;
                PlayAudio(ISim, duration, false, ChatCombo);

                UpdateProgressBar(100); // Completed
                toolStripProgressBar1.Visible = false;
                string newPath = cacheDir + @"\" + DateTime.Now.ToString().Replace(@"/", string.Empty).Replace(@"\", string.Empty).Replace(" ", string.Empty).Replace(":", string.Empty) + "_Output.wav";
                File.Copy(audioFilePath, newPath, true);
            }
            catch (HttpRequestException e)
            {
                MessageBox.Show("Error sending request to the speech generation server:\n" + e.Message);
            }
            catch (TaskCanceledException e)
            {
                MessageBox.Show("The request timed out:\n" + e.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show("An unexpected error occurred:\n" + ex.Message);
            }
        }

        private void UpdateProgressBar(int value)
        {
            // Ensure the value is within bounds
            if (value < 0 || value > 100)
                throw new ArgumentOutOfRangeException(nameof(value), "Progress value must be between 0 and 100.");
            bool btp = false;
            // Check if we need to invoke on the UI thread
            if (btp)
            {

            }
            else
            {
                toolStripProgressBar1.Value = value;
            }
        }

        public async Task GimmieLocoz(string message)
        {
            await CreateVoice(Reference_Voice, message);
            CanSkip = true;
        }

        public int Iseeder()
        {
            seedCount++;
            return seedCount;
        }

        public async Task GimmieFish(string xmessage, bool PreviewMode)
        {
            // Predefined sentence
            string sentence = xmessage;

            // Add a period if the sentence doesn't end with ?, ., or !
            if (!sentence.EndsWith("?") && !sentence.EndsWith(".") && !sentence.EndsWith("!"))
            {
                if (TranslationMode)
                {

                }
                else
                {
                    sentence += ".";
                }
            }

            string TTS_Message = sentence;

            toolStripStatusLabel1.Text = "TTS: [" + sentence + "]";

            MyOutput = TTS_Message;

            cat = new List<byte[]>();
            try
            {
                cat.Add(File.ReadAllBytes(Reference_Voice));
            }
            catch
            {
                MessageBox.Show("Please select a voice first...");
            }

            List<string> transscript = new List<string>();

            transscript.Add(Reference_Text);
            if (!ReuseSeed)
            {
                if (ISeed)
                {
                    Seed = Iseeder();
                }
                else
                {
                    Seed = GenerateRandomSeed();
                }
                toolStripStatusLabel1.Text = toolStripStatusLabel1.Text + " [SEED | " + Seed.ToString() + "]";
            }
            if (ConstructiveTokens)
            {
                Max_Tokens = (int)CalculateTokenLength(sentence);
                MaxTokenBox.Text = Max_Tokens.ToString();
            }
            if (ConstructiveChunks)
            {
                Chunk_Length = (int)CalculateChunkLength(sentence);
                ChunkBox.Text = Chunk_Length.ToString();
            }
            var client = new TTSClient(
                url: "http://127.0.0.1:8080/v1/tts",
                text: sentence,
                apiKey: "YOUR_API_KEY",
                referenceTexts: transscript,
                referenceAudios: cat,
                chunkLength: Chunk_Length,          // Optional, defaults to 200 if not provided
                topP: Top_P,                // Optional, defaults to 0.7 if not provided
                temperature: Temperature,         // Optional, defaults to 0.7 if not provided
                seed: Seed,                 // Optional, defaults to null if not provided
                maxNewTokens: Max_Tokens,        // Optional, defaults to 1024 if not provided
                repetitionPenalty: Repetition_Penalty    // Optional, defaults to 1.2 if not provided
            );

            var (success, message) = await client.SendRequestAndSaveAudio();

            audioFilePath = message;
            duration = GetWaveFileDuration(audioFilePath);
            OutDev = comboBoxOutputDevices.SelectedIndex;

            if (PreviewMode) // Preview mode is on.
            {
                OutDev = Previews.SelectedIndex;
                PlayAudio(ISim, duration, false, false); // Plays on Virtual Mic.
                PrevHack = 0; // Enter was pressed twice in the chatbox.
            }
            else // Preview mode isn't on so do normal generations.
            {
                OutDev = comboBoxOutputDevices.SelectedIndex;
                PlayAudio(ISim, duration, false, false); // Plays on Virtual Mic.
                PrevHack = 0; // Enter was pressed twice in the chatbox.
            }

            File.Copy(audioFilePath, @"C:\Users\DjZaN\OneDrive\Desktop\opt\Result.wav", true);
        }

        private void comboBoxInputDevices_SelectedIndexChanged(object sender, EventArgs e)
        {
            LookButton.Focus();
            LookButton.Select();
        }

        private void comboBoxOutputDevices_SelectedIndexChanged(object sender, EventArgs e)
        {
            LookButton.Focus();
            LookButton.Select();
        }

        private void Previews_SelectedIndexChanged(object sender, EventArgs e)
        {
            LookButton.Focus();
            LookButton.Select();
        }

        private void sTARTToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Process.Start("cmd.exe");
            Thread.Sleep(5555);
            ISim.Keyboard.TextEntry("bash");
            Thread.Sleep(3333);
            ISim.Keyboard.KeyPress(VirtualKeyCode.RETURN);
            Thread.Sleep(3333);
            ISim.Keyboard.TextEntry("cd");
            Thread.Sleep(333);
            ISim.Keyboard.KeyPress(VirtualKeyCode.RETURN);
            Thread.Sleep(100);
            ISim.Keyboard.TextEntry("cd Whisper");
            Thread.Sleep(133);
            ISim.Keyboard.KeyPress(VirtualKeyCode.RETURN);
            Thread.Sleep(300);
            ISim.Keyboard.TextEntry("conda activate cosyvoice");
            Thread.Sleep(393);
            ISim.Keyboard.KeyPress(VirtualKeyCode.RETURN);
            Thread.Sleep(300);
            ISim.Keyboard.TextEntry("python app_uvi.py");
            Thread.Sleep(232);
            ISim.Keyboard.KeyPress(VirtualKeyCode.RETURN);
        }

        private void button5_Click(object sender, EventArgs e)
        {
            audioFilePath = outputFilePath;
            OutDev = Previews.SelectedIndex;
            PlayAudio(ISim, GetWaveFileDuration(outputFilePath), true, false);
            LookButton.Focus();
            LookButton.Select();
        }

        private void volumeSlider1_VolumeChanged(object sender, EventArgs e)
        {
            vol = volumeSlider1.Volume;
            toolStripStatusLabel1.Text = "[VOLUME CHANGE:" + vol.ToString() + "]";
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            CanSkip = false;
            PlayWavFile(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\SFX\Click.wav");

            if (File.Exists(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\Block.BLK"))
            {
                File.Delete(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\Block.BLK");
            }

            File.WriteAllText(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\Block.BLK", VoicesList.SelectedItem.ToString());

            if (!DeleteTriggered)
            {
                if (Male)
                {
                    // Get the path for the presets folder.
                    string SelectionPath = @"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\Presets\MALE\" + VoicesList.SelectedItem;

                    // Get the path for the Recording.txt file.
                    string recordingTxtFile = Path.Combine(SelectionPath, "Recording.txt");

                    // Get the path for the Recording.wav file.
                    string recordingWavFile = Path.Combine(SelectionPath, "Recording.wav");

                    // Read the contents of the Recording.txt file.
                    string Text = File.ReadAllText(recordingTxtFile);

                    RefAudioFile = recordingWavFile;
                    Reference_Voice = recordingWavFile;
                    Reference_Text = Text;
                    LoadKeys();
                    LookButton.Focus();
                    LookButton.Select();
                    if (Speaker_Prefix)
                    {
                        MyLink.Text = recordingWavFile;
                    }
                }
                else
                {
                    // Get the path for the presets folder.
                    string SelectionPath = @"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\Presets\FEMALE\" + VoicesList.SelectedItem;

                    // Get the path for the Recording.txt file.
                    string recordingTxtFile = Path.Combine(SelectionPath, "Recording.txt");

                    // Get the path for the Recording.wav file.
                    string recordingWavFile = Path.Combine(SelectionPath, "Recording.wav");

                    // Read the contents of the Recording.txt file.
                    string Text = File.ReadAllText(recordingTxtFile);

                    RefAudioFile = recordingWavFile;
                    Reference_Voice = recordingWavFile;
                    Reference_Text = Text;
                    LoadKeys();
                    LookButton.Focus();
                    LookButton.Select();
                    if (Speaker_Prefix)
                    {
                        MyLink.Text = recordingWavFile;
                    }
                }
            }
        }

        private void oNToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ChatCombo = true;
            oNToolStripMenuItem.Text = "✅ ON";
            oFFToolStripMenuItem.Text = "OFF";
        }

        private void oFFToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ChatCombo = false;
            oNToolStripMenuItem.Text = "ON";
            oFFToolStripMenuItem.Text = "✅ OFF";
        }

        private void oNToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            PartyMode = true;
            oNToolStripMenuItem1.Text = "✅ ON";
            oFFToolStripMenuItem1.Text = "OFF";
        }

        private void oFFToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            PartyMode = false;
            oNToolStripMenuItem1.Text = "ON";
            oFFToolStripMenuItem1.Text = "✅ OFF";
        }

        private void yESToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TopMost = true;
            yESToolStripMenuItem.Text = "✅ YES";
            nOToolStripMenuItem.Text = "NO";
        }

        private void nOToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TopMost = false;
            yESToolStripMenuItem.Text = "YES";
            nOToolStripMenuItem.Text = "✅ NO";
        }

        private void enableToolStripMenuItem_Click(object sender, EventArgs e)
        {
            P2T = true;
            enableToolStripMenuItem.Text = "✅ Enable";
            disableToolStripMenuItem.Text = "Disable";
        }

        private void disableToolStripMenuItem_Click(object sender, EventArgs e)
        {
            P2T = false;
            enableToolStripMenuItem.Text = "Enable";
            disableToolStripMenuItem.Text = "✅ Disable";
        }

        public void Defaults()
        {
            // Disable push to talk.
            P2T = false;
            enableToolStripMenuItem.Text = "Enable";
            disableToolStripMenuItem.Text = "✅ Disable";

            // Enable the portable chatbox.
            oNToolStripMenuItem3.Text = "✅ ON";
            oFFToolStripMenuItem3.Text = "OFF";
            UseChatbox = true;

            string DesiredInputDevice = "Microphone (HyperX Cloud III)";

            if (comboBoxInputDevices.Items.Contains(DesiredInputDevice))
            {
                comboBoxInputDevices.SelectedItem = DesiredInputDevice;
            }
            else
            {
                MessageBox.Show($"Item '{DesiredInputDevice}' not found in the ComboBox.");
            }

            string DesiredOutputDevice = "CABLE-B Input (VB-Audio Cable B";

            if (comboBoxOutputDevices.Items.Contains(DesiredOutputDevice))
            {
                comboBoxOutputDevices.SelectedItem = DesiredOutputDevice;
            }
            else
            {
                MessageBox.Show($"Item '{DesiredOutputDevice}' not found in the ComboBox.");
            }

            string DesiredPreviewDevice = "Headphones (HyperX Cloud III)";

            if (Previews.Items.Contains(DesiredPreviewDevice))
            {
                Previews.SelectedItem = DesiredPreviewDevice;
            }
            else
            {
                MessageBox.Show($"Item '{DesiredPreviewDevice}' not found in the ComboBox.");
            }
        }

        private void button7_Click(object sender, EventArgs e)
        {
            LookButton.Focus();
            LookButton.Select();

            Max_Tokens = int.Parse(MaxTokenBox.Text);
            Chunk_Length = int.Parse(ChunkBox.Text);
            Top_P = float.Parse(TopPBox.Text);
            Repetition_Penalty = float.Parse(RepBox.Text);
            Temperature = float.Parse(TempBox.Text);
            toolStripStatusLabel1.Text = "AI Values Applied!";

            string[] lines = new string[]
            {
                MaxTokenBox.Text,
                ChunkBox.Text,
                TopPBox.Text,
                RepBox.Text,
                TempBox.Text
            };

            File.WriteAllLines(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\Settings.ini", lines);
        }

        private void button6_Click(object sender, EventArgs e)
        {
            MaxTokenBox.Text = "1024";
            ChunkBox.Text = "200";
            TopPBox.Text = "0.7";
            RepBox.Text = "1.1";
            TempBox.Text = "0.7";

            toolStripStatusLabel1.Text = "AI Values Applied!";
        }

        private void MaxTokenBox_Click(object sender, EventArgs e)
        {
            MaxTokenBox.SelectAll();
        }

        private void ChunkBox_Click(object sender, EventArgs e)
        {
            ChunkBox.SelectAll();
        }

        private void TopPBox_Click(object sender, EventArgs e)
        {
            TopPBox.SelectAll();
        }

        private void RepBox_Click(object sender, EventArgs e)
        {
            RepBox.SelectAll();
        }

        private void TempBox_Click(object sender, EventArgs e)
        {
            TempBox.SelectAll();
        }

        private void voiceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Create a new instance of OpenFileDialog
            OpenFileDialog openFileDialog = new OpenFileDialog();

            // Set the filter to only allow WAV files
            openFileDialog.Filter = "WAV Files (*.wav)|*.wav";
            openFileDialog.Title = "Select a WAV File";

            // Show the dialog and check if the user selected a file
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                // Get the selected file path
                string filePath = openFileDialog.FileName;
                if (File.Exists(outputFilePath))
                {
                    File.Delete(outputFilePath);
                }

                File.Move(filePath, outputFilePath);

                // You can add your logic here to process the selected WAV file
            }
        }

        private void stopRecordToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Stop recording
            waveSource.StopRecording();
            waveFile.Dispose();
            waveFile = null;
            toolStripStatusLabel1.Text = "Ready.";

            Thread.Sleep(333);

            // Get current date and time
            DateTime now = DateTime.Now;

            // Format the date and time to be safe for filenames
            string formattedDate = now.ToString("yyyyMMdd_HHmmss");

            // Create a filename
            string filename = $"MatchRecord_{formattedDate}.wav";

            string matchPath = @"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\Match\" + filename;

            File.Copy(outputFilePath, matchPath);

            // Create a new process to open the folder
            Process.Start("explorer.exe", @"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\Match\");
        }

        private void recordToolStripMenuItem_Click(object sender, EventArgs e)
        {
            waveSource.DeviceNumber = comboBoxInputDevices.SelectedIndex;

            // Start recording
            waveFile = new WaveFileWriter(outputFilePath, waveSource.WaveFormat);
            waveSource.StartRecording();
            toolStripStatusLabel1.Text = "[🔴 RECORDING]";
        }

        private void startToolStripMenuItem2_Click(object sender, EventArgs e)
        {
            Process.Start("cmd.exe");
            Thread.Sleep(5555);
            ISim.Keyboard.TextEntry("bash");
            Thread.Sleep(3333);
            ISim.Keyboard.KeyPress(VirtualKeyCode.RETURN);
            Thread.Sleep(3333);
            ISim.Keyboard.TextEntry("cd");
            Thread.Sleep(333);
            ISim.Keyboard.KeyPress(VirtualKeyCode.RETURN);
            Thread.Sleep(100);
            ISim.Keyboard.TextEntry("cd seed-vc");
            Thread.Sleep(133);
            ISim.Keyboard.KeyPress(VirtualKeyCode.RETURN);
            Thread.Sleep(300);
            ISim.Keyboard.TextEntry("conda activate Seeder");
            Thread.Sleep(393);
            ISim.Keyboard.KeyPress(VirtualKeyCode.RETURN);
            Thread.Sleep(300);
            ISim.Keyboard.TextEntry("python real-time-gui.py");
            Thread.Sleep(232);
            ISim.Keyboard.KeyPress(VirtualKeyCode.RETURN);
        }

        private static WaveOutEvent waveOutz;
        private static AudioFileReader audioFileReaderz;

        static void StopPlayback()
        {
            if (waveOutz != null)
            {
                waveOutz.Stop();
                waveOutz.Dispose();
                waveOutz = null;

                if (audioFileReaderz != null)
                {
                    audioFileReaderz.Dispose();
                    audioFileReaderz = null;
                }
            }
        }

        void PlayWavFile(string filePath)
        {
            StopPlayback(); // Stop any currently playing audio

            // Initialize the WaveOutEvent and AudioFileReader
            waveOutz = new WaveOutEvent();
            audioFileReaderz = new AudioFileReader(filePath);

            // Initialize and play the audio
            waveOutz.Init(audioFileReaderz);
            waveOutz.DeviceNumber = Previews.SelectedIndex;
            waveOutz.Play();

            // Subscribe to the PlaybackStopped event
            waveOutz.PlaybackStopped += OnPlaybackStopped;
        }

        private static void OnPlaybackStopped(object sender, StoppedEventArgs e)
        {
            StopPlayback(); // Ensure resources are cleaned up on stop
        }

        private void randomSeedToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        public static int GenerateRandomSeed()
        {
            // Create a byte array to hold the random value
            byte[] randomNumber = new byte[4];

            // Use RNGCryptoServiceProvider to fill the array with a cryptographically strong random value
            using (RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider())
            {
                rng.GetBytes(randomNumber);
            }

            // Convert the byte array to an integer
            int seed = BitConverter.ToInt32(randomNumber, 0);

            // Ensure the seed is positive and within the desired range
            return Math.Abs(seed % (int.MaxValue - 1)) + 1; // Ensures it's at least 1
        }

        private void Key_2_Click(object sender, EventArgs e)
        {
            WipeAss();
            try
            {
                if (!Directory.Exists(LocationKey))
                {
                    Directory.CreateDirectory(LocationKey);
                }

                string filePath = LocationKey + @"\Slash.wav";
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
                File.Copy(audioFilePath, filePath, true);
                KeyStrings[Num_Slash] = filePath;
                Key_2_SLASH.ForeColor = Color.Red;

                LookButton.Focus();
                LookButton.Select();
            }
            catch
            {
                // Handle exceptions
            }
        }

        private void Key_3_Click(object sender, EventArgs e)
        {
            WipeAss();
            try
            {
                if (!Directory.Exists(LocationKey))
                {
                    Directory.CreateDirectory(LocationKey);
                }

                string filePath = LocationKey + @"\Multiply.wav";
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
                File.Copy(audioFilePath, filePath, true);
                KeyStrings[Num_Multi] = filePath;
                Key_3_MULTI.ForeColor = Color.Red;

                LookButton.Focus();
                LookButton.Select();
            }
            catch
            {
                // Handle exceptions
            }
        }

        private void Key_4_Click(object sender, EventArgs e)
        {
            WipeAss();
            try
            {
                if (!Directory.Exists(LocationKey))
                {
                    Directory.CreateDirectory(LocationKey);
                }

                string filePath = LocationKey + @"\Subtract.wav";
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
                File.Copy(audioFilePath, filePath, true);
                KeyStrings[Num_Sub] = filePath;
                Key_4_MIN.ForeColor = Color.Red;

                LookButton.Focus();
                LookButton.Select();
            }
            catch
            {
                // Handle exceptions
            }
        }

        private void Key_5_Click(object sender, EventArgs e)
        {
            try
            {
                if (!Directory.Exists(LocationKey))
                {
                    Directory.CreateDirectory(LocationKey);
                }

                string filePath = LocationKey + @"\Seven.wav";
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
                File.Copy(audioFilePath, filePath, true);
                KeyStrings[Num_7] = filePath;
                Key_5_SEVEN.ForeColor = Color.Red;

                LookButton.Focus();
                LookButton.Select();
            }
            catch
            {
                // Handle exceptions
            }
        }

        private void Key_6_Click(object sender, EventArgs e)
        {
            try
            {
                if (!Directory.Exists(LocationKey))
                {
                    Directory.CreateDirectory(LocationKey);
                }

                string filePath = LocationKey + @"\Eight.wav";
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
                File.Copy(audioFilePath, filePath, true);
                KeyStrings[Num_8] = filePath;
                Key_6_EIGHT.ForeColor = Color.Red;

                LookButton.Focus();
                LookButton.Select();
            }
            catch
            {
                // Handle exceptions
            }
        }

        private void Key_7_Click(object sender, EventArgs e)
        {
            try
            {
                if (!Directory.Exists(LocationKey))
                {
                    Directory.CreateDirectory(LocationKey);
                }

                string filePath = LocationKey + @"\Nine.wav";
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
                File.Copy(audioFilePath, filePath, true);
                KeyStrings[Num_9] = filePath;
                Key_7_NINE.ForeColor = Color.Red;

                LookButton.Focus();
                LookButton.Select();
            }
            catch
            {
                // Handle exceptions
            }
        }

        private void Key_8_Click(object sender, EventArgs e)
        {
            try
            {
                if (!Directory.Exists(LocationKey))
                {
                    Directory.CreateDirectory(LocationKey);
                }

                string filePath = LocationKey + @"\Plus.wav";
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
                File.Copy(audioFilePath, filePath, true);
                KeyStrings[Num_Plus] = filePath;
                Key_8_PLUS.ForeColor = Color.Red;

                LookButton.Focus();
                LookButton.Select();
            }
            catch
            {
                // Handle exceptions
            }
        }

        private void Key_9_Click(object sender, EventArgs e)
        {
            try
            {
                if (!Directory.Exists(LocationKey))
                {
                    Directory.CreateDirectory(LocationKey);
                }

                string filePath = LocationKey + @"\Four.wav";
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
                File.Copy(audioFilePath, filePath, true);
                KeyStrings[Num_4] = filePath;
                Key_9_FOUR.ForeColor = Color.Red;

                LookButton.Focus();
                LookButton.Select();
            }
            catch
            {
                // Handle exceptions
            }
        }

        private void Key_10_Click(object sender, EventArgs e)
        {
            try
            {
                if (!Directory.Exists(LocationKey))
                {
                    Directory.CreateDirectory(LocationKey);
                }

                string filePath = LocationKey + @"\Five.wav";
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
                File.Copy(audioFilePath, filePath, true);
                KeyStrings[Num_5] = filePath;
                Key_FIVE.ForeColor = Color.Red;

                LookButton.Focus();
                LookButton.Select();
            }
            catch
            {
                // Handle exceptions
            }
        }

        private void Key_11_Click(object sender, EventArgs e)
        {
            try
            {
                if (!Directory.Exists(LocationKey))
                {
                    Directory.CreateDirectory(LocationKey);
                }

                string filePath = LocationKey + @"\Six.wav";
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
                File.Copy(audioFilePath, filePath, true);
                KeyStrings[Num_6] = filePath;
                Key_11_SIX.ForeColor = Color.Red;

                LookButton.Focus();
                LookButton.Select();
            }
            catch
            {
                // Handle exceptions
            }
        }

        private void Key_12_Click(object sender, EventArgs e)
        {
            try
            {
                if (!Directory.Exists(LocationKey))
                {
                    Directory.CreateDirectory(LocationKey);
                }

                string filePath = LocationKey + @"\One.wav";
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
                File.Copy(audioFilePath, filePath, true);
                KeyStrings[Num_1] = filePath;
                Key_12_ONE.ForeColor = Color.Red;

                LookButton.Focus();
                LookButton.Select();
            }
            catch
            {
                // Handle exceptions
            }
        }

        private void Key_13_Click(object sender, EventArgs e)
        {
            try
            {
                if (!Directory.Exists(LocationKey))
                {
                    Directory.CreateDirectory(LocationKey);
                }

                string filePath = LocationKey + @"\Two.wav";
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
                File.Copy(audioFilePath, filePath, true);
                KeyStrings[Num_2] = filePath;
                Key_13_TWO.ForeColor = Color.Red;

                LookButton.Focus();
                LookButton.Select();
            }
            catch
            {
                // Handle exceptions
            }
        }

        private void Key_14_Click(object sender, EventArgs e)
        {
            try
            {
                if (!Directory.Exists(LocationKey))
                {
                    Directory.CreateDirectory(LocationKey);
                }

                string filePath = LocationKey + @"\Three.wav";
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
                File.Copy(audioFilePath, filePath, true);
                KeyStrings[Num_3] = filePath;
                Key_14_THREE.ForeColor = Color.Red;

                LookButton.Focus();
                LookButton.Select();
            }
            catch
            {
                // Handle exceptions
            }
        }

        private void Key_16_Click(object sender, EventArgs e)
        {
            try
            {
                if (!Directory.Exists(LocationKey))
                {
                    Directory.CreateDirectory(LocationKey);
                }

                string filePath = LocationKey + @"\Zero.wav";
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
                File.Copy(audioFilePath, filePath, true);
                KeyStrings[Num_0] = filePath;
                Key_16_ZERO.ForeColor = Color.Red;

                LookButton.Focus();
                LookButton.Select();
            }
            catch
            {
                // Handle exceptions
            }
        }

        private void LoadKeys()
        {
            string selectedPath = string.Empty;

            if (Male)
            {
                selectedPath = @"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\Presets\MALE\" + VoicesList.SelectedItem + @"\Keys";
            }
            else
            {
                selectedPath = @"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\Presets\FEMALE\" + VoicesList.SelectedItem + @"\Keys";
            }

            LocationKey = selectedPath;

            KeyStrings = new string[28];

            Key_1_NUM.ForeColor = button1.ForeColor;
            Key_2_SLASH.ForeColor = button1.ForeColor;
            Key_3_MULTI.ForeColor = button1.ForeColor;
            Key_4_MIN.ForeColor = button1.ForeColor;
            Key_5_SEVEN.ForeColor = button1.ForeColor;
            Key_6_EIGHT.ForeColor = button1.ForeColor;
            Key_7_NINE.ForeColor = button1.ForeColor;
            Key_8_PLUS.ForeColor = button1.ForeColor;
            Key_9_FOUR.ForeColor = button1.ForeColor;
            Key_FIVE.ForeColor = button1.ForeColor;
            Key_11_SIX.ForeColor = button1.ForeColor;
            Key_12_ONE.ForeColor = button1.ForeColor;
            Key_13_TWO.ForeColor = button1.ForeColor;
            Key_14_THREE.ForeColor = button1.ForeColor;
            Key_15.ForeColor = button1.ForeColor;
            Key_16_ZERO.ForeColor = button1.ForeColor;
            F2B.ForeColor = button1.ForeColor;
            F5B.ForeColor = button1.ForeColor;
            F6B.ForeColor = button1.ForeColor;
            F7B.ForeColor = button1.ForeColor;
            F8B.ForeColor = button1.ForeColor;
            F3BB.ForeColor = button1.ForeColor;
            F4B.ForeColor = button1.ForeColor;
            F1B.ForeColor = button1.ForeColor;
            F2B.ForeColor = button1.ForeColor;
            F9B.ForeColor = button1.ForeColor;
            F10B.ForeColor = button1.ForeColor;
            F11B.ForeColor = button1.ForeColor;
            F12B.ForeColor = button1.ForeColor;
            // Create a Font object with the default font family and size, without bold or italic
            var defaultFont = new Font(this.Font.FontFamily, this.Font.Size, FontStyle.Regular);

            // Now set the Font property of each control
            Key_1_NUM.Font = defaultFont;
            Key_2_SLASH.Font = defaultFont;
            Key_3_MULTI.Font = defaultFont;
            Key_4_MIN.Font = defaultFont;
            Key_5_SEVEN.Font = defaultFont;
            Key_6_EIGHT.Font = defaultFont;
            Key_7_NINE.Font = defaultFont;
            Key_8_PLUS.Font = defaultFont;
            Key_9_FOUR.Font = defaultFont;
            Key_FIVE.Font = defaultFont;
            Key_11_SIX.Font = defaultFont;
            Key_12_ONE.Font = defaultFont;
            Key_13_TWO.Font = defaultFont;
            Key_14_THREE.Font = defaultFont;
            Key_15.Font = defaultFont;
            Key_16_ZERO.Font = defaultFont;
            F2B.Font = defaultFont;
            F5B.Font = defaultFont;
            F6B.Font = defaultFont;
            F7B.Font = defaultFont;
            F8B.Font = defaultFont;
            F3BB.Font = defaultFont;
            F4B.Font = defaultFont;
            F1B.Font = defaultFont;
            F9B.Font = defaultFont;
            F10B.Font = defaultFont;
            F11B.Font = defaultFont;
            F12B.Font = defaultFont;

            if (Directory.Exists(selectedPath))
            {
                LocationKey = selectedPath;
                // Iterate through each file in the selected directory
                foreach (var file in Directory.GetFiles(selectedPath))
                {
                    var fileName = Path.GetFileName(file);

                    if (fileName.StartsWith("Sla"))
                    {
                        Key_2_SLASH.ForeColor = Color.Red;
                        Key_2_SLASH.Font = new Font(Key_2_SLASH.Font, FontStyle.Bold);
                        KeyStrings[Num_Slash] = file;
                    }
                    if (fileName.StartsWith("Mult"))
                    {
                        Key_3_MULTI.ForeColor = Color.Red;
                        Key_3_MULTI.Font = new Font(Key_3_MULTI.Font, FontStyle.Bold);
                        KeyStrings[Num_Multi] = file;
                    }
                    if (fileName.StartsWith("Subtract"))
                    {
                        Key_4_MIN.ForeColor = Color.Red;
                        Key_4_MIN.Font = new Font(Key_4_MIN.Font, FontStyle.Bold);
                        KeyStrings[Num_Sub] = file;
                    }
                    if (fileName.StartsWith("Seven"))
                    {
                        Key_5_SEVEN.ForeColor = Color.Red;
                        Key_5_SEVEN.Font = new Font(Key_5_SEVEN.Font, FontStyle.Bold);
                        KeyStrings[Num_7] = file;
                    }
                    if (fileName.StartsWith("Eight"))
                    {
                        Key_6_EIGHT.ForeColor = Color.Red;
                        Key_6_EIGHT.Font = new Font(Key_6_EIGHT.Font, FontStyle.Bold);
                        KeyStrings[Num_8] = file;
                    }
                    if (fileName.StartsWith("Nine"))
                    {
                        Key_7_NINE.ForeColor = Color.Red;
                        Key_7_NINE.Font = new Font(Key_7_NINE.Font, FontStyle.Bold);
                        KeyStrings[Num_9] = file;
                    }
                    if (fileName.StartsWith("Plus"))
                    {
                        Key_8_PLUS.ForeColor = Color.Red;
                        Key_8_PLUS.Font = new Font(Key_8_PLUS.Font, FontStyle.Bold);
                        KeyStrings[Num_Plus] = file;
                    }
                    if (fileName.StartsWith("Four"))
                    {
                        Key_9_FOUR.ForeColor = Color.Red;
                        Key_9_FOUR.Font = new Font(Key_9_FOUR.Font, FontStyle.Bold);
                        KeyStrings[Num_4] = file;
                    }
                    if (fileName.StartsWith("Five"))
                    {
                        Key_FIVE.ForeColor = Color.Red;
                        Key_FIVE.Font = new Font(Key_FIVE.Font, FontStyle.Bold);
                        KeyStrings[Num_5] = file;
                    }
                    if (fileName.StartsWith("Six"))
                    {
                        Key_11_SIX.ForeColor = Color.Red;
                        Key_11_SIX.Font = new Font(Key_11_SIX.Font, FontStyle.Bold);
                        KeyStrings[Num_6] = file;
                    }
                    if (fileName.StartsWith("One"))
                    {
                        Key_12_ONE.ForeColor = Color.Red;
                        Key_12_ONE.Font = new Font(Key_12_ONE.Font, FontStyle.Bold);
                        KeyStrings[Num_1] = file;
                    }
                    if (fileName.StartsWith("Two"))
                    {
                        Key_13_TWO.ForeColor = Color.Red;
                        Key_13_TWO.Font = new Font(Key_13_TWO.Font, FontStyle.Bold);
                        KeyStrings[Num_2] = file;
                    }
                    if (fileName.StartsWith("Three"))
                    {
                        Key_14_THREE.ForeColor = Color.Red;
                        Key_14_THREE.Font = new Font(Key_14_THREE.Font, FontStyle.Bold);
                        KeyStrings[Num_3] = file;
                    }
                    if (fileName.StartsWith("Zero"))
                    {
                        Key_16_ZERO.ForeColor = Color.Red;
                        Key_16_ZERO.Font = new Font(Key_16_ZERO.Font, FontStyle.Bold);
                        KeyStrings[Num_0] = file;
                    }
                    if (fileName.StartsWith("F5"))
                    {
                        F5B.ForeColor = Color.Red;
                        F5B.Font = new Font(F5B.Font, FontStyle.Bold);
                        KeyStrings[F5_Key] = file;
                    }
                    if (fileName.StartsWith("F6"))
                    {
                        F6B.ForeColor = Color.Red;
                        F6B.Font = new Font(F6B.Font, FontStyle.Bold);
                        KeyStrings[F6_Key] = file;
                    }
                    if (fileName.StartsWith("F7"))
                    {
                        F7B.ForeColor = Color.Red;
                        F7B.Font = new Font(F7B.Font, FontStyle.Bold);
                        KeyStrings[F7_Key] = file;
                    }
                    if (fileName.StartsWith("F8"))
                    {
                        F8B.ForeColor = Color.Red;
                        F8B.Font = new Font(F8B.Font, FontStyle.Bold);
                        KeyStrings[F8_Key] = file;
                    }
                    if (fileName.StartsWith("F3"))
                    {
                        F3BB.ForeColor = Color.Red;
                        F3BB.Font = new Font(F3BB.Font, FontStyle.Bold);
                        KeyStrings[F3_Key] = file;
                    }
                    if (fileName.StartsWith("F4"))
                    {
                        F4B.ForeColor = Color.Red;
                        F4B.Font = new Font(F4B.Font, FontStyle.Bold);
                        KeyStrings[F4_Key] = file;
                    }
                    if (fileName.StartsWith("F9"))
                    {
                        F9B.ForeColor = Color.Red;
                        F9B.Font = new Font(F9B.Font, FontStyle.Bold);
                        KeyStrings[F9_Key] = file;
                    }
                    if (fileName.StartsWith("F10"))
                    {
                        F10B.ForeColor = Color.Red;
                        F10B.Font = new Font(F10B.Font, FontStyle.Bold);
                        KeyStrings[F10_Key] = file;
                    }
                    if (fileName.StartsWith("F11"))
                    {
                        F11B.ForeColor = Color.Red;
                        F11B.Font = new Font(F11B.Font, FontStyle.Bold);
                        KeyStrings[F11_Key] = file;
                    }
                    if (fileName.StartsWith("F12"))
                    {
                        F12B.ForeColor = Color.Red;
                        F12B.Font = new Font(F12B.Font, FontStyle.Bold);
                        KeyStrings[F12_Key] = file;
                    }
                    if (fileName.StartsWith("F_One"))
                    {
                        F1B.ForeColor = Color.Red;
                        F1B.Font = new Font(F1B.Font, FontStyle.Bold);
                        KeyStrings[F1_Key] = file;
                    }
                    if (fileName.StartsWith("F2"))
                    {
                        F2B.ForeColor = Color.Red;
                        F2B.Font = new Font(F2B.Font, FontStyle.Bold);
                        KeyStrings[F2_Key] = file;
                    }
                    if (fileName.StartsWith("Positive"))
                    {
                        Key_1_NUM.ForeColor = Color.Red;
                        Key_1_NUM.Font = new Font(Key_1_NUM.Font, FontStyle.Bold);
                        KeyStrings[OPlus] = file;
                    }
                    if (fileName.StartsWith("Negative"))
                    {
                        Key_15.ForeColor = Color.Red;
                        Key_15.Font = new Font(Key_15.Font, FontStyle.Bold);
                        KeyStrings[OMinus] = file;
                    }
                }
            }
        }

        private void Key_1_NUM_Click(object sender, EventArgs e)
        {
            WipeAss();
            try
            {
                if (!Directory.Exists(LocationKey))
                {
                    Directory.CreateDirectory(LocationKey);
                }

                string filePath = LocationKey + @"\Positive.wav";
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
                File.Copy(audioFilePath, filePath, true);
                KeyStrings[OPlus] = filePath;
                Key_1_NUM.ForeColor = Color.Red;

                LookButton.Focus();
                LookButton.Select();
            }
            catch
            {
            }
        }

        private void button5_Click_1(object sender, EventArgs e)
        {
            if (Directory.Exists(LocationKey))
            {
                Directory.Delete(LocationKey, true);
                LoadKeys();
            }
        }

        private void F5B_Click(object sender, EventArgs e)
        {
            WipeAss();
            try
            {
                if (!Directory.Exists(LocationKey))
                {
                    Directory.CreateDirectory(LocationKey);
                }

                string filePath = LocationKey + @"\F5.wav";
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
                File.Copy(audioFilePath, filePath, true);
                KeyStrings[F5_Key] = filePath;
                F5B.ForeColor = Color.Red;

                LookButton.Focus();
                LookButton.Select();
            }
            catch
            {
                if (!Directory.Exists(LocationKey))
                {
                    Directory.CreateDirectory(LocationKey);
                }

                string filePath = LocationKey + @"\F5.wav";
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
                File.Copy(audioFilePath, filePath, true);
                KeyStrings[F5_Key] = filePath;
                F5B.ForeColor = Color.Red;

                LookButton.Focus();
                LookButton.Select();
            }
        }

        private void F6B_Click(object sender, EventArgs e)
        {
            WipeAss();
            try
            {
                if (!Directory.Exists(LocationKey))
                {
                    Directory.CreateDirectory(LocationKey);
                }

                string filePath = LocationKey + @"\F6.wav";
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
                File.Copy(audioFilePath, filePath, true);
                KeyStrings[F6_Key] = filePath;
                F6B.ForeColor = Color.Red;

                LookButton.Focus();
                LookButton.Select();
            }
            catch
            {
                // Handle exceptions
            }
        }

        private void F7B_Click(object sender, EventArgs e)
        {
            WipeAss();
            if (!Directory.Exists(LocationKey))
            {
                Directory.CreateDirectory(LocationKey);
            }

            string filePath = LocationKey + @"\F7.wav";
            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }
            File.Copy(audioFilePath, filePath, true);
            KeyStrings[F7_Key] = filePath;
            F7B.ForeColor = Color.Red;

            LookButton.Focus();
            LookButton.Select();
        }

        private void F8B_Click(object sender, EventArgs e)
        {
            WipeAss();
            try
            {
                if (!Directory.Exists(LocationKey))
                {
                    Directory.CreateDirectory(LocationKey);
                }

                string filePath = LocationKey + @"\F8.wav";
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
                File.Copy(audioFilePath, filePath, true);
                KeyStrings[F8_Key] = filePath;
                F8B.ForeColor = Color.Red;

                LookButton.Focus();
                LookButton.Select();
            }
            catch
            {
                // Handle exceptions
            }
        }

        private void F9B_Click(object sender, EventArgs e)
        {
            WipeAss();
            try
            {
                if (!Directory.Exists(LocationKey))
                {
                    Directory.CreateDirectory(LocationKey);
                }

                string filePath = LocationKey + @"\F9.wav";
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
                File.Copy(audioFilePath, filePath, true);
                KeyStrings[F9_Key] = filePath;
                F9B.ForeColor = Color.Red;

                LookButton.Focus();
                LookButton.Select();
            }
            catch
            {

            }
        }

        private void F10B_Click(object sender, EventArgs e)
        {
            WipeAss();
            try
            {
                if (!Directory.Exists(LocationKey))
                {
                    Directory.CreateDirectory(LocationKey);
                }

                string filePath = LocationKey + @"\F10.wav";
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
                File.Copy(audioFilePath, filePath, true);
                KeyStrings[F10_Key] = filePath;
                F10B.ForeColor = Color.Red;

                LookButton.Focus();
                LookButton.Select();
            }
            catch
            {

            }
        }

        private void F11B_Click(object sender, EventArgs e)
        {
            WipeAss();
            try
            {
                if (!Directory.Exists(LocationKey))
                {
                    Directory.CreateDirectory(LocationKey);
                }

                string filePath = LocationKey + @"\F11.wav";
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
                File.Copy(audioFilePath, filePath, true);
                KeyStrings[F11_Key] = filePath;
                F11B.ForeColor = Color.Red;

                LookButton.Focus();
                LookButton.Select();
            }
            catch
            {

            }
        }

        private void F12B_Click(object sender, EventArgs e)
        {
            WipeAss();
            try
            {
                if (!Directory.Exists(LocationKey))
                {
                    Directory.CreateDirectory(LocationKey);
                }

                string filePath = LocationKey + @"\F12.wav";
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
                File.Copy(audioFilePath, filePath, true);
                KeyStrings[F12_Key] = filePath;
                F12B.ForeColor = Color.Red;

                LookButton.Focus();
                LookButton.Select();
            }
            catch
            {

            }
        }

        private void F4B_Click(object sender, EventArgs e)
        {
            WipeAss();
            try
            {
                if (!Directory.Exists(LocationKey))
                {
                    Directory.CreateDirectory(LocationKey);
                }

                string filePath = LocationKey + @"\F4.wav";
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
                File.Copy(audioFilePath, filePath, true);
                KeyStrings[F4_Key] = filePath;
                F4B.ForeColor = Color.Red;

                LookButton.Focus();
                LookButton.Select();
            }
            catch
            {

            }
        }

        private void F3BB_Click(object sender, EventArgs e)
        {
            WipeAss();
            try
            {
                if (!Directory.Exists(LocationKey))
                {
                    Directory.CreateDirectory(LocationKey);
                }

                string filePath = LocationKey + @"\F3.wav";
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
                File.Copy(audioFilePath, filePath, true);
                KeyStrings[F3_Key] = filePath;
                F3BB.ForeColor = Color.Red;

                LookButton.Focus();
                LookButton.Select();
            }
            catch
            {

            }
        }

        private void F1B_Click(object sender, EventArgs e)
        {
            WipeAss();
            try
            {
                if (!Directory.Exists(LocationKey))
                {
                    Directory.CreateDirectory(LocationKey);
                }

                string filePath = LocationKey + @"\F_One.wav";
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
                File.Copy(audioFilePath, filePath, true);
                KeyStrings[F1_Key] = filePath;
                F1B.ForeColor = Color.Red;

                LookButton.Focus();
                LookButton.Select();
            }
            catch
            {

            }
        }

        private void F2B_Click(object sender, EventArgs e)
        {
            WipeAss();
            try
            {
                if (!Directory.Exists(LocationKey))
                {
                    Directory.CreateDirectory(LocationKey);
                }

                string filePath = LocationKey + @"\F2.wav";
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
                File.Copy(audioFilePath, filePath, true);
                KeyStrings[F2_Key] = filePath;
                F2B.ForeColor = Color.Red;

                LookButton.Focus();
                LookButton.Select();
            }
            catch
            {

            }
        }

        private void confirmModeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ConfMode = true;
        }

        private void Key_15_Click(object sender, EventArgs e)
        {
            if (!Directory.Exists(LocationKey))
            {
                Directory.CreateDirectory(LocationKey);
            }

            string filePath = LocationKey + @"\Negative.wav";
            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }
            File.Copy(audioFilePath, filePath, true);
            KeyStrings[OMinus] = filePath;
            Key_15.ForeColor = Color.Red;

            LookButton.Focus();
            LookButton.Select();
        }

        private void fishSpeechToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            FishSpeechMode = true;
            ZonosTTSMode = false;
            panel5.Location = panel9.Location;
            panel9.Location = OffMap.Location;
        }

        private void zonosToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FishSpeechMode = false;
            ZonosTTSMode = true;
            panel7.Location = panel5.Location;
            panel5.Location = OffMap.Location;
        }

        private async void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex == 0)
            {
                IndexTTSBool = true;
                FishSpeechMode = false;
                ZonosTTSMode = false;
                indexpnl.Location = panel9.Location;
                panel5.Location = OffMap.Location;
                panel9.Location = OffMap.Location;
                toolStripStatusLabel2.Text = "(Powered by | Index TTS)";
            }
            if (comboBox1.SelectedIndex == 1)
            {
                FishSpeechMode = true;
                ZonosTTSMode = false;
                panel5.Location = panel9.Location;
                panel9.Location = OffMap.Location;
                toolStripStatusLabel2.Text = "(Powered by | Fish Speech v1.5 🐟)";
            }
            if (comboBox1.SelectedIndex == 2)
            {
                FishSpeechMode = false;
                ZonosTTSMode = true;
                panel7.Location = panel9.Location;
                panel9.Location = OffMap.Location;
                toolStripStatusLabel2.Text = "(Powered by | Zonos-v0.1)";
            }
        }

        private void button13_Click(object sender, EventArgs e)
        {
            PlayWavFile(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\SFX\Click.wav");
            panel8.Location = panel7.Location;
            panel7.Location = OffMap.Location;
        }

        private void button11_Click(object sender, EventArgs e)
        {
            PlayWavFile(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\SFX\Click.wav");
            panel7.Location = panel8.Location;
            panel8.Location = OffMap.Location;
        }

        private void HN_Click(object sender, EventArgs e)
        {
            LookButton.Focus();
            LookButton.Select();
            // Parse the current value from HappyBox
            float Intilize;
            if (float.TryParse(HappyBox.Text, out Intilize))
            {
                // Decrement by 0.1
                Intilize -= 0.1f;

                // Ensure it does not go below zero
                if (Intilize < 0)
                {
                    Intilize = 0;
                }

                // Update HappyBox with the new value
                HappyBox.Text = Intilize.ToString("0.0"); // Format to one decimal place
            }
            else
            {
                // Handle invalid input
                HappyBox.Text = "0.0"; // or set to a default value
            }
        }

        private void HP_Click(object sender, EventArgs e)
        {
            LookButton.Focus();
            LookButton.Select();
            // Parse the current value from HappyBox
            float Intilize;
            if (float.TryParse(HappyBox.Text, out Intilize))
            {
                // Increment by 0.1
                Intilize += 0.1f;

                // Ensure it does not exceed 1.0
                if (Intilize > 1.0f)
                {
                    Intilize = 1.0f;
                }

                // Update HappyBox with the new value
                HappyBox.Text = Intilize.ToString("0.0"); // Format to one decimal place
            }
            else
            {
                // Handle invalid input
                HappyBox.Text = "0.0"; // or set to a default value
            }
        }

        private void GN_Click(object sender, EventArgs e)
        {
            LookButton.Focus();
            LookButton.Select();
            // Parse the current value from HappyBox
            float Intilize;
            if (float.TryParse(GrossBox.Text, out Intilize))
            {
                // Decrement by 0.1
                Intilize -= 0.1f;

                // Ensure it does not go below zero
                if (Intilize < 0)
                {
                    Intilize = 0;
                }

                // Update HappyBox with the new value
                GrossBox.Text = Intilize.ToString("0.0"); // Format to one decimal place
            }
            else
            {
                // Handle invalid input
                GrossBox.Text = "0.0"; // or set to a default value
            }
        }

        private void GP_Click(object sender, EventArgs e)
        {
            LookButton.Focus();
            LookButton.Select();
            // Parse the current value from HappyBox
            float Intilize;
            if (float.TryParse(GrossBox.Text, out Intilize))
            {
                // Increment by 0.1
                Intilize += 0.1f;

                // Ensure it does not exceed 1.0
                if (Intilize > 1.0f)
                {
                    Intilize = 1.0f;
                }

                // Update HappyBox with the new value
                GrossBox.Text = Intilize.ToString("0.0"); // Format to one decimal place
            }
            else
            {
                // Handle invalid input
                GrossBox.Text = "0.0"; // or set to a default value
            }
        }

        private void SN_Click(object sender, EventArgs e)
        {
            LookButton.Focus();
            LookButton.Select();
            // Parse the current value from HappyBox
            float Intilize;
            if (float.TryParse(SadBox.Text, out Intilize))
            {
                // Decrement by 0.1
                Intilize -= 0.1f;

                // Ensure it does not go below zero
                if (Intilize < 0)
                {
                    Intilize = 0;
                }

                // Update HappyBox with the new value
                SadBox.Text = Intilize.ToString("0.0"); // Format to one decimal place
            }
            else
            {
                // Handle invalid input
                SadBox.Text = "0.0"; // or set to a default value
            }
        }

        private void SP_Click(object sender, EventArgs e)
        {
            LookButton.Focus();
            LookButton.Select();
            // Parse the current value from HappyBox
            float Intilize;
            if (float.TryParse(SadBox.Text, out Intilize))
            {
                // Increment by 0.1
                Intilize += 0.1f;

                // Ensure it does not exceed 1.0
                if (Intilize > 1.0f)
                {
                    Intilize = 1.0f;
                }

                // Update HappyBox with the new value
                SadBox.Text = Intilize.ToString("0.0"); // Format to one decimal place
            }
            else
            {
                // Handle invalid input
                SadBox.Text = "0.0"; // or set to a default value
            }
        }

        private void SCN_Click(object sender, EventArgs e)
        {
            LookButton.Focus();
            LookButton.Select();
            // Parse the current value from HappyBox
            float Intilize;
            if (float.TryParse(ScaredBox.Text, out Intilize))
            {
                // Decrement by 0.1
                Intilize -= 0.1f;

                // Ensure it does not go below zero
                if (Intilize < 0)
                {
                    Intilize = 0;
                }

                // Update HappyBox with the new value
                ScaredBox.Text = Intilize.ToString("0.0"); // Format to one decimal place
            }
            else
            {
                // Handle invalid input
                ScaredBox.Text = "0.0"; // or set to a default value
            }
        }

        private void SCP_Click(object sender, EventArgs e)
        {
            LookButton.Focus();
            LookButton.Select();
            // Parse the current value from HappyBox
            float Intilize;
            if (float.TryParse(ScaredBox.Text, out Intilize))
            {
                // Increment by 0.1
                Intilize += 0.1f;

                // Ensure it does not exceed 1.0
                if (Intilize > 1.0f)
                {
                    Intilize = 1.0f;
                }

                // Update HappyBox with the new value
                ScaredBox.Text = Intilize.ToString("0.0"); // Format to one decimal place
            }
            else
            {
                // Handle invalid input
                ScaredBox.Text = "0.0"; // or set to a default value
            }
        }

        private void AN_Click(object sender, EventArgs e)
        {
            LookButton.Focus();
            LookButton.Select();
            // Parse the current value from HappyBox
            float Intilize;
            if (float.TryParse(AngryBox.Text, out Intilize))
            {
                // Decrement by 0.1
                Intilize -= 0.1f;

                // Ensure it does not go below zero
                if (Intilize < 0)
                {
                    Intilize = 0;
                }

                // Update HappyBox with the new value
                AngryBox.Text = Intilize.ToString("0.0"); // Format to one decimal place
            }
            else
            {
                // Handle invalid input
                AngryBox.Text = "0.0"; // or set to a default value
            }
        }

        private void AP_Click(object sender, EventArgs e)
        {
            LookButton.Focus();
            LookButton.Select();
            // Parse the current value from HappyBox
            float Intilize;
            if (float.TryParse(AngryBox.Text, out Intilize))
            {
                // Increment by 0.1
                Intilize += 0.1f;

                // Ensure it does not exceed 1.0
                if (Intilize > 1.0f)
                {
                    Intilize = 1.0f;
                }

                // Update HappyBox with the new value
                AngryBox.Text = Intilize.ToString("0.0"); // Format to one decimal place
            }
            else
            {
                // Handle invalid input
                AngryBox.Text = "0.0"; // or set to a default value
            }
        }

        private void ON_Click(object sender, EventArgs e)
        {
            LookButton.Focus();
            LookButton.Select();
            // Parse the current value from HappyBox
            float Intilize;
            if (float.TryParse(OtherBox.Text, out Intilize))
            {
                // Decrement by 0.1
                Intilize -= 0.1f;

                // Ensure it does not go below zero
                if (Intilize < 0)
                {
                    Intilize = 0;
                }

                // Update HappyBox with the new value
                OtherBox.Text = Intilize.ToString("0.0"); // Format to one decimal place
            }
            else
            {
                // Handle invalid input
                OtherBox.Text = "0.0"; // or set to a default value
            }
        }

        private void OP_Click(object sender, EventArgs e)
        {
            LookButton.Focus();
            LookButton.Select();
            // Parse the current value from HappyBox
            float Intilize;
            if (float.TryParse(OtherBox.Text, out Intilize))
            {
                // Increment by 0.1
                Intilize += 0.1f;

                // Ensure it does not exceed 1.0
                if (Intilize > 1.0f)
                {
                    Intilize = 1.0f;
                }

                // Update HappyBox with the new value
                OtherBox.Text = Intilize.ToString("0.0"); // Format to one decimal place
            }
            else
            {
                // Handle invalid input
                OtherBox.Text = "0.0"; // or set to a default value
            }
        }

        private void NN_Click(object sender, EventArgs e)
        {
            LookButton.Focus();
            LookButton.Select();
            // Parse the current value from HappyBox
            float Intilize;
            if (float.TryParse(NeutralBox.Text, out Intilize))
            {
                // Decrement by 0.1
                Intilize -= 0.1f;

                // Ensure it does not go below zero
                if (Intilize < 0)
                {
                    Intilize = 0;
                }

                // Update HappyBox with the new value
                NeutralBox.Text = Intilize.ToString("0.0"); // Format to one decimal place
            }
            else
            {
                // Handle invalid input
                NeutralBox.Text = "0.0"; // or set to a default value
            }
        }

        private void NP_Click(object sender, EventArgs e)
        {
            LookButton.Focus();
            LookButton.Select();
            // Parse the current value from HappyBox
            float Intilize;
            if (float.TryParse(NeutralBox.Text, out Intilize))
            {
                // Increment by 0.1
                Intilize += 0.1f;

                // Ensure it does not exceed 1.0
                if (Intilize > 1.0f)
                {
                    Intilize = 1.0f;
                }

                // Update HappyBox with the new value
                NeutralBox.Text = Intilize.ToString("0.0"); // Format to one decimal place
            }
            else
            {
                // Handle invalid input
                NeutralBox.Text = "0.0"; // or set to a default value
            }
        }

        private void SHN_Click(object sender, EventArgs e)
        {
            LookButton.Focus();
            LookButton.Select();
            // Parse the current value from HappyBox
            float Intilize;
            if (float.TryParse(ShockedBox.Text, out Intilize))
            {
                // Decrement by 0.1
                Intilize -= 0.1f;

                // Ensure it does not go below zero
                if (Intilize < 0)
                {
                    Intilize = 0;
                }

                // Update HappyBox with the new value
                ShockedBox.Text = Intilize.ToString("0.0"); // Format to one decimal place
            }
            else
            {
                // Handle invalid input
                ShockedBox.Text = "0.0"; // or set to a default value
            }
        }

        private void SHP_Click(object sender, EventArgs e)
        {
            LookButton.Focus();
            LookButton.Select();
            // Parse the current value from HappyBox
            float Intilize;
            if (float.TryParse(ShockedBox.Text, out Intilize))
            {
                // Increment by 0.1
                Intilize += 0.1f;

                // Ensure it does not exceed 1.0
                if (Intilize > 1.0f)
                {
                    Intilize = 1.0f;
                }

                // Update HappyBox with the new value
                ShockedBox.Text = Intilize.ToString("0.0"); // Format to one decimal place
            }
            else
            {
                // Handle invalid input
                ShockedBox.Text = "0.0"; // or set to a default value
            }
        }

        private void button8_Click(object sender, EventArgs e)
        {
            HappyBox.Text = "0.0";
            SadBox.Text = "0.0";
            ShockedBox.Text = "0.0";
            AngryBox.Text = "0.0";
            NeutralBox.Text = "0.0";
            OtherBox.Text = "0.0";
            GrossBox.Text = "0.0";
            ScaredBox.Text = "0.0";
        }

        private void button9_Click(object sender, EventArgs e)
        {
            LookButton.Focus();
            LookButton.Select();
            // Create a new instance of OpenFileDialog
            OpenFileDialog openFileDialog = new OpenFileDialog();

            // Set the filter to only allow WAV files
            openFileDialog.Filter = "WAV Files (*.wav)|*.wav";
            openFileDialog.Title = "Select a WAV File";

            // Show the dialog and check if the user selected a file
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                // Get the selected file path
                string filePath = openFileDialog.FileName;
                MyLink.Text = filePath;
            }
        }

        private void CFGN_Click(object sender, EventArgs e)
        {
            LookButton.Focus();
            LookButton.Select();
            // Parse the current value from HappyBox
            float Intilize;
            if (float.TryParse(CFGBox.Text, out Intilize))
            {
                // Decrement by 0.1
                Intilize -= 0.1f;

                // Ensure it does not go below zero
                if (Intilize < 1)
                {
                    Intilize = 1;
                }

                // Update HappyBox with the new value
                CFGBox.Text = Intilize.ToString("0.0"); // Format to one decimal place
            }
            else
            {
                // Handle invalid input
                CFGBox.Text = "1.0"; // or set to a default value
            }
        }

        private void CFGP_Click(object sender, EventArgs e)
        {
            LookButton.Focus();
            LookButton.Select();
            // Parse the current value from HappyBox
            float Intilize;
            if (float.TryParse(CFGBox.Text, out Intilize))
            {
                // Increment by 0.1
                Intilize += 0.1f;

                // Ensure it does not exceed 1.0
                if (Intilize > 5.0f)
                {
                    Intilize = 5.0f;
                }

                // Update HappyBox with the new value
                CFGBox.Text = Intilize.ToString("0.0"); // Format to one decimal place
            }
            else
            {
                // Handle invalid input
                CFGBox.Text = "5.0"; // or set to a default value
            }
        }

        private void button17_Click(object sender, EventArgs e)
        {
            Male = true;
            VoicesList.Items.Clear();
            PopulateList(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\Presets\MALE");
            LookButton.Focus();
            LookButton.Select();
            button17.ForeColor = Color.Red;
            button16.ForeColor = Color.Aquamarine;
        }

        private void button16_Click(object sender, EventArgs e)
        {
            Male = false;
            VoicesList.Items.Clear();
            PopulateList(@"C:\Users\DjZaN\OneDrive\Desktop\Digital_Breath\Content\Presets\FEMALE");
            LookButton.Focus();
            LookButton.Select();
            button16.ForeColor = Color.Red;
            button17.ForeColor = Color.Aquamarine;
        }

        private void SpeakerAP_Click(object sender, EventArgs e)
        {
            Speaker_Prefix = !Speaker_Prefix;
            if (Speaker_Prefix)
            {
                SpeakerAP.BackColor = Color.Aquamarine;
                SpeakerAP.ForeColor = Color.Black;
                MyLink.Text = RefAudioFile;
            }
            else
            {
                SpeakerAP.BackColor = button1.BackColor;
                SpeakerAP.ForeColor = button1.ForeColor;
                MyLink.Text = string.Empty;
            }
        }

        private void SPSN_Click(object sender, EventArgs e)
        {
            LookButton.Focus();
            LookButton.Select();
            // Parse the current value from HappyBox
            float Intilize;
            if (float.TryParse(SpeechSpeedBox.Text, out Intilize))
            {
                // Decrement by 0.1
                Intilize -= 0.1f;

                // Ensure it does not go below zero
                if (Intilize < 5)
                {
                    Intilize = 5;
                }

                // Update HappyBox with the new value
                SpeechSpeedBox.Text = Intilize.ToString("0.0"); // Format to one decimal place
            }
            else
            {
                // Handle invalid input
                SpeechSpeedBox.Text = "5.0"; // or set to a default value
            }
        }

        private void SPSP_Click(object sender, EventArgs e)
        {
            LookButton.Focus();
            LookButton.Select();
            // Parse the current value from HappyBox
            float Intilize;
            if (float.TryParse(SpeechSpeedBox.Text, out Intilize))
            {
                // Increment by 0.1
                Intilize += 0.1f;

                // Ensure it does not exceed 1.0
                if (Intilize > 30.0f)
                {
                    Intilize = 30.0f;
                }

                // Update HappyBox with the new value
                SpeechSpeedBox.Text = Intilize.ToString("0.0"); // Format to one decimal place
            }
            else
            {
                // Handle invalid input
                SpeechSpeedBox.Text = "30.0"; // or set to a default value
            }
        }

        private void button14_Click(object sender, EventArgs e)
        {
            Search = !Search;
            if (Search)
            {
                SearchBox.Focus();
                SearchBox.Select();
                // Search Is Enabled, Manage UI Elements For Current State.
                F3B.Location = OffMap.Location;
                button2.Location = OffMap.Location;
                SearchBox.Location = PE3;
            }
            else
            {
                SearchBox.Text = string.Empty;
                // Search Is Disabled, Manage UI Elements For Current State.
                F3B.Location = PE1;
                button2.Location = PE2;
                SearchBox.Location = OffMap.Location;
            }
        }

        private void SearchBox_TextChanged(object sender, EventArgs e)
        {
            string searchText = SearchBox.Text.ToLower();

            // Clear previous items to show filtered results
            VoicesList.Items.Clear();

            // Assuming you have a source list to search from
            List<string> voices = CurrentPresets; // Replace with your actual data source 

            // If the search box is empty, add all items back to the list
            if (string.IsNullOrEmpty(searchText))
            {
                foreach (var voice in voices)
                {
                    VoicesList.Items.Add(voice); // Add all items back to the ListView
                }
                return; // Exit the method early
            }

            // Filtered search results when the search text is not empty
            foreach (var voice in voices)
            {
                // Check if the voice contains the search text
                if (voice.ToLower().Contains(searchText))
                {
                    VoicesList.Items.Add(voice); // Add matching items to the ListView
                }
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (this.Opacity < targetOpacity)
            {
                this.Opacity += opacityStep;
                // Clamp the opacity to not exceed the maximum value
                if (this.Opacity > targetOpacity)
                {
                    this.Opacity = targetOpacity;
                }
            }
            else
            {
                // Stop the timer when we've reached the target opacity
                opacityTimer.Stop();
            }
        }

        private void cacheOutputsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            cacheout = !cacheout;
        }

        private void setDirectorytToolStripMenuItem_Click(object sender, EventArgs e)
        {
            folderBrowserDialog2.ShowDialog();
            cacheDir = folderBrowserDialog2.SelectedPath;
        }

        private void constructiveChunksToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ConstructiveChunks = !ConstructiveChunks;
            if (ConstructiveChunks)
            {
                constructiveChunksToolStripMenuItem.Text = "Constructive Chunks ✅";
            }
            else
            {
                constructiveChunksToolStripMenuItem.Text = "Constructive Chunks";
            }
        }

        private void constructiveTokensToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ConstructiveTokens = !ConstructiveTokens;
            if (ConstructiveTokens)
            {
                constructiveTokensToolStripMenuItem.Text = "Constructive Tokens ✅";
            }
            else
            {
                constructiveTokensToolStripMenuItem.Text = "Constructive Tokens";
            }
        }

        private void comboBoxModels_SelectedIndexChanged(object sender, EventArgs e)
        {
            MainModel = comboBoxModels.SelectedItem.ToString();
        }

        private void TranslationMdl_SelectedIndexChanged(object sender, EventArgs e)
        {
            TranslationModel = TranslationMdl.SelectedItem.ToString();
        }

        private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
        {
            TranslationLang = comboBox4.SelectedItem.ToString();
        }

        private void SpellCheckMdl_SelectedIndexChanged(object sender, EventArgs e)
        {
            SpellCheckModel = SpellCheckMdl.SelectedItem.ToString();
        }

        private void translationModeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TranslationMode = !TranslationMode;
            if (TranslationMode)
            {
                translationModeToolStripMenuItem.Text = "Translation Mode ✅";
            }
            else
            {
                translationModeToolStripMenuItem.Text = "Translation Mode";
            }
        }

        private void longGenerationsModeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LongerGenMode = !LongerGenMode;
            if (LongerGenMode)
            {
                longGenerationsModeToolStripMenuItem.Text = "Long Generations Mode ✅";
            }
            else
            {
                longGenerationsModeToolStripMenuItem.Text = "Long Generations Mode";
            }
        }

        private void spellCheckModeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            spellcheck = !spellcheck;
            if (spellcheck)
            {
                spellCheckModeToolStripMenuItem.Text = "Spell Check Mode ✅";
            }
            else
            {
                spellCheckModeToolStripMenuItem.Text = "Spell Check Mode";
            }
        }

        public async Task IndexAPI(string text)
        {
            string apiUrl = "http://127.0.0.1:8000/infer";
            string promptAudio = RefAudioFile;  // Replace with your file
            string outputAudio = "output.wav";
            string inferMode = comboBox2.SelectedItem.ToString();

            // Add a period if the sentence doesn't end with ?, ., or !
            if (!text.EndsWith("?") && !text.EndsWith(".") && !text.EndsWith("!"))
            {
                if (TranslationMode)
                {

                }
                else
                {
                    text += ".";
                }
            }

            try
            {
                string resultPath = await IndexTTS.GenerateTTS(apiUrl, promptAudio, text, inferMode, outputAudio);
                audioFilePath = resultPath;

                duration = GetWaveFileDuration(resultPath);

                PlayAudio(ISim, duration, false, false);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error generating TTS: " + ex.Message);
            }
        }

        private async void debugToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LoraBlend Ass = new LoraBlend();
            Ass.Show();
        }

        private void oNToolStripMenuItem2_Click(object sender, EventArgs e)
        {
            SpeechToText = true;
            oNToolStripMenuItem2.Text = "✅ ON";
            oFFToolStripMenuItem2.Text = "OFF";
        }

        private void oFFToolStripMenuItem2_Click(object sender, EventArgs e)
        {
            SpeechToText = false;
            oFFToolStripMenuItem2.Text = "✅ OFF";
            oNToolStripMenuItem2.Text = "ON";
        }

        private void portableChatboxToolStripMenuItem_Click(object sender, EventArgs e)
        {
            chatBox.Show();
        }

        private void oNToolStripMenuItem3_Click(object sender, EventArgs e)
        {
            oNToolStripMenuItem3.Text = "✅ ON";
            oFFToolStripMenuItem3.Text = "OFF";
            UseChatbox = true;
        }

        private void oFFToolStripMenuItem3_Click(object sender, EventArgs e)
        {
            oFFToolStripMenuItem3.Text = "✅ OFF";
            oNToolStripMenuItem3.Text = "ON";
            UseChatbox = false;
        }

        private void sTARTToolStripMenuItem2_Click_1(object sender, EventArgs e)
        {
            Process.Start("cmd.exe");
            Thread.Sleep(5555);
            ISim.Keyboard.TextEntry("conda activate index-tts");
            Thread.Sleep(1111);
            ISim.Keyboard.KeyPress(VirtualKeyCode.RETURN);
            Thread.Sleep(1111);
            ISim.Keyboard.TextEntry("cd " + @"C:\AI\index-tts");
            Thread.Sleep(333);
            ISim.Keyboard.KeyPress(VirtualKeyCode.RETURN);
            Thread.Sleep(100);
            ISim.Keyboard.TextEntry("python server.py");
            Thread.Sleep(133);
            ISim.Keyboard.KeyPress(VirtualKeyCode.RETURN);
            Thread.Sleep(300);
        }

        private void recentPlayersToolStripMenuItem_Click(object sender, EventArgs e)
        {

            RecentPlayaz.ShowDialog(this);
        }

        private void stateToolStripMenuItem_Click(object sender, EventArgs e)
        {
            stateToolStripMenuItem.Text = "✅ ON";
            oFFToolStripMenuItem4.Text = "OFF";
            ISeed = true;
        }

        private void oFFToolStripMenuItem4_Click(object sender, EventArgs e)
        {
            stateToolStripMenuItem.Text = "ON";
            oFFToolStripMenuItem4.Text = "✅ OFF";
            ISeed = false;
        }

        private void oNToolStripMenuItem4_Click(object sender, EventArgs e)
        {
        }

        private void button1_Click_1(object sender, EventArgs e)
        {

        }

        private void makeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            dataSetMaker = new DataSetMaker(this);
            dataSetMaker._lastAccentsEnd = _lastAccentsEnd;
            dataSetMaker._lastAccentsStart = _lastAccentsStart;
            dataSetMaker._lastMainEnd = _lastMainEnd;
            dataSetMaker._lastMainStart = _lastMainStart;
            dataSetMaker._lastTextColor = _lastTextColor;
            dataSetMaker.BackupBool = UseChatbox;

            if (UseChatbox)
            {
                UseChatbox = false;
            }

            dataSetMaker.Show();

            this.Hide();
        }

        private void rollDiceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GenerateRandomTheme(false);
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            ColorHelper.SaveColors(_lastMainStart, _lastMainEnd, _lastAccentsStart, _lastAccentsEnd, _lastTextColor);
        }

        private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }
    }
}