public RecognizeEngineDiscreteHmmLearning(int numberOfHiddenStates, EngineParameters parameters,
     Codebook codebook)
 {
     _numberOfHiddenStates = numberOfHiddenStates;
     _engineParameters = parameters;
     _codeBook = codebook;
 }
 void MainWindow_Loaded(object sender, RoutedEventArgs e)
 {
     var result = TrainResult.Load("SavedData", "model");
     if (result != null)
     {
         _models = result.Models;
         _codebook = result.Catalog;
     }
 }
 public DetectionEngine(int numberOfHiddenStates, EngineParameters parameters, Codebook codebook, IEnumerable<HiddenMarkovModel> models = null)
 {
     _numberOfHiddenStates = numberOfHiddenStates;
     _engineParameters = parameters;
     _codeBook = codebook;
     if (models != null)
     {
         foreach (var model in models)
         {
             var idProp = (IdentificationProperties) model.Tag;
             _models[idProp.Label] = model;
         }
     }
 }
        public static Codebook FromWaves(IList<ISoundSignalReader> sounds, EngineParameters parameters, int codeBookSize = 256)
        {
            var featureUtility = new FeatureUtility(parameters);
            var features = new List<double[][]>();
            foreach (var signal in sounds)
            {
                signal.Reset();
                var items = featureUtility.ExtractFeatures(signal).Select(item => item.ToArray());
                features.AddRange(items);
            }

            var codeBook = new Codebook(features.SelectMany(item => item).Select(item => new Point(item)).ToArray(), codeBookSize);

            return codeBook;
        }
        private void Train()
        {
            Dictionary<string, IList<ISoundSignalReader>> learningWordSignals = new Dictionary<string, IList<ISoundSignalReader>>();

            List<string> learningDirectories = new List<string>();
            foreach (var folder in ConfigurationSettings.LearningsFolders)
            {
                learningDirectories.AddRange(Directory.GetDirectories(folder));
            }

            foreach (var directory in learningDirectories.Where(item => !item.Contains("catalog")))
            {
                var word = new DirectoryInfo(directory).Name;
                learningWordSignals.Add(word, new List<ISoundSignalReader>());
                var wavFiles = Directory.GetFiles(directory).Select(item => new FileInfo(item)).Where(fItem => fItem.Extension.Contains("wav"));
                foreach (var file in wavFiles)
                {
                    learningWordSignals[word].Add(new WavSoundSignalReader(file.FullName));
                }
            }

            var catalogSignals = new List<ISoundSignalReader>();
            catalogSignals.AddRange(learningWordSignals.SelectMany(item => item.Value));

            var codeBook = CodeBookFactory.FromWaves(catalogSignals, EngineParameters.Default);

            var recognitionEngine = new DetectionEngine(codeBook);
            var result = recognitionEngine.Train(learningWordSignals);
            //result.Hmm.Save("HMModels.dat");
            _models = result.Models;
            _codebook = result.Catalog;

            result.Save("SavedData", "model");
        }
 public RecognizeEngineDiscreteHmmLearning(Codebook codeBook)
     : this(5, EngineParameters.Default, codeBook)
 {
 }
 public DetectionEngine(Codebook codeBook, IEnumerable<HiddenMarkovModel> models = null)
     : this(5, EngineParameters.Default, codeBook, models)
 {
 }