Example #1
0
        /// <summary>
        /// Adds a command to the list of commands
        /// </summary>
        public void AddCommand(JsonCommand _Command)
        {
            // Item
            ListBoxItem _Item = new ListBoxItem()
            {
                Content = _Command.CommandName,
                Tag     = _Command
            };

            // Event
            _Item.Selected += delegate {
                // Prevent crashing
                if (Directory.Exists(_Command.CommandPath))
                {
                    // Edit title
                    this.Title = string.Format(Langs.Get("profile_window_title"), Profile, _Command.CommandName);

                    // Save selected command
                    if (CurrentBoard != null)
                    {
                        CurrentBoard.SaveCommand();
                    }

                    // Set
                    CurrentBoard = new CommandBoard(_Command, _Item);
                    Utils.EmbedUserControl(CurrentBoard, Grid);
                }
            };

            // Add
            CommandsBox.Items.Add(_Item);
        }
Example #2
0
        /// <summary>
        /// Load current profile commands
        /// </summary>
        public static void LoadCommands()
        {
            // Unload gammar
            Recognizer.UnloadAllGrammars();

            // Profile is valid
            if (Profiles.GetProfile() != null)
            {
                // There is commands
                List <JsonCommand> _ProfileCommands = Profiles.GetProfileCommands();
                if (_ProfileCommands.Count() > 0)
                {
                    // Commands
                    Choices _Commands = new Choices();

                    // Add commands
                    _ProfileCommands.ForEach(a => _Commands.Add(a.CommandName));

                    // Add grammar
                    GrammarBuilder _Builder = new GrammarBuilder();
                    _Builder.Append(_Commands);
                    _Builder.Culture = RecognizerInfo.Culture;
                    Grammar _Grammar = new Grammar(_Builder);

                    // Load grammar
                    Recognizer.LoadGrammar(_Grammar);
                }

                Utils.Log(String.Format(Langs.Get("profile_loaded"), Profiles.GetProfile(), _ProfileCommands.Count()));
            }
        }
Example #3
0
        private void Install()
        {
            // Stop timer
            Timer.Stop();

            try {
                // Extract files
                ZipFile.ExtractToDirectory(Reference.TempUpdateZip, Reference.TempUpdatePath);
                // Check files
                if (File.Exists(Reference.TempUpdateFile))
                {
                    // Start setup
                    Process _Update = new Process();
                    _Update.StartInfo.FileName  = Reference.TempUpdateFile;
                    _Update.StartInfo.Arguments = String.Format(" /sp- /silent /nocancel /norestart /closeapplications /restartapplications /dir=\"{0}\"", Reference.AppPath);
                    _Update.Start();
                }
                else
                {
                    MessageBox.Show(Langs.Get("update_install_error"), Reference.AppName, MessageBoxButton.OK, MessageBoxImage.Error);
                    Utils.CloseApplication();
                }
            } catch {
                MessageBox.Show(Langs.Get("update_install_error"), Reference.AppName, MessageBoxButton.OK, MessageBoxImage.Error);
            } finally {
                Utils.CloseApplication();
            }
        }
Example #4
0
        private void SaveExit()
        {
            // If window is closing
            if (IsClosing)
            {
                return;
            }
            IsClosing = true;

            // Variables
            string _ProfileName = Profiles.GetProfile();
            string _ProfilePath = Profiles.GetProfilePath();

            // Save profile
            if (CurrentBoard != null)
            {
                CurrentBoard.SaveCommand();
            }

            #region Edit profile name

            // New profile name
            string _NewProfileName = Utils.GetSafeFilename(ProfileName.Text.Trim()).Trim();

            // Profile name is different & is not empty
            if (!string.IsNullOrEmpty(_NewProfileName) && _NewProfileName != _ProfileName)
            {
                // New profile path
                string _NewProfilePath = Path.Combine(Reference.ProfilesPath, _NewProfileName);

                // Profile doesn't exist
                if (!Directory.Exists(_NewProfilePath))
                {
                    // Edit profile name
                    Directory.Move(_ProfilePath, _NewProfilePath);

                    // Profile vars
                    _ProfileName = _NewProfileName;
                    _ProfilePath = _NewProfilePath;
                }
                else
                {
                    Utils.Log(string.Format(Langs.Get("profile_already_exist"), _ProfileName));
                }
            }

            #endregion

            // Clear current board (prevent crashing)
            CurrentBoard = null;

            // Refresh list
            Profiles.RefreshList(null);
            // Select profile
            Profiles.Select(_ProfileName);
        }
