private void CNewChapter(object sender, ExecutedRoutedEventArgs e) { TranscriptionChapter c = new TranscriptionChapter(Properties.Strings.DefaultChapterText); TranscriptionSection s = new TranscriptionSection(Properties.Strings.DefaultSectionText); TranscriptionParagraph p = new TranscriptionParagraph(); p.Add(new TranscriptionPhrase()); Transcription.Add(c); c.Add(s); s.Add(p); VirtualizingListBox.ActiveTransctiption = c; }
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; }
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); }