public SpeechInput(Settings settings, MusicList musicCollection, string playerPath) {
            ModeTimer = new CommandModeTimer();
            RNG = new Random();
            AppSettings = settings;
            SRecognize = new SpeechRecognitionEngine();
            Player = new Aimp3Player(playerPath);
            if(musicCollection != null) {
                MusicCollection = musicCollection;
            } else {
                throw new ArgumentNullException(nameof(musicCollection));
            }
            InitCommands();

            try {
                LoadGrammar();

                SRecognize.SetInputToDefaultAudioDevice();
                SRecognize.RecognizeAsync(RecognizeMode.Multiple);
            } catch(Exception e) {
                System.Windows.Forms.MessageBox.Show("Error while starting SpeechInput\n" + e.ToString());
            }
            SRecognize.SpeechRecognized += SRecognize_SpeechRecognized;

            MusicCollection.SongListUpdated += (s, a) => LoadGrammar();
        }
        public RulesEdit(SongRules rules, MusicList allMusic) {
            if(rules != null) {
                Rules = rules;
            } else {
                throw new ArgumentNullException(nameof(rules));
            }

            if(allMusic != null) {
                AllMusic = allMusic;
            } else {
                throw new ArgumentNullException(nameof(allMusic));
            }

            InitializeComponent();
            SetupLists();
        }
示例#3
0
        private void Init() {
            string rulesPath;
            if(AppSettings.TryGetSetting("SongRulesPath", out rulesPath) && !string.IsNullOrEmpty(rulesPath)) {
                CurrentSongRules = SettingsFile.ReadSettingFile<SongRules>(rulesPath);

                if(CurrentSongRules == null) {
                    File.Delete(rulesPath);
                    CurrentSongRules = new SongRules(rulesPath);
                }
            } else {
                MessageBox.Show("Error: RulesPath setting is empty");
                return;
            }

            MusicCollection = new MusicList(AppSettings, CurrentSongRules);
            WriteLine($"Loaded {MusicCollection.ActiveSongs.Count()} songs");

            string playerPath;
            if(AppSettings.TryGetSetting("PlayerPath", out playerPath) && !string.IsNullOrEmpty(playerPath)) {
                SpeechControll = new SpeechInput(AppSettings, MusicCollection, playerPath);
            } else {
                MessageBox.Show("Error: PlayerPath setting is empty");
                return;
            }

            foreach(var word in SpeechControll.Keywords) {
                Write(word + ", ");
            }
            WriteLine("Possible: ");

            UpdateSuggestions();

            SpeechControll.MessageSend += (s) => {
                Action<string> update = WriteLine;
                Invoke(update, s);
            };
            CurrentSongRules.OnChange += (s, a) => {
                Action update = UpdateSuggestions;
                Invoke(update);
            };
            MusicCollection.SongListUpdated += (s, a) => {
                Action update = UpdateSuggestions;
                Invoke(update);
            };
            new MessageOverlay("SpeechMusicController is listening!", 1500).Show();
        }