Example #5
0
 /// <summary>
 /// Reload the commands list
 /// </summary>
 public void ReloadCommandsList()
 {
     // Clear list
     CommandsBox.Items.Clear();
     // Clear grid
     Grid.Children.Clear();
     // Clear title
     this.Title = string.Format(Langs.Get("profile_window_title"), Profile, "?");
     // Add commands
     Profiles.GetProfileCommands().ToList().ForEach(a => AddCommand(a));
 }
Example #6
0
        public CommandBoard(JsonCommand _Command, ListBoxItem _Item)
        {
            InitializeComponent();

            // Save
            Command = _Command;
            Item    = _Item;

            #region Events

            // Command name
            CommandNameBox.Text = Command.CommandName;

            CommandNameBox.LostFocus += delegate {
                // Name is valid
                string _Name  = Utils.GetSafeFilename(CommandNameBox.Text.Trim());
                string _Path  = Path.Combine(Profiles.GetProfilePath(), _Name);
                bool   _Valid = (_Name == Command.CommandName || !Directory.Exists(_Path));

                // Apply
                NameCheckIcon.Kind       = _Valid ? PackIconKind.CheckCircleOutline : PackIconKind.CloseOutline;
                NameCheckIcon.Foreground = _Valid ? new SolidColorBrush(Colors.DarkGreen) : new SolidColorBrush(Colors.DarkRed);;

                NewPath = (!Directory.Exists(_Path)) ? _Path : null;
            };

            // Add command variable
            CommandAddBtn.Click += delegate {
                // Key is not null & Key doesn't exist
                string _Key = KeyVariableBox.Text.Replace(" ", "");
                if (!string.IsNullOrEmpty(_Key) && !Command.Command_vars.Keys.Contains(_Key))
                {
                    KeyValuePair <string, string> _Pair = new KeyValuePair <string, string>(_Key, ValueVariableBox.Text);
                    Command.Command_vars.Add(_Pair.Key, _Pair.Value);
                    AddVariable(_Pair);
                }
                else
                {
                    Utils.ErrorLabel(CommandAddError, Langs.Get("variable_already_exist"), 5);
                }
            };

            #endregion

            #region Variables

            // Add variables
            foreach (KeyValuePair <string, string> _Pair in Command.Command_vars)
            {
                AddVariable(_Pair);
            }

            #endregion
        }
Example #7
0
 private void ElapsedTime(object sender, EventArgs e)
 {
     // Text
     InstallTime--;
     InstallBtn.Content = String.Format(Langs.Get("update_install"), InstallTime);
     // Install
     if (InstallTime == 0)
     {
         Install();
     }
 }
Example #8
0
        private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {
            // Variables
            double _Received   = double.Parse(e.BytesReceived.ToString());
            double _Total      = double.Parse(e.TotalBytesToReceive.ToString());
            double _Percentage = _Received / _Total * 100;

            // Show
            this.Title        = String.Format(Langs.Get("update_downloading"), Utils.BytesToString(e.BytesReceived), Utils.BytesToString(e.TotalBytesToReceive), Math.Truncate(_Percentage));
            ProgressBar.Value = int.Parse(Math.Truncate(_Percentage).ToString());
        }
Example #9
0
        private static void SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            // Recognition threshold
            if (e.Result.Confidence > Reference.JsonSettings.Confidence / 100)
            {
                string _Confidence = Math.Round(e.Result.Confidence * 100, 1).ToString();

                Utils.Log(string.Format(Langs.Get("command_recognized"), e.Result.Text, _Confidence));

                // Execute command
                Profiles.ExecuteCommand(e.Result.Text);
            }
        }
