private void initialiseSpeechEngine()
 {
     try
     {
         if (speechRecogniser == null)
         {
             speechRecogniser = new SpeechRecogniser(crewChief);
         }
         if (!speechRecogniser.initialised)
         {
             speechRecogniser.initialiseSpeechEngine();
             Console.WriteLine("Attempted to initialise speech engine - success = " + speechRecogniser.initialised);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("Unable to create speech engine, error message: " + e.Message);
         runListenForChannelOpenThread = false;
     }
 }
 private void toggleButton_CheckedChanged(object sender, EventArgs e)
 {
     if (((RadioButton)sender).Checked)
     {
         runListenForButtonPressesThread = true;
         runListenForChannelOpenThread = false;
         try
         {
             if (speechRecogniser == null)
             {
                 speechRecogniser = new SpeechRecogniser(crewChief);
             }
             speechRecogniser.initialiseSpeechEngine();
             speechRecogniser.voiceOptionEnum = VoiceOptionEnum.TOGGLE;
             voiceOption = VoiceOptionEnum.TOGGLE;
             UserSettings.GetUserSettings().setProperty("VOICE_OPTION", getVoiceOptionString());
             UserSettings.GetUserSettings().saveUserSettings();
         }
         catch (Exception ex)
         {
             Console.WriteLine("Unable to initialise speech engine, message = " + ex.Message);
         }
     }
 }
        public MainWindow()
        {
            InitializeComponent();
            CheckForIllegalCrossThreadCalls = false;
            Console.SetOut(new ControlWriter(textBox1));
            crewChief = new CrewChief();
            controllerConfiguration = new ControllerConfiguration();
            float messagesVolume = UserSettings.GetUserSettings().getFloat("messages_volume");
            float backgroundVolume = UserSettings.GetUserSettings().getFloat("background_volume");
            setMessagesVolume(messagesVolume);
            messagesVolumeSlider.Value = (int)(messagesVolume * 10f);
            backgroundVolumeSlider.Value = (int) (backgroundVolume * 10f);

            getControllers();
            controllerConfiguration.loadSettings(this);
            String customDeviceGuid = UserSettings.GetUserSettings().getString("custom_device_guid");
            if (customDeviceGuid != null && customDeviceGuid.Length > 0)
            {
                try
                {
                    Guid guid;
                    if (Guid.TryParse(customDeviceGuid, out guid)) {
                        controllerConfiguration.addCustomController(guid);
                    }
                    else
                    {
                        Console.WriteLine("Failed to add custom device, unable to process GUID");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Failed to add custom device, message: " + e.Message);
                }
            }
            voiceOption = getVoiceOptionEnum(UserSettings.GetUserSettings().getString("VOICE_OPTION"));
            if (voiceOption == VoiceOptionEnum.DISABLED)
            {
                this.voiceDisableButton.Checked = true;
            }
            else if (voiceOption == VoiceOptionEnum.ALWAYS_ON)
            {
                this.alwaysOnButton.Checked = true;
            } else if (voiceOption == VoiceOptionEnum.HOLD)
            {
                this.holdButton.Checked = true;
            }
            else if (voiceOption == VoiceOptionEnum.TOGGLE)
            {
                this.toggleButton.Checked = true;
            }
            speechRecogniser = new SpeechRecogniser(crewChief);
            if (voiceOption != VoiceOptionEnum.DISABLED)
            {
                initialiseSpeechEngine();
            }
            runListenForButtonPressesThread = controllerConfiguration.listenForButtons(voiceOption == VoiceOptionEnum.TOGGLE);
            updateActions();
            this.assignButtonToAction.Enabled = false;
            this.deleteAssigmentButton.Enabled = false;

            if (UserSettings.GetUserSettings().getBoolean("run_immediately"))
            {
                doStartAppStuff();
            }
        }