/// <summary> /// Switches stuff use to alternate/user-edited data. <see cref="EditorPhonF"/> /// @note The data in the "PHONEMES" table changes as data is edited in /// 'EditorPhonF' so if that is canceled the table needs to revert. /// </summary> /// <param name="revert">true to revert to previous data</param> internal void AlternateData(bool revert = false) { if (!revert) { rb_alt.Checked = false; // force false to allow the radio-button to refire. _dt1.Rows.Clear(); _dt2.Rows.Clear(); _fxedata_alt.Clear(); FxeData.GenerateData(_ars_alt, _fxedata_alt); rb_alt.Checked = rb_alt.Visible = true; // fire rb_CheckChanged rb_def.Visible = true; // else default-button won't be visible if there's no typed-text. } else { object rb; if (rb_def.Checked) { rb = rb_def; } else if (rb_enh.Checked) { rb = rb_enh; } else { rb = rb_alt; } checkedchanged_Radio(rb, EventArgs.Empty); } }
/// <summary> /// cTor. /// </summary> /// <param name="pfe">blank string if '!isConsole'</param> /// <param name="headtype">blank string if '!isConsole'</param> internal FxeGeneratorF(string pfe = "", string headtype = "") { #if DEBUG // LogSpeechRecognitionEngines(); logfile.Log("FxeGeneratorF() cTor pfe= " + pfe + " headtype= " + headtype); #endif That = this; FxeData.LoadTrigrams(); bool fatality = false; if (pfe == String.Empty) // is GUI interface -> { #if DEBUG logfile.Log(". is GUI"); #endif InitializeComponent(); co_headtype.SelectedIndex = 0; la_def_word_pct.Text = la_def_phon_pct.Text = la_enh_word_pct.Text = la_enh_phon_pct.Text = String.Empty; tb_text.Text = String.Empty; tb_text.BackColor = tb_expected.BackColor = Color.AntiqueWhite; tb_def_words.BackColor = tb_def_phons.BackColor = tb_enh_words.BackColor = tb_enh_phons.BackColor = Color.GhostWhite; // PHONEMES data/grid -> DataColumn dc; dc = new DataColumn(HEAD_PHONS_0, typeof(string)); // pos dc.ReadOnly = true; _dt1.Columns.Add(dc); dc = new DataColumn(HEAD_PHONS_1, typeof(string)); // phon dc.ReadOnly = true; _dt1.Columns.Add(dc); dc = new DataColumn(HEAD_PHONS_2, typeof(string)); // start dc.ReadOnly = true; _dt1.Columns.Add(dc); dc = new DataColumn(HEAD_PHONS_3, typeof(string)); // stop dc.ReadOnly = true; _dt1.Columns.Add(dc); dc = new DataColumn(HEAD_PHONS_4, typeof(string)); // vis dc.ReadOnly = true; _dt1.Columns.Add(dc); dc = new DataColumn(HEAD_PHONS_5, typeof(string)); // truth dc.ReadOnly = true; _dt1.Columns.Add(dc); dc = new DataColumn(HEAD_PHONS_6, typeof(string)); // level dc.ReadOnly = true; _dt1.Columns.Add(dc); grid_phons.DataSource = _dt1; grid_phons.Columns[0].Width = 50; // 50 "pos" grid_phons.Columns[1].Width = 76; // 76 "phoneme" grid_phons.Columns[2].Width = 86; // 86 "start" grid_phons.Columns[3].Width = 86; // 86 "stop" grid_phons.Columns[4].Width = 67; // 67 "viseme" grid_phons.Columns[5].Width = 57; // 57 "truth" grid_phons.Columns[6].Width = 61; // 56 "level" for (int i = 0; i != grid_phons.Columns.Count; ++i) { grid_phons.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable; } // Data Blocks data/grid -> dc = new DataColumn(HEAD_BLOCKS_0, typeof(string)); dc.ReadOnly = true; _dt2.Columns.Add(dc); dc = new DataColumn(HEAD_BLOCKS_1, typeof(float)); dc.ReadOnly = true; _dt2.Columns.Add(dc); dc = new DataColumn(HEAD_BLOCKS_2, typeof(float)); dc.ReadOnly = true; _dt2.Columns.Add(dc); grid_blocs.DataSource = _dt2; // grid_blocs.Columns[0].Width = 80; // 68 "viseme" // grid_blocs.Columns[1].Width = 97; // 87 "frame stop" // grid_blocs.Columns[2].Width = 110; // 100 "morph weight" grid_blocs.Columns[0].Width = 140; // 68 "viseme" grid_blocs.Columns[1].Width = 67; // "stop" grid_blocs.Columns[2].Width = 80; // "weight" // for (int i = 0; i != grid_blocs.Columns.Count; ++i) // grid_blocs.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable; grid_blocs.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable; grid_blocs.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable; grid_blocs.ColumnHeaderMouseClick += dgblocs_ColumnHeaderMouseClick; grid_phons.RowHeadersVisible = grid_blocs.RowHeadersVisible = false; printversion(); // instantiate/initialize SAPI _sapi = new SapiLipsync(); _sapi.TtsStreamEnded += OnTtsStreamEnded; _sapi.SrStreamEnded += OnSrStreamEnded; // this will set '_sapi._recognizer' // this will set '_sapi._phoneConverter.LanguageId' // and the Titletext if (!SpeechRecognizerLister.AddSpeechRecognizers(co_recognizers)) { string info = "FXE LipSyncer requires a SAPI 5.4 compliant" + Environment.NewLine + "Microsoft Speech Recognizer" + Environment.NewLine + "as displayed in Windoz ControlPanel|SpeechRecognition." + Environment.NewLine + Environment.NewLine + "none was found ..."; using (var d = new InfoDialog("FATAL Error", info)) { d.ShowDialog(this); } fatality = true; } } else if (headtype != String.Empty && File.Exists(pfe)) // is Console interface -> { #if DEBUG logfile.Log(". is Console"); #endif // TODO: Fail if a Recognizer is not found. // TODO: Ensure that 'head Model/Skeleton type' is a recognized type. // Eg. "P_HHM" Filelabel = Utility.GetFilelabel(pfe); // NOTE: that will be written into the FXE-file output. _sapi = new SapiLipsync(_pfe = pfe); if (_sapi.Wavefile != String.Empty) { isConsole = true; _headtype = headtype; _sapi.SrStreamEnded += OnSrStreamEnded; _sapi.Start(LoadTypedTextFile()); } else { fatality = true; } } else // is Console error -> { fatality = true; } if (fatality) { Environment.Exit(0); } }
/// <summary> /// This is the biggie. Generates and prints data after the /// SpeechRecognition stream of an audio-file finishes. /// </summary> /// <param name="ars_def"></param> /// <param name="ars_enh"></param> void OnSrStreamEnded(List <OrthographicResult> ars_def, List <OrthographicResult> ars_enh) { #if DEBUG logfile.Log(); logfile.Log("OnSrStreamEnded() ars_def.Count= " + ars_def.Count + " ars_enh.Count= " + ars_enh.Count); #endif _ars_def = ars_def; _ars_enh = ars_enh; if (!isConsole) { PrintResults(_ars_def, tb_def_words, tb_def_phons); if (tb_text.Text != String.Empty) { PrintResults(_ars_enh, tb_enh_words, tb_enh_phons); la_def_word_pct.Text = _sapi.RatioWords_def.ToString("P1"); la_enh_word_pct.Text = _sapi.RatioWords_enh.ToString("P1"); } else { la_def_word_pct.Text = _sapi.Confidence_def.ToString("P1"); } if (_sapi.Expected.Count != 0) { la_def_phon_pct.Text = _sapi.RatioPhons_def.ToString("P1"); la_enh_phon_pct.Text = _sapi.RatioPhons_enh.ToString("P1"); rb_def.Visible = rb_enh.Visible = true; } ColorPercents(tb_text.Text == String.Empty); bu_createfxe.Enabled = co_headtype.Enabled = true; } FxeData.GenerateData(_ars_def, _fxedata_def); FxeData.GenerateData(_ars_enh, _fxedata_enh); #if DEBUG logfile.Log(". _sapi.RatioPhons_def= " + _sapi.RatioPhons_def); logfile.Log(". _sapi.RatioPhons_enh= " + _sapi.RatioPhons_enh); #endif if (tb_text.Text == String.Empty || _sapi.RatioPhons_def > _sapi.RatioPhons_enh) { #if DEBUG logfile.Log(". select DEFault"); #endif if (!isConsole) { #if DEBUG logfile.Log(". . rb_def"); #endif rb_def.Checked = true; // fire rb_CheckChanged } else { _fxedata = _fxedata_def; } } else { #if DEBUG logfile.Log(". select ENHanced"); #endif if (!isConsole) { #if DEBUG logfile.Log(". . rb_enh"); #endif rb_enh.Checked = true; // fire rb_CheckChanged } else { _fxedata = _fxedata_enh; } } if (!isConsole) { bu_edit.Enabled = bu_save.Enabled = (_dt1 != null && _dt1.Rows.Count != 0); bu_load.Enabled = true; Cursor = Cursors.Default; } else { string pfe = _pfe.Substring(0, _pfe.Length - 3).ToLower() + FxeGeneratorF.EXT_FXE; FxeWriter.WriteFile(pfe, _headtype, _fxedata); Application.Exit(); } }