Example #1
0
        //public List<Dictionary<string,List<TimeSpan>>> MarkCollections { get; set; }

        private List <string> CreateSubstringList()
        {
            List <string> retVal = new List <string>();

            string[] linesToConvert = new string[] {};
            string   cleanLine      = "";

            if (textBox.SelectionLength > 0)
            {
                linesToConvert = textBox.SelectedText.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
            }
            else
            {
                linesToConvert = textBox.Lines;
            }
            foreach (string line in linesToConvert)
            {
                cleanLine = LipSyncTextConvert.RemovePunctuation(line);                 //Remove punctuation marks as these always fail to match words
                if ((alignCombo.SelectedIndex == -1) || !(alignCombo.SelectedItem.Equals("Phrase")))
                {
                    retVal.AddRange(cleanLine.Split());
                }
                else
                {
                    retVal.Add(cleanLine);
                }
            }
            return(retVal);
        }
Example #2
0
        private void convertButton_Click(object sender, EventArgs e)
        {
            int mcIndex = startOffsetCombo.SelectedIndex;
            Tuple <TimeSpan, TimeSpan> timing      = Tuple.Create(new TimeSpan(), new TimeSpan());
            List <LipSyncConvertData>  convertData = new List <LipSyncConvertData>();

            if (LipSyncTextConvert.StandardDictExists() == false)
            {
                //messageBox Arguments are (Text, Title, No Button Visible, Cancel Button Visible)
                MessageBoxForm.msgIcon = SystemIcons.Error;                 //this is used if you want to add a system icon to the message form.
                var messageBox = new MessageBoxForm("Unable to find Standard Phoneme Dictionary", "Error", false, false);
                messageBox.ShowDialog();
                return;
            }

            LipSyncTextConvert.InitDictionary();

            if (NewTranslation != null)
            {
                var           selectedMarkCollection = (markCollectionCombo.SelectedItem as ComboBoxItem)?.Value as MarkCollection;
                List <string> subStrings             = CreateSubstringList();

                var  selMC          = selectedMarkCollection?.Marks.Select(x => x.StartTime).ToList();
                bool doPhonemeAlign =
                    (alignCombo.SelectedIndex != -1) && (alignCombo.SelectedItem.Equals("Phoneme"));

                if (mcIndex == -1)
                {
                    selMC   = null;
                    mcIndex = 0;
                }

                foreach (string strElem in subStrings)
                {
                    if (string.IsNullOrWhiteSpace(strElem))
                    {
                        continue;
                    }

                    int phonemeIndex = 0;
                    List <PhonemeType> phonemeList = LipSyncTextConvert.TryConvert(strElem.Trim());
                    if (phonemeList.Count == 0)
                    {
                        EventHandler <TranslateFailureEventArgs> failHandler = TranslateFailure;
                        TranslateFailureEventArgs failArgs = new TranslateFailureEventArgs();
                        failArgs.FailedWord = strElem;
                        failHandler(this, failArgs);

                        //At this point, we should have it corrected, if not, then ignore
                        phonemeList = LipSyncTextConvert.TryConvert(strElem);
                    }

                    if (phonemeList.Count == 0)
                    {
                        //User has bailed on one of the conversions
                        return;
                    }

                    if (doPhonemeAlign == false)
                    {
                        timing = CalcPhonemeTimespans(selMC, mcIndex++, phonemeList.Count);
                    }

                    foreach (PhonemeType phoneme in phonemeList)
                    {
                        if (doPhonemeAlign == true)
                        {
                            timing       = CalcPhonemeTimespans(selMC, mcIndex++, 1);
                            phonemeIndex = 0;
                        }

                        long startTicks = timing.Item1.Ticks + (timing.Item2.Ticks * phonemeIndex++);
                        convertData.Add(new LipSyncConvertData(startTicks, timing.Item2.Ticks, phoneme, strElem));
                    }
                    if (checkBoxClearText.Checked)
                    {
                        textBox.Text = "";
                    }
                }

                EventHandler <NewTranslationEventArgs> handler = NewTranslation;
                NewTranslationEventArgs args = new NewTranslationEventArgs();
                args.PhonemeData = convertData;
                if (markCollectionRadio.Checked)
                {
                    args.Placement = TranslatePlacement.Mark;
                }
                else if (cursorRadio.Checked)
                {
                    args.Placement = TranslatePlacement.Cursor;
                }
                else
                {
                    args.Placement = TranslatePlacement.Clipboard;
                }

                if (startOffsetCombo.SelectedItem != null)
                {
                    args.FirstMark = (TimeSpan)startOffsetCombo.SelectedItem;
                }

                handler(this, args);

                if (markCollectionRadio.Checked)
                {
                    int markIncrement = 0;
                    switch (alignCombo.Text)
                    {
                    case "Phoneme":
                        markIncrement = convertData.Count;
                        break;

                    case "Word":
                        markIncrement = subStrings.Count;
                        break;

                    case "Phrase":
                        markIncrement = 1;
                        break;
                    }
                    if (startOffsetCombo.SelectedIndex + markIncrement < startOffsetCombo.Items.Count)
                    {
                        startOffsetCombo.SelectedIndex = startOffsetCombo.SelectedIndex + markIncrement;
                    }
                }
            }
        }
