/// <summary>
        /// Execute
        /// </summary>
        /// <param name="context">WF context</param>
        /// <returns></returns>
        protected override void Execute(NativeActivityContext context)
        {
            // Obtain the runtime value of the Text input argument
            SplitedDocument sDoc         = context.GetValue(this.SplitedDocument);
            var             localEpisode = context.GetValue(this.LocalEpisode);

            // TODO : Code this activity
            DMDocument doc = new DMDocument();

            int index = 0;

            foreach (var para in sDoc.Paragraphs)
            {
                DMParagraph paragraph = new DMParagraph();

                for (int i = 0; i < para.Sentences.Count; i++)
                {
                    var text = para.Sentences[i];

                    var sentence = new DMSentence()
                    {
                        Index = index
                    };
                    sentence.Initialize(text);
                    paragraph.Inlines.Add(sentence);
                    paragraph.Inlines.Add(new Run(" "));

                    index += 1;
                }
                doc.Blocks.Add(paragraph);
            }

            doc.Save(localEpisode.SyncDocumentFilePath);
            localEpisode.ReloadSyncDocument();
        }
Example #2
0
        static void engine_RecognizeCompleted(object sender, System.Speech.Recognition.RecognizeCompletedEventArgs e)
        {
            DMDocument  doc       = new DMDocument();
            DMParagraph paragraph = new DMParagraph();


            DictationSyncEngine engine = sender as DictationSyncEngine;

            if (engine != null)
            {
                for (int i = 0; i < engine.Result.Count; i++)
                {
                    var        sentence   = engine.Result[i];
                    DMSentence dmSentence = BuildSentence(i, sentence);
                    paragraph.Inlines.Add(dmSentence);
                }

                doc.Blocks.Add(paragraph);
            }

            doc.Save(Path.Combine(Environment.CurrentDirectory, "data.xml"));

            Console.WriteLine("Recognize Completed!");

            Console.WriteLine("Press any key to exists!");
        }
Example #3
0
        private DMSentence GetSelectedSentence(TextSelection selection)
        {
            if (selection == null)
            {
                return(null);
            }

            var sender = selection.Start.Parent;

            DMSentence sentence = null;

            switch (sender.GetType().Name)
            {
            case nameof(DMSentence):
                sentence = sender as DMSentence;
                break;

            case nameof(SyncableWord):
                sentence = (sender as SyncableWord).Sentence;
                break;

            case nameof(DMParagraph):
                sentence = (sender as DMParagraph).Sentences.First();
                break;

            default:
                if (sender is TextElement)
                {
                    sentence = GetParent <DMSentence>(sender as TextElement);
                }
                break;
            }
            return(sentence);
        }
Example #4
0
        void SyncEngine_SentenceRecognized(object sender, SentenceRecognizedEventArgs e)
        {
            var message = $"Recognized: [{e.Sentence.Begin.TotalSeconds.ToString("F2")}, {e.Sentence.End.TotalSeconds.ToString("F2")} [{e.Sentence.Text}]]";

            Console.WriteLine(message);
            DMSentence sentence = null;

            myDocument.Dispatcher.Invoke(new Action(() =>
            {
                sentence             = new DMSentence(this._sentenceIndex);
                this._sentenceIndex += 1;

                foreach (var word in e.Sentence.Words)
                {
                    sentence.Inlines.Add(new SyncableWord(word.Text)
                    {
                        BeginTime = word.Begin, EndTime = word.End
                    });
                    sentence.Inlines.Add(new Run(" "));
                }
                sentence.Inlines.Add(new Run(". "));

                var para = new DMParagraph();
                para.Inlines.Add(sentence);
                this.myDocument.Blocks.Add(para);

                if (this._notifyDictationProgress != null)
                {
                    this._notifyDictationProgress.Recognized(sentence.Clone() as DMSentence, this._sentenceIndex);
                }
            }
                                                    ));
        }
        public DialogSpeechTextEditor(DMSentence sentence, Action <string> setSpeechTextCallback)
        {
            InitializeComponent();

            this.CurrentSentence       = sentence;
            this.SetSpeechTextCallback = setSpeechTextCallback;
        }
Example #6
0
        public void Select(TimeSpan begin, TimeSpan end)
        {
            DMSentence first = null;
            DMSentence last  = null;

            foreach (var sentence in this.Dictation.Sentences)
            {
                if (TimeSpanHelper.Intersect(begin, end, sentence.BeginTime, sentence.EndTime))
                {
                    if (first == null)
                    {
                        first = sentence;
                    }
                    last = sentence;
                }
                else if (first != null)
                {
                    break;
                }
            }

            if (first != null && last != null)
            {
                this.SelectElement(first, last);
            }
        }
