Exemplo n.º 1
0
        void CheckOnStop()
        {
            // Console.WriteLine(timer1.Interval + " - end " + DateTime.Now.Second + " ml: " + DateTime.Now.Millisecond);
            SentenceVideo sent = this.CurrentSentenceWithVideo;

            if (VideoForm.IsVideoControlAccesible && sent != null)
            {
                if (VideoForm.CurrentVideoContrl.Player.Ctlcontrols.currentPosition > GetEndForCurrentSentence())
                {
                    if (restCountRepeat > 0)
                    {
                        this.PlayCurrentSentence();
                    }
                    else
                    {
                        Pause();
                    }
                }
                else
                {// начинаем часто проверять не подошел ли конец предложения, т.к. по управлению теряются доли секунд
                    if (this.timerForVideoManualControl.Interval != 100)
                    {
                        this.timerForVideoManualControl.Interval = 100; // но правда это приводит к показу следующего субтира
                    }
                }
            }
            if (isRecordingSound)
            {
                //  SoundCapture.Stop();
                WriteNext();
            }
        }
Exemplo n.º 2
0
        public static List <Sentence> GetSentencesFromSMI(string fileName, Encoding enc)
        {
            List <Sentence> sents = new List <Sentence>();

            using (TextReader tr = new StreamReader(fileName, enc)) //, true))
            {
                double        frameStart = 0;
                SentenceVideo sentPrev   = null;
                bool          isBody     = false;
                string        line       = "";

                while ((line = tr.ReadLine()) != null)
                {
                    if (!isBody)
                    {
                        if (line.Contains("<BODY>"))
                        {
                            isBody = true;
                        }
                        continue;
                    }
                    else
                    if (line.Contains("</BODY>"))
                    {
                        break;
                    }

                    if (line.Contains("<SYNC"))
                    {
                        int i; // <SYNC Start=67860><P Class=ENCC>
                        if (int.TryParse(line.Split(new string[] { "Start=", ">" }, StringSplitOptions.RemoveEmptyEntries)[1].Trim(), out i))
                        {
                            frameStart = i / 1000;
                            if (sentPrev != null)
                            {
                                sentPrev.InitLength(frameStart - sentPrev.Start);
                            }
                        }
                        else
                        {
                            System.Diagnostics.Debug.Fail(string.Format("Error on parsing line '{0}'", line));
                        }
                    }
                    else
                    {
                        line     = line.Replace("<br>", Environment.NewLine);
                        sentPrev = new SentenceVideo(line, sents, frameStart, frameStart + DefaultSubtitleLength);
                        sents.Add(sentPrev);
                    }
                }

                // в SMI нет конца, поэтому после цикла последнее предложение остается с длиной по умолчанию
                //if (sentPrev != null)
                //    sentPrev.InitLength(sentPrev.End - sentPrev.Start);
            }
            return(sents);
        }
Exemplo n.º 3
0
        public static List <Sentence> GetSentencesFromSSA(string fileName, Encoding enc)
        {
            List <Sentence> sents = new List <Sentence>();

            using (TextReader tr = new StreamReader(fileName, enc)) //, true))
            {
                bool isBody   = false;
                bool isFormat = false;

                string        line;
                SentenceVideo sent = null;
                while ((line = tr.ReadLine()) != null)
                {
                    if (!isBody || !isFormat)
                    {
                        if (line.Contains("[Events]"))
                        {
                            isBody = true;
                        }
                        if (isBody && line.Contains("Format:"))
                        {
                            isFormat = true;
                        }
                        continue;
                    }

                    // do split Dialogue: Marked=0,1:55:09.19,1:55:12.94,StyleB,NTP,0000,0000,0000,!Effect,...и я не чувствую ничего,\Nкроме благодарности...

                    string[] parts = line.Split(new string[] { "=0,", ",", "Effect," }, StringSplitOptions.RemoveEmptyEntries);

                    string frameStartRaw = parts[1].Replace(".", ","); // 1:55:09.19 => 1:55:09,19
                    string frameEndRaw   = parts[2].Replace(".", ",");

                    double frameStart = ConvertTimeSpanFromString(frameStartRaw);
                    double frameEnd   = ConvertTimeSpanFromString(frameEndRaw);

                    string text = parts[parts.Length - 1].Replace("\\N", Environment.NewLine);
                    sent = new SentenceVideo(text, sents, frameStart, frameEnd);
                    sent.InitLength(sent.End - sent.Start);
                    sents.Add(sent);
                }
            }
            return(sents);
        }
