private void addToTrainFile_btn_Click(object sender, EventArgs e) { if (_yourWav != null) { int size = _yourWav.FullData.Count; int startPnt = (int)(_startSelected * size); int endPnt = (int)(_endSelected * size); string word = ""; DialogResult re = InputBox("Nhap Word", "Vui Long nhap tu muon training:", ref word); if (re == DialogResult.OK && !string.IsNullOrEmpty(word)) { string traingDir = VCDir.Instance.TrainDirAudio + word; VCDir.CreateDirectory(traingDir); string file = Path.GetFileName(_yourPath); string path = word + "\\" + file; _label = word; string newpath = VCDir.Instance.TrainDirAudio + path; if (File.Exists(_yourPath)) { File.Move(_yourPath, newpath); } trainFrom.AddRow(word, path, startPnt, endPnt); } } }
public bool Train() { _words = new List <string>(); _hmms = new List <string>(); _models = new List <HMMWrapper>(); foreach (TrainFilesCarrier.TrainFileRow ent in tbEntry) { if (!_words.Contains(ent.Word)) { _words.Add(ent.Word); LogUtil.Info("Word : {0}\n", ent.Word); } } foreach (string word in _words) { List <string> files = new List <string>(); LogUtil.Info("List File for Word : {0}\n", word); VCDir.CreateDirectory(VCDir.Instance.TrainDirMFCC + word); VCDir.CreateDirectory(VCDir.Instance.TrainDirHMM); foreach (TrainFilesCarrier.TrainFileRow ent in tbEntry) { if (word.Equals(ent.Word)) { string audio = VCDir.Instance.TrainDirAudio + ent.Path; string mfcc = VCDir.Instance.TrainDirMFCC + ent.Path; WavFileWrapper Wav = new WavFileWrapper(audio); if (Wav.Load()) { Wav.NormalizeWave(1.0f); if (VCContext.Instance.MFCCOptions.ShiftSampleToZero) { Wav.ShifToZero(); } Wav.SelectedWave((uint)ent.Start, (uint)ent.End); MFCCWrapper Mfcc = new MFCCWrapper(Wav, VCContext.Instance.MFCCOptions.TimeFrame, VCContext.Instance.MFCCOptions.TimeShift, VCContext.Instance.MFCCOptions.CepFilter, VCContext.Instance.MFCCOptions.LowFreq, VCContext.Instance.MFCCOptions.HighFreq, VCContext.Instance.MFCCOptions.NumCeps, 2); Mfcc.UserStandardization = VCContext.Instance.MFCCOptions.UseStandardization; bool res = Mfcc.Process(); res &= Mfcc.SaveMFCC(mfcc + ".Mfcc" + ".xml"); res &= Mfcc.SaveDeltaMFCC(mfcc + ".Delta" + ".xml"); res &= Mfcc.SaveDoubleMFCC(mfcc + ".Double" + ".xml"); if (res) { switch (VCContext.Instance.MFCCOptions.TrainCofficientType) { case 0: files.Add(mfcc + ".Mfcc" + ".xml"); break; case 1: files.Add(mfcc + ".Delta" + ".xml"); break; case 2: files.Add(mfcc + ".Double" + ".xml"); break; } } LogUtil.Info("File : W - {0} Path - {1} MFCC process - {2}\n", ent.Word, VCDir.Instance.TrainDirMFCC + ent.Path + ".xml", (res) ? "Completed" : "Failed"); } } } HMMWrapper hmm = new HMMWrapper(VCContext.Instance.MFCCOptions.TrainHMMState, VCContext.Instance.MFCCOptions.TrainGMMComponent, VCContext.Instance.MFCCOptions.TrainGMMCovVar); bool ok = hmm.Trainning(files); LogUtil.Info("Train word: {0} - {1}\n", word, (ok)? "Completed": "Failed"); if (ok) { hmm.Save(VCDir.Instance.TrainDirHMM + word + ".xml"); _models.Add(hmm); _hmms.Add(word + ".xml"); LogUtil.Info("Save {0} Model to {1}\n", word, VCDir.Instance.TrainDirHMM + word + ".xml"); } } Save(VCDir.Instance.TrainXmlFile); return(true); }