Ejemplo n.º 1
0
        private void CNewSection(object sender, ExecutedRoutedEventArgs e)
        {
            TranscriptionSection   s = new TranscriptionSection(Properties.Strings.DefaultSectionText);
            TranscriptionParagraph p = new TranscriptionParagraph();

            p.Add(new TranscriptionPhrase());
            Transcription.Add(s);
            s.Add(p);
            VirtualizingListBox.ActiveTransctiption = s;
        }
Ejemplo n.º 2
0
        private void CInsertNewSection(object sender, ExecutedRoutedEventArgs e)
        {
            if (VirtualizingListBox.ActiveTransctiption != null)
            {
                if (VirtualizingListBox.ActiveTransctiption.IsParagraph)
                {
                    TranscriptionParagraph p = (TranscriptionParagraph)VirtualizingListBox.ActiveTransctiption;
                    int idx = p.ParentIndex;
                    TranscriptionSection sec = (TranscriptionSection)p.Parent;
                    TranscriptionSection s   = new TranscriptionSection(Properties.Strings.DefaultSectionText);
                    for (int i = idx; i < sec.Children.Count; i++)
                    {
                        s.Add(sec[i]);
                    }

                    sec.Children.RemoveRange(idx, sec.Children.Count - idx);

                    sec.Parent.Insert(sec.ParentIndex + 1, s);
                    VirtualizingListBox.ActiveTransctiption = s;

                    VirtualizingListBox.Reset();
                }
                else if (VirtualizingListBox.ActiveTransctiption.IsSection)
                {
                    var s = new TranscriptionSection(Properties.Strings.DefaultSectionText);
                    s.Children.AddRange(VirtualizingListBox.ActiveTransctiption.Children);
                    VirtualizingListBox.ActiveTransctiption.Children.Clear();
                    VirtualizingListBox.ActiveTransctiption.Parent.Insert(VirtualizingListBox.ActiveTransctiption.ParentIndex, s);
                    VirtualizingListBox.ActiveTransctiption = s;
                    VirtualizingListBox.Reset();
                }
                else if (VirtualizingListBox.ActiveTransctiption.IsChapter)
                {
                    var s = new TranscriptionSection(Properties.Strings.DefaultSectionText);
                    VirtualizingListBox.ActiveTransctiption.Insert(0, s);
                    VirtualizingListBox.ActiveTransctiption = s;
                    VirtualizingListBox.Reset();
                }
            }
        }
Ejemplo n.º 3
0
        public void GetTranscription(bool useOrtoTP, bool removeNonPhonemes, Transcription storage)
        {
            Transcription data = storage;
            List <TranscriptionPhrase> phrazes = new List <TranscriptionPhrase>();

            string[] orto = useOrtoTP ? ORTOTP : ORTOT;

            for (int i = 0; i < ORTOT.Length; i++)
            {
                TranscriptionPhrase ph = new TranscriptionPhrase();
                ph.Text = orto[i].Trim() + " ";
                if (orto[i].Length == 0) //empty words
                {
                    ph.Text = "";
                }
                ph.Phonetics = PRON[i];
                ph.Begin     = START[i];
                ph.End       = STOP[i];
                phrazes.Add(ph);
            }

            TranscriptionChapter c   = new TranscriptionChapter();
            TranscriptionSection sec = new TranscriptionSection();

            var second = TimeSpan.FromSeconds(0.5);
            TranscriptionParagraph     pah     = new TranscriptionParagraph();
            List <TranscriptionPhrase> silence = new List <TranscriptionPhrase>();
            TimeSpan sec20 = TimeSpan.FromSeconds(20);

            #region sileny splitovaci algoritmus
            while (phrazes.Count > 0)
            {
                string tt = phrazes[0].Text.Trim();
                if (string.IsNullOrWhiteSpace(tt) || (tt.First() == '[' && tt.Last() == ']'))//nerecova udalost
                {
                    silence.Add(phrazes[0]);
                    TimeSpan begin;
                    TimeSpan end;

                    if (pah.Phrases.Count > 0)//pokud uz jsou sestavene nejake fraze spocitam jestli presahnou spolu s tichy 20s
                    {
                        begin = pah.Phrases.First().Begin;
                        end   = silence.Last().End;
                        if (end - begin >= sec20)//pokud ano reknu, ze pred tichy mel odstavec zkoncit
                        {
                            pah.Begin = pah.Phrases.First().Begin;
                            pah.End   = pah.Phrases.Last().End;
                            sec.Paragraphs.Add(pah);
                            pah = new TranscriptionParagraph();
                        }
                    }
                }
                else if (silence.Count > 0)                                                    //mam nejaky nerecovy udalosti a prislo neco jinyho
                {
                    if (silence.Last().End - silence.First().Begin >= TimeSpan.FromSeconds(2)) //mam vic nereci nez 2 sekundy udelat z ni samostatnej segment
                    {
                        if (pah.Phrases.Count > 0)
                        {
                            pah.Begin = pah.Phrases.First().Begin;
                            pah.End   = pah.Phrases.Last().End;
                            sec.Paragraphs.Add(pah);
                            pah = new TranscriptionParagraph();
                        }


                        foreach (var ss in silence)
                        {
                            pah.Phrases.Add(ss);
                        }

                        silence.Clear();

                        pah.Begin = pah.Phrases.First().Begin;
                        pah.End   = pah.Phrases.Last().End;
                        sec.Paragraphs.Add(pah);
                        pah = new TranscriptionParagraph();


                        pah.Phrases.Add(phrazes[0]);
                    }
                    else//mam ji malo -  prilepit nerecovy udalosti k odstavci
                    {
                        foreach (var ss in silence)
                        {
                            pah.Phrases.Add(ss);
                        }

                        silence.Clear();
                        pah.Phrases.Add(phrazes[0]);
                    }
                }
                else//prisla recova fraze a nemam nic v tichu pridat do paragrafu
                {
                    pah.Phrases.Add(phrazes[0]);
                }

                phrazes.RemoveAt(0);
            }

            //dosyp zbytek do prepisu

            while (silence.Count > 0)
            {
                pah.Phrases.Add(silence[0]);
                silence.RemoveAt(0);
            }
            #endregion

            pah.Begin = pah.Phrases.First().Begin;
            pah.End   = pah.Phrases.Last().End;
            sec.Paragraphs.Add(pah);
            c.Sections.Add(sec);
            data.Chapters.Add(c);

            if (removeNonPhonemes)
            {
                {
                    TranscriptionPhrase ph = (TranscriptionPhrase)sec[0][0];
                    while (ph != null)
                    {
                        var parent = ph.Parent;

                        var ph2 = (TranscriptionPhrase)ph.NextSibling();

                        string t = ph.Text.Trim();
                        if (string.IsNullOrWhiteSpace(t) || (t.StartsWith("[") && t.EndsWith("]")))
                        {
                            ph.Parent.Remove(ph);
                        }

                        ph = ph2;
                    }
                }
            }

            data.MediaURI = FileName;
        }