Exemplo n.º 4
0
        public static List <Sentence> GetSentencesFromTXT(string fileName)
        {
            List <Sentence> sents = new List <Sentence>();

            using (TextReader tr = new StreamReader(fileName, Encoding.Default)) //, true))
            {
                string        line;
                SentenceVideo sent = null;
                while ((line = tr.ReadLine()) != null)
                {
                    if (sents.Count == 0 && line.StartsWith("["))
                    {
                        continue;                                           // for [INFORMATION][AUTHOR] .... [COLF]&HFFFFFF,[STYLE]no,[SIZE]18,[FONT]Arial
                    }
                    string[] parts = line.Split(new char[] { '{', '}' }, StringSplitOptions.RemoveEmptyEntries);

                    double frameStart; // = Convert.ToDouble(parts[0]);
                    if (!Double.TryParse(parts[0], out frameStart))
                    {
                        throw new ApplicationException(string.Format("Error in file '{0}'", fileName));
                    }

                    frameStart = Math.Round(frameStart / 25, 3);
                    if (sent != null)
                    {
                        sent.InitLength(frameStart - sent.Start);
                    }

                    double frameEnd = Math.Round(Convert.ToDouble(parts[1]) / 25, 3);
                    //double frameEnd = Convert.ToDouble(parts[1]) / 25;
                    sent = new SentenceVideo(parts[2].Replace("|", Environment.NewLine), sents, frameStart, frameEnd);

                    sents.Add(sent);
                }
                if (sent != null)
                {
                    sent.InitLength(sent.End - sent.Start);
                }
            }
            return(sents);
        }
Exemplo n.º 5
0
        private void WriteNext()
        {
            sentencesForWrite.MoveNext();
            SentenceVideo sen = sentencesForWrite.Current as SentenceVideo;

            if (sen == null)
            {
                isRecordingSound = false;
                return;
            }
            if (sen.WordsToLearn.Count > 0)
            {
                int ind = this.Sentences.IndexOf(sen);
                this.SafeSelectedIndex = ind;
                string fileName = string.Format("{0} {1}{2}", ind + 1,
                                                ((sen.TextValue.Length > MAX_LENGTH_FILE_NAME + 1) ? sen.TextValue.Substring(0, MAX_LENGTH_FILE_NAME) : sen.TextValue),
                                                "... .mp3");
                //  SoundCapture.Start(FolderForOutPut + fileName);
            }
            else
            {
                WriteNext();
            }
        }
Exemplo n.º 6
0
        public static List <Sentence> GetSentencesFromSRT(string fileName, Encoding enc)
        {
            string[]        timeDelimiters = new string[] { "-->", "," };
            List <Sentence> sents          = new List <Sentence>();

            using (TextReader tr = new StreamReader(fileName, enc, true)) //, true))
            {
                bool          isNumber = true;
                double        frameStart = 0;
                double        frameEnd = 0;
                string        line, lineStore = "";
                SentenceVideo sentPrev = null;

                //while ((line = tr.ReadLine()) != null)
                while (true)
                {
                    line = tr.ReadLine();
                    if (line == null)
                    {
                        break;
                    }

                    if (sents.Count == 0 && line.StartsWith("["))
                    {
                        continue;                                           // for [INFORMATION][AUTHOR] .... [COLF]&HFFFFFF,[STYLE]no,[SIZE]18,[FONT]Arial
                    }
                    if (isNumber && line != null && (line.Contains(timeDelimiters[0]) || line.Contains(timeDelimiters[1])))
                    {
                        string timeDelimiter = timeDelimiters[0]; // frequently Delimiter == "-->"
                        if (!line.Contains(timeDelimiters[0]))
                        {
                            timeDelimiter = timeDelimiters[1];
                        }

                        string[] times = line.Split(new string[] { timeDelimiter }, StringSplitOptions.RemoveEmptyEntries);
                        frameStart = ConvertTimeSpanFromString(times[0]);
                        frameEnd   = ConvertTimeSpanFromString(times[1]);
                        isNumber   = false;
                        continue;
                    }
                    if (isNumber && line != null)
                    {
                        continue;
                    }

                    //if (line == null && lineStore == null)
                    //    break;

                    if (string.IsNullOrEmpty(line))
                    {
                        if (sentPrev != null)
                        {
                            sentPrev.InitLength(frameStart - sentPrev.Start);
                            //    Console.WriteLine("length - " + sent.Length.ToString());
                        }
                        sentPrev = new SentenceVideo(lineStore, sents, frameStart, frameEnd);
                        sents.Add(sentPrev);
                        //  Console.WriteLine(sents.Count.ToString() + ") " + lineStore + " frame: " + frameStart.ToString());
                        lineStore = null;
                        isNumber  = true;
                    }
                    else
                    {
                        if (sents.Count == 0 && line.StartsWith("["))
                        {
                            continue;                                           // for [INFORMATION][AUTHOR] .... [COLF]&HFFFFFF,[STYLE]no,[SIZE]18,[FONT]Arial
                        }
                        lineStore += Environment.NewLine + " " + line;
                        //lineStore += " " + line;
                    }
                }
                if (sentPrev != null)
                {
                    sentPrev.InitLength(sentPrev.End - sentPrev.Start);
                }
            }
            return(sents);
        }