Example #10
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // Init text
            this.Title         = String.Format(Langs.Get("update_downloading"), 0, 0, 0);
            InstallBtn.Content = String.Format(Langs.Get("update_install"), "..");
            CancelBtn.Content  = Langs.Get("cancel");
            // Init
            Client.DownloadFileCompleted   += new System.ComponentModel.AsyncCompletedEventHandler(DownloadFileCompleted);
            Client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
            // Timer
            Timer.Tick    += new EventHandler(ElapsedTime);
            Timer.Interval = new TimeSpan(0, 0, 1);
            // Download
            Uri _Uri = new Uri(LatestLink);

            Client.DownloadFileAsync(_Uri, Reference.TempUpdateZip);
        }
Example #11
0
        public static void Init()
        {
            // Initialize synthesizer
            SpeechSynthesizer = new SpeechSynthesizer();

            // A voice is installed
            if (GetInstalledVoices().Count > 0)
            {
                // Get voice
                SynthesizerVoice = GetVoice(Reference.JsonSettings.Synthesizer_voice);
                Reference.JsonSettings.Synthesizer_voice = SynthesizerVoice.Id;

                Utils.Log(string.Format(Langs.Get("synthesizer_loaded"), SynthesizerVoice.Culture.NativeName));

                IsReady = true;
            }
            else
            {
                Utils.Log(Langs.Get("synthesizer_no_voice"));
            }
        }
