Exemplo n.º 1
0
        public bool AddorUpdate(TrainFilesCarrier.TrainFileRow row)
        {
            TrainFilesCarrier.TrainFileRow existedRow = IsRowExisted(row);
            if (existedRow == null)
            {
                tbEntry.AddTrainFileRow(row);
                return(true);
            }
            else
            {
                if (existedRow.Start != row.Start)
                {
                    existedRow.Start = row.Start;
                }
                if (existedRow.End != row.End)
                {
                    existedRow.End = row.End;
                }
                if (existedRow.Word != row.Word)
                {
                    existedRow.Word = row.Word;
                }
            }

            return(false);
        }
Exemplo n.º 2
0
        private void UpdateRow(TrainFilesCarrier.TrainFileRow row)
        {
            string file = VCDir.Instance.TrainDirAudio + row.Path;

            if (File.Exists(file))
            {
                _yourChanged = true;
                _yourPath    = file;
                _yourWav     = new WavFileWrapper(_yourPath);

                if (_yourWav.Load())
                {
                    _yourWav.NormalizeWave(1.0);
                    LogUtil.Info("Load Wave: {0}   -- OK\n", _yourPath);
                    option = VCContext.Instance.MFCCOptions;
                    if (option.ShiftSampleToZero)
                    {
                        LogUtil.Info("Shift Sample To Zero: --   -- OK\n");
                        _yourWav.ShifToZero();
                    }
                    waveViewer.WaveData = _yourWav.FullData;
                    waveViewer.FitToScreen();
                    _label = row.Word;
                    int size = _yourWav.FullData.Count;
                    _startSelected         = (float)row.Start / size;
                    _endSelected           = (float)row.End / size;
                    waveViewer.LeftSlider  = _startSelected;
                    waveViewer.RightSlider = _endSelected;
                }
            }
        }
Exemplo n.º 3
0
        public bool Load(string path)
        {
            tbEntry = new TrainFilesCarrier.TrainFileDataTable();
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(path);
                XmlNode node = doc.SelectSingleNode("Train/TrainFiles");
                if (node != null)
                {
                    XmlNodeList listWords = node.SelectNodes("File");
                    foreach (XmlNode word in listWords)
                    {
                        TrainFilesCarrier.TrainFileRow row = tbEntry.NewTrainFileRow();
                        row.Word  = word.Attributes["Word"].Value;
                        row.Path  = word.Attributes["Path"].Value;
                        row.Start = Convert.ToInt32(word.Attributes["Start"].Value);
                        row.End   = Convert.ToInt32(word.Attributes["End"].Value);
                        // row.ID = word.Attribute("ID").Value;
                        string p = VCDir.Instance.TrainDirAudio + row.Path;
                        //if (!words.ContainsKey(w))
                        // {
                        if (File.Exists(p))
                        {
                            tbEntry.AddTrainFileRow(row);
                        }
                        else
                        {
                            Debug.WriteLine("Cant Load {0} - Path {1}", row.Word, row.Path);
                        }
                    }
                }

                node = doc.SelectSingleNode("Train/HMMModels");
                if (node != null)
                {
                    XmlNodeList listModels = node.SelectNodes("Model");
                    foreach (XmlNode models in listModels)
                    {
                        string     word = models.Attributes["Word"].Value;
                        string     file = models.Attributes["Path"].Value;
                        HMMWrapper hmm  = new HMMWrapper();

                        if (word != null && file != null && hmm.Load(VCDir.Instance.TrainDirHMM + file))
                        {
                            Debug.WriteLine("Load Model {0}: {1}", word, VCDir.Instance.TrainDirHMM + file);
                            _words.Add(word);
                            _hmms.Add(file);
                            _models.Add(hmm);
                        }
                    }
                }
            }
            catch (Exception)
            {
            }

            return(true);
        }
        public bool AddRow(TrainFilesCarrier.TrainFileRow row)
        {
            bool res = _trainTask.AddorUpdate(row);

            _trainTask.Save(VCDir.Instance.TrainXmlFile);
            gridTrain.DataSource = _trainTask.Entries;
            return(res);
        }
 public bool AddRow(string word, string path, int start, int end)
 {
     TrainFilesCarrier.TrainFileRow row = _trainTask.Entries.NewTrainFileRow();
     row.End   = end;
     row.Start = start;
     row.Word  = word;
     row.Path  = path;
     return(AddRow(row));
 }
Exemplo n.º 6
0
 public TrainFilesCarrier.TrainFileRow IsRowExisted(TrainFilesCarrier.TrainFileRow row)
 {
     foreach (TrainFilesCarrier.TrainFileRow ent in tbEntry)
     {
         if (String.Equals(ent.Path, row.Path, StringComparison.OrdinalIgnoreCase))
         {
             return(ent);
         }
     }
     return(null);
 }
        private void viewTrain_CustomDrawGroupRow(object sender, DevExpress.XtraGrid.Views.Base.RowObjectCustomDrawEventArgs e)
        {
            GridView         view = sender as GridView;
            GridGroupRowInfo info = e.Info as GridGroupRowInfo;
            int numElement        = view.GetChildRowCount(e.RowHandle);
            int rowHdl            = view.GetChildRowHandle(e.RowHandle, 0);

            if (rowHdl >= 0)
            {
                TrainFilesCarrier.TrainFileRow dataRow = view.GetDataRow(rowHdl) as TrainFilesCarrier.TrainFileRow;
                info.GroupText = String.Format(" {0} - {1}", dataRow.Word, numElement);
            }
        }
 private void viewTrain_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
 {
     if (viewTrain.IsGroupRow(e.FocusedRowHandle))
     {
         bool expanded = viewTrain.GetRowExpanded(e.FocusedRowHandle);
         viewTrain.SetRowExpanded(e.FocusedRowHandle, !expanded);
     }
     else
     {
         TrainFilesCarrier.TrainFileRow row = (TrainFilesCarrier.TrainFileRow)viewTrain.GetDataRow(e.FocusedRowHandle);
         if (handler != null)
         {
             handler(this, new RecallEntryEventArgs(row));
         }
     }
 }
 public RecallEntryEventArgs(TrainFilesCarrier.TrainFileRow row)
 {
     RecalledRow = row;
 }
Exemplo n.º 10
0
 public void Remove(TrainFilesCarrier.TrainFileRow row)
 {
     tbEntry.RemoveTrainFileRow(row);
 }