Exemplo n.º 1
0
        /// <summary>
        /// Dump the data in the utterance to a script item.
        /// </summary>
        /// <param name="utt">The utterance for dumpping.</param>
        /// <param name="ttsEngine">The object ttsEngine to help to convert the Pos and get sentence id.</param>
        /// <returns>A script item object.</returns>
        public static ScriptItem ToScriptItem(this SP.TtsUtterance utt, SP.TtsEngine ttsEngine)
        {
            if (ttsEngine == null)
            {
                throw new ArgumentNullException("ttsEngine");
            }

            ScriptItem item = new ScriptItem();
            item.Text = utt.OriginalText;
            item.Id = Helper.NeutralFormat("{0:D" + IdLength + "}", BeginId);
            ScriptSentence sentence = new ScriptSentence();
            sentence.SentenceType = (SentenceType)utt.SentenceType;
            DumpWords(sentence, utt, ttsEngine, GetLanguage(utt));
            sentence.Text = sentence.BuildTextFromWords();
            item.Sentences.Add(sentence);
            return item;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Generate script item from raw text(only generate to word level).
        /// </summary>
        /// <param name="text">Plain text.</param>
        /// <returns>ScriptItem.</returns>
        public ScriptItem GenerateScriptItem(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                throw new ArgumentNullException("text");
            }

            // this function should contain "ProcessMode.TextProcess"
            if ((_mode & ProcessMode.TextProcess) == 0)
            {
                throw new InvalidOperationException("Process mode can only be ProcessMode.TextProcess");
            }

            ScriptItem item = new ScriptItem();
            item.Text = text;

            foreach (SP.TtsUtterance utt in EspUtterances(text))
            {
                using (utt)
                {
                    if (utt.Words.Count == 0)
                    {
                        continue;
                    }

                    ScriptSentence sentence = new ScriptSentence();
                    foreach (SP.TtsWord word in utt.Words)
                    {
                        if (!string.IsNullOrEmpty(word.WordText))
                        {
                            ScriptWord scriptWord = new ScriptWord();
                            scriptWord.Grapheme = word.WordText;

                            if (!string.IsNullOrEmpty(word.Pronunciation))
                            {
                                scriptWord.Pronunciation = word.Pronunciation.ToLowerInvariant();
                            }

                            scriptWord.WordType = WordType.Normal;
                            if (word.WordType == SP.TtsWordType.WT_PUNCTUATION)
                            {
                                scriptWord.WordType = WordType.Punctuation;
                            }

                            scriptWord.PronSource = (TtsPronSource)word.PronSource;

                            sentence.Words.Add(scriptWord);
                        }
                    }

                    sentence.Text = sentence.BuildTextFromWords();
                    item.Sentences.Add(sentence);
                }
            }

            return item;
        }