Ejemplo n.º 4
0
        public static bool Import(Stream input, Transcription storage)
        {
            XDocument doc  = XDocument.Load(input);
            var       root = doc.Element("NanovoidSegmentation");

            var mediums = root.Elements("Medium").ToArray();

            XElement medium = null;

            if (mediums.Length > 1)
            {
                SelectFile sf = new SelectFile(mediums.Select(m => m.Attribute("url") != null ? Path.GetFileName(m.Attribute("url").Value) : "name not specified").ToList());
                sf.Title = "Select Medium";
                if (sf.ShowDialog() == true)
                {
                    medium = mediums[sf.SelectedIndex];
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                medium = mediums.First();
            }

            var segmentations = medium.Elements("Segmentation").ToArray();

            XElement segmentation = null;

            if (segmentations.Length > 1)
            {
                var        lst = segmentations.Select(s => string.Join(" ", s.Attributes().Select(a => a.Name + ":" + a.Value))).ToList();
                SelectFile sf  = new SelectFile(lst);
                sf.Title = "Select segmentation";
                if (sf.ShowDialog() == true)
                {
                    segmentation = segmentations[sf.SelectedIndex];
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                segmentation = segmentations.First();
            }

            TimeSpan unitlen = new TimeSpan((long)(TimeSpan.FromSeconds(1).Ticks *XmlConvert.ToDouble(segmentation.Attribute("tres").Value)));
            //segmentations.Elements("Segment");

            Transcription        tr = storage;
            TranscriptionChapter ch = new TranscriptionChapter();

            ch.Text = segmentation.Attribute("type").Value;

            TranscriptionSection sec = new TranscriptionSection();

            sec.Text = segmentation.Attribute("label").Value;

            tr.MediaURI = medium.Attribute("url") != null?medium.Attribute("url").Value : "";

            var idss = segmentation.Element("Identities");

            if (idss != null)
            {
                var ids = idss.Elements("Id");
                if (ids != null && ids.Count() > 0)
                {
                    var speakers = ids.Select(i => new Speaker()
                    {
                        ID = XmlConvert.ToInt32(i.Attribute("id").Value), Surname = i.Attribute("label").Value
                    });
                    tr.Speakers = new SpeakerCollection(speakers);
                }
            }

            var segments = segmentation.Element("Segments").Elements("Segment");

            var paragraphs = MakeParagraphs(segments, unitlen);

            foreach (var p in paragraphs)
            {
                sec.Add(p);
            }

            ch.Add(sec);
            tr.Add(ch);


            tr.AssingSpeakersByID(); //added in newer version



            return(true);
        }