Example #1
0
        /// <summary>
        /// cTor.
        /// </summary>
        /// <param name="pfe">blank string if '!isConsole'</param>
        internal SapiLipsync(string pfe = "")
        {
            That = this;
#if DEBUG
            logfile.Log();
            logfile.Log("SapiLipsync() cTor pfe= " + pfe);

            logfile.Log(". create (SpVoice)_voice");
#endif
            _voice = new SpVoice();
#if DEBUG
            logfile.Log(". (SpVoice)_voice CREATED");
#endif
            _voice.Volume     = 0;
            _voice.Rate       = 10;
            _voice.Phoneme   += tts_Phoneme;
            _voice.EndStream += tts_EndStream;

            /*
             * https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ee125220%28v%3dvs.85%29
             * enum SpeechVoiceEvents
             * SVEStartInputStream = 2
             * SVEEndInputStream   = 4
             * SVEVoiceChange      = 8
             * SVEBookmark         = 16
             * SVEWordBoundary     = 32
             * SVEPhoneme          = 64
             * SVESentenceBoundary = 128 <-
             * SVEViseme           = 256 <--
             * SVEAudioLevel       = 512
             * SVEPrivate          = 32768
             * SVEAllEvents        = 33790
             */
            _voice.EventInterests = (SpeechVoiceEvents)(int)SpeechVoiceEvents.SVEPhoneme
                                    + (int)SpeechVoiceEvents.SVEEndInputStream;
#if DEBUG
            logfile.Log(". _voice.EventInterests= " + _voice.EventInterests);
#endif

#if DEBUG
            logfile.Log(". create (SpPhoneConverter)_phoneConverter");
#endif
            _phoneConverter = new SpPhoneConverter();
#if DEBUG
            logfile.Log(". (SpPhoneConverter)_phoneConverter CREATED");
//			PrintPhons(1036); // test fr-FR
#endif

            if (FxeGeneratorF.isConsole)
            {
                _phoneConverter.LanguageId = 1033;                 // EnglishUS (default) // TODO: <--
                Wavefile = AudioConverter.deterwave(pfe);
#if DEBUG
                logfile.Log(". Wavefile= " + Wavefile);
#endif
            }
        }
Example #2
0
        /// <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);
            }
        }