Example #3
0
        private void convertButton_Click(object sender, EventArgs e)
        {
            int mcIndex = startOffsetCombo.SelectedIndex;
            Tuple <TimeSpan, TimeSpan> timing      = Tuple.Create(new TimeSpan(), new TimeSpan());
            List <LipSyncConvertData>  convertData = new List <LipSyncConvertData>();

            if (LipSyncTextConvert.StandardDictExists() == false)
            {
                MessageBox.Show("Unable to find Standard Phoneme Dictionary", "Error", MessageBoxButtons.OK);
                return;
            }

            LipSyncTextConvert.InitDictionary();

            if (NewTranslation != null)
            {
                List <string>  subStrings     = CreateSubstringList();
                MarkCollection selMC          = MarkCollections.Find(x => x.Name.Equals(markCollectionCombo.SelectedItem));
                bool           doPhonemeAlign =
                    (alignCombo.SelectedIndex != -1) && (alignCombo.SelectedItem.Equals("Phoneme"));

                if (mcIndex == -1)
                {
                    selMC   = null;
                    mcIndex = 0;
                }

                foreach (string strElem in subStrings)
                {
                    if (string.IsNullOrWhiteSpace(strElem))
                    {
                        continue;
                    }

                    int phonemeIndex = 0;
                    List <PhonemeType> phonemeList = LipSyncTextConvert.TryConvert(strElem.Trim());
                    if (phonemeList.Count == 0)
                    {
                        EventHandler <TranslateFailureEventArgs> failHandler = TranslateFailure;
                        TranslateFailureEventArgs failArgs = new TranslateFailureEventArgs();
                        failArgs.FailedWord = strElem;
                        failHandler(this, failArgs);

                        //At this point, we should have it corrected, if not, then ignore
                        phonemeList = LipSyncTextConvert.TryConvert(strElem);
                    }

                    if (phonemeList.Count == 0)
                    {
                        //User has bailed on one of the conversions
                        return;
                    }

                    if (doPhonemeAlign == false)
                    {
                        timing = CalcPhonemeTimespans(selMC, mcIndex++, phonemeList.Count);
                    }

                    foreach (PhonemeType phoneme in phonemeList)
                    {
                        if (doPhonemeAlign == true)
                        {
                            timing       = CalcPhonemeTimespans(selMC, mcIndex++, 1);
                            phonemeIndex = 0;
                        }

                        long startTicks = timing.Item1.Ticks + (timing.Item2.Ticks * phonemeIndex++);
                        convertData.Add(new LipSyncConvertData(startTicks, timing.Item2.Ticks, phoneme, strElem));
                    }
                }

                EventHandler <NewTranslationEventArgs> handler = NewTranslation;
                NewTranslationEventArgs args = new NewTranslationEventArgs();
                args.PhonemeData = convertData;
                if (markCollectionRadio.Checked)
                {
                    args.Placement = TranslatePlacement.Mark;
                }
                else if (cursorRadio.Checked)
                {
                    args.Placement = TranslatePlacement.Cursor;
                }
                else
                {
                    args.Placement = TranslatePlacement.Clipboard;
                }

                if (startOffsetCombo.SelectedItem != null)
                {
                    args.FirstMark = (TimeSpan)startOffsetCombo.SelectedItem;
                }

                handler(this, args);
            }
        }