Example #12
0
        public Main()
        {
            InitializeComponent();

            // Logs autoscroll
            LogsTxt.TextChanged += delegate {
                LogsTxt.ScrollToEnd();
            };

            #region Profiles menu

            // Open menu
            MoreBtn.Click += delegate {
                // Translate items (don't work in XAML)
                CreateBtn.Header = Langs.Get("create_profile");
                RemoveBtn.Header = Langs.Get("remove_profile");

                MoreBtn.ContextMenu.IsOpen = true;
            };

            // Create | Remove
            CreateBtn.Click += delegate {
                // Profile informations
                string _ProfilePath = Utils.GetValidFileID(true, Reference.ProfilesPath, Langs.Get("default_profile_name"), 0);
                string _ProfileName = Path.GetFileNameWithoutExtension(_ProfilePath);

                // Create profile
                Directory.CreateDirectory(_ProfilePath);
                ProfilesCombo.Items.Add(new ListBoxItem()
                {
                    Content = _ProfileName
                });

                // Select profile
                Profiles.Select(_ProfileName);
            };
            RemoveBtn.Click += delegate {
                // Confirmation
                if (MessageBox.Show(Langs.Get("remove_profile_confirm"), Reference.AppName, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {
                    // Remove profile
                    Directory.Delete(Profiles.GetProfilePath(), true);
                    // Refresh
                    Profiles.RefreshList(false);
                }
            };

            #endregion

            #region Top menu

            EditProfileBtn.Click += delegate {
                string _ProfileName = Profiles.GetProfile();

                // A profile is selected
                if (_ProfileName != null)
                {
                    // Profile exist
                    if (Profiles.Exist(_ProfileName))
                    {
                        // Disable recognition
                        Boolean _Rec = SpeechRecognition.State;
                        SpeechRecognition.State = false;

                        // Window
                        ProfileWindow _ProfileWindow = new ProfileWindow(_ProfileName);
                        _ProfileWindow.ShowDialog();

                        // Recognition
                        SpeechRecognition.State = _Rec;
                    }
                    else
                    {
                        Utils.Log(string.Format(Langs.Get("profile_doesnt_exist"), _ProfileName));
                        Profiles.RefreshList(false);
                    }
                }
                else
                {
                    Utils.Log(string.Format(Langs.Get("no_profile")));
                    Profiles.RefreshList(false);
                }
            };

            SettingsBtn.Click += delegate {
                // Window
                SettingsWindow _Settings = new SettingsWindow();
                _Settings.ShowDialog();
            };

            MicrophoneBtn.Click += delegate {
                // If profile has commands
                if (Profiles.GetProfileCommands().Count() > 0)
                {
                    // Switch microphone state
                    SpeechRecognition.State = !SpeechRecognition.State;
                    Utils.Log(Langs.Get((SpeechRecognition.State) ? "microphone_enabled" : "microphone_disabled"));
                }
                else
                {
                    Utils.Log(Langs.Get("microphone_no_commands"));
                }
            };

            StopCommandsBtn.Click += delegate {
                // Stop text to speech
                Classes.Recognition.Synthesizer.SpeechSynthesizer.SpeakAsyncCancelAll();
                Utils.Log(Langs.Get("commands_stopped"));
            };

            #endregion
        }
Example #13
0
        public ProfileWindow(string _Profile)
        {
            InitializeComponent();

            // Title
            Profile    = _Profile;
            this.Title = string.Format(Langs.Get("profile_window_title"), Profile, "?");

            // Commands init
            ReloadCommandsList();

            #region Profile name

            // Text
            ProfileName.Text = Profile;

            // Events
            ProfileName.KeyDown += (s, e) => {
                if (e.Key == Key.Enter)
                {
                    SaveExit();
                    this.Close();
                }
            };
            OkBtn.Click += delegate {
                SaveExit();
                this.Close();
            };

            #endregion

            #region Commands manager

            CommandMenu.Loaded += delegate {
                // No command selected
                RemoveCommand.IsEnabled = (CommandsBox.SelectedItems.Count > 0);
            };

            CreateCommand.Click += delegate {
                // Command informations
                string _CommandPath = Utils.GetValidFileID(true, Profiles.GetProfilePath(), Langs.Get("default_command_name"), 0);
                string _CommandName = Path.GetFileNameWithoutExtension(_CommandPath);

                // Command directory
                Directory.CreateDirectory(_CommandPath);
                // Command files
                File.WriteAllText(Path.Combine(_CommandPath, "command.info"), Wolfy.Properties.Resources.command_info);
                File.WriteAllText(Path.Combine(_CommandPath, "command.py"), Wolfy.Properties.Resources.command_template);

                // Reload list
                ReloadCommandsList();
            };

            RemoveCommand.Click += delegate {
                // Confirm
                if (MessageBox.Show(Langs.Get("remove_command_confirm"), Reference.AppName, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {
                    // Delete
                    Directory.Delete(((JsonCommand)((ListBoxItem)CommandsBox.SelectedItem).Tag).CommandPath, true);
                    ReloadCommandsList();
                }
            };

            #endregion
        }
Example #14
0
        public static void Init()
        {
            // Recognizer languages
            ReadOnlyCollection <RecognizerInfo> _InstalledRecognizers = GetInstalledRecognizers();

            // A recognizer is installed
            if (_InstalledRecognizers.Count > 0)
            {
                #region Speech language

                // Get speech language
                if (Reference.JsonSettings.Speech_language != null)
                {
                    foreach (RecognizerInfo _ri in _InstalledRecognizers)
                    {
                        if (_ri.Id.Equals(Reference.JsonSettings.Speech_language, StringComparison.OrdinalIgnoreCase))
                        {
                            RecognizerInfo = _ri;
                            break;
                        }
                    }
                }
                // Set default speech language if it's not set
                if (RecognizerInfo == null)
                {
                    RecognizerInfo = _InstalledRecognizers[0];
                    Reference.JsonSettings.Speech_language = _InstalledRecognizers[0].Id;
                }

                #endregion

                #region Recognizer

                // Set voice
                Recognizer = new SpeechRecognitionEngine(RecognizerInfo.Id);

                // User has microphone
                try {
                    // Set microphone
                    Recognizer.SetInputToDefaultAudioDevice();
                } catch {
                    Utils.Log(Langs.Get("no_microphone"));
                    return;
                }

                // Events
                Recognizer.SpeechRecognized  += new EventHandler <SpeechRecognizedEventArgs>(SpeechRecognized);
                Recognizer.AudioLevelUpdated += new EventHandler <AudioLevelUpdatedEventArgs>(AudioLevelUpdated);

                // Recognition threshold limit
                float _Confidence = Reference.JsonSettings.Confidence;
                if ((_Confidence < 0) || (_Confidence > 100))
                {
                    Reference.JsonSettings.Confidence = 80;
                }

                #endregion

                Utils.Log(string.Format(Langs.Get("recognizer_loaded"), RecognizerInfo.Culture.NativeName));
            }
            else
            {
                Utils.Log(Langs.Get("no_speech_language"));
            }
        }