Example #7
0
        private void ProcessSentence(string cmd, DMSentence selectedSentence)
        {
            var paragraph   = selectedSentence.Paragraph;
            var newSentence = new DMSentence();

            newSentence.Initialize("(New Sentences)");

            switch (cmd)
            {
            case "Before":
                newSentence.BeginTime = selectedSentence.BeginTime;
                newSentence.EndTime   = selectedSentence.BeginTime;
                //this.Document.Insert(this.list_LyricsSentence.SelectedIndex, newLP);
                paragraph.Inlines.InsertBefore(selectedSentence, newSentence);
                break;

            case "Behind":
                newSentence.BeginTime = selectedSentence.EndTime;
                newSentence.EndTime   = selectedSentence.EndTime;
                //this.SentencePhrases.Insert(this.list_LyricsSentence.SelectedIndex + 1, newLP);
                paragraph.Inlines.InsertAfter(selectedSentence, newSentence);
                break;

            case "Delete":
                //this.SentencePhrases.RemoveAt(this.list_LyricsSentence.SelectedIndex);
                paragraph.Inlines.Remove(selectedSentence);
                break;
            }
        }
        void AudioPlayer_PositionChanged(object sender, PositionChangedEventArgs e)
        {
            if (this.Document == null)
            {
                return;
            }

            var position = e.CurrentPosition;

            DMParagraph newSelectedParagraph = null;
            DMSentence  newSelectedSentence  = null;

            bool isInCurrentPara = this.CheckIsInCurrentParagraph(position);

            if (isInCurrentPara == true)
            {
                newSelectedParagraph = this.SelectedParagraph;

                var isInCurrentSen = this.CheckIsInCurrentSentence(position);
                if (isInCurrentSen == true)
                {
                    newSelectedSentence = this.SelectedSentence;
                }
                else
                {
                    newSelectedSentence = this.SelectedParagraph.GetSentence(position);
                }
            }
            else
            {
                newSelectedParagraph = this.Document.GetParagraph(position);
                if (newSelectedParagraph != null)
                {
                    newSelectedSentence = newSelectedParagraph.GetSentence(position);
                }
            }

            if (newSelectedParagraph != this.SelectedParagraph)
            {
                this.SelectedParagraph = newSelectedParagraph;
            }

            if (newSelectedSentence != this.SelectedSentence)
            {
                this.SelectedSentence = newSelectedSentence;
            }

            SyncableWord word = null;

            if (newSelectedSentence != null)
            {
                word = newSelectedSentence.GetWord(position);
            }

            if (word != this.SelectedWord)
            {
                this.SelectedWord = word;
            }
        }
Example #9
0
        private void SelectElement(DMSentence begin, DMSentence end)
        {
            this.flowDocumentScrollViewer.Selection.Changed -= Selection_Changed;

            this.flowDocumentScrollViewer.Selection.Select(begin.ContentStart, end.ContentEnd);
            begin.BringIntoView();

            if (this.SyncableObjectSelected != null)
            {
                this.SyncableObjectSelected(this, new TimelineEventArgs(begin));
            }

            this.flowDocumentScrollViewer.Selection.Changed += Selection_Changed;
        }
Example #10
0
        public void Play(DMSentence sentence)
        {
            if (this.HighlightService.AudioPlayer == null)
            {
                this.HighlightService.AudioPlayer = this.AudioPlayer;
            }

            if (this.HighlightService.IsActivated == false)
            {
                this.HighlightService.Activate();
            }

            if (this.AudioPlayer != null)
            {
                this.AudioPlayer.PlayRange(sentence.BeginTime, sentence.EndTime);
            }
        }
Example #11
0
        private static DMSentence BuildSentence(int index, RecognizedSentence sentence)
        {
            var dmSentence = new DMSentence(index);

            for (int i = 0; i < sentence.Words.Count; i++)
            {
                var          word     = sentence.Words[i];
                SyncableWord syncWord = new SyncableWord(word.Text)
                {
                    BeginTime  = word.Begin,
                    EndTime    = word.End,
                    Confidence = word.Confidence,
                };
                dmSentence.Inlines.Add(syncWord);
            }

            return(dmSentence);
        }
        private string BUildSentenceHtml(DMSentence sentence)
        {
            var sb = new StringBuilder();

            foreach (var syncable in sentence.Syncables.Cast <DependencyObject>())
            {
                if ((bool)syncable.GetValue(SyncExtension.IsCurrentProperty) == true)
                {
                    sb.AppendLine(string.Format("<b style='color:blue;'>{0}</b>", syncable.ToString()));
                }
                else
                {
                    sb.AppendLine(string.Format("<a>{0}</a>", syncable.ToString()));
                }
            }

            return(sb.ToString());
        }
Example #13
0
        private static DMDocument BuildDocument(Core.Lyrics lrc)
        {
            var doc   = new DMDocument();
            var para  = new DMParagraph();
            var index = 0;

            foreach (var phrase in lrc.Phrases)
            {
                var sentence = new DMSentence(index)
                {
                    BeginTime = phrase.BeginTime,
                    EndTime   = phrase.EndTime,
                };
                sentence.Initialize(lrc.Transcript);

                para.Inlines.Add(sentence);

                index += 1;
            }
            doc.Blocks.Add(para);
            return(doc);
        }
Example #14
0
 private void SelectElement(DMSentence textElement)
 {
     this.SelectElement(textElement, textElement);
 }