示例#1
0
        public List <Utterance> ConvertSentence(string sentence)
        {
            List <Utterance> toReturn = new List <Utterance>();

            string[] words = sentence.Split(' ');
            foreach (string word in words)
            {
                if (word != "." && word != ",")
                {
                    Utterance utter = new Utterance();
                    utter.Type     = UtteranceType.Syllable;
                    utter.Syllable = Syllables[Math.Abs(word.GetHashCode()) % Syllables.Count];

                    if (toReturn.Count == 0 || utter.Syllable != toReturn.Last().Syllable)
                    {
                        toReturn.Add(utter);
                    }
                }
                else
                {
                    Utterance pause = new Utterance();
                    pause.Type = UtteranceType.Pause;
                    toReturn.Add(pause);
                }
            }

            return(toReturn);
        }
示例#2
0
        public List<Utterance> ConvertSentence(string sentence)
        {
            List<Utterance> toReturn = new List<Utterance>();
            string[] words = sentence.Split(' ');
            foreach(string word in words)
            {
                if(word != "." && word != ",")
                {
                    Utterance utter = new Utterance();
                    utter.Type = UtteranceType.Syllable;
                    utter.Syllable = Syllables[Math.Abs(word.GetHashCode()) % Syllables.Count];

                    if(toReturn.Count == 0 || utter.Syllable != toReturn.Last().Syllable)
                    {
                        toReturn.Add(utter);
                    }
                }
                else
                {
                    Utterance pause = new Utterance();
                    pause.Type = UtteranceType.Pause;
                    toReturn.Add(pause);
                }
            }

            return toReturn;
        }
示例#3
0
        private IEnumerable <Utterance> ConvertSentence(string sentence)
        {
            string[] words = sentence.Split(' ');
            for (int i = 0; i < words.Length; i++)
            {
                words[i] += " ";
            }

            List <string> syls      = new List <string>();
            int           chunkSize = 5;

            foreach (var word in words)
            {
                int i = 0;
                for (i = 0; i < word.Length - chunkSize; i += chunkSize)
                {
                    syls.Add(word.Substring(i, chunkSize));
                }

                if (i < word.Length)
                {
                    syls.Add(word.Substring(i));
                }
            }


            if (syls.Count == 0)
            {
                syls.Add(sentence);
            }
            int    utterances    = 0;
            string lastUtterance = null;
            string builtSentence = "";

            foreach (string word in syls)
            {
                builtSentence += word;
                string subSentence = new string(builtSentence.ToCharArray());
                if (!(word.Contains(".") || word.Contains(",")))
                {
                    Utterance utter = new Utterance();
                    utter.Type        = UtteranceType.Syllable;
                    utter.SubSentence = subSentence;
                    utter.Syllable    = Syllables[(int)word[0] % Syllables.Count];

                    if (utterances == 0 || utter.Syllable != lastUtterance)
                    {
                        lastUtterance = utter.Syllable;
                        yield return(utter);
                    }
                }
                else
                {
                    Utterance utter = new Utterance();
                    utter.Type        = UtteranceType.Syllable;
                    utter.SubSentence = subSentence;
                    utter.Syllable    = Syllables[(int)word[0] % Syllables.Count];

                    if (utterances == 0 || utter.Syllable != lastUtterance)
                    {
                        lastUtterance = utter.Syllable;
                        yield return(utter);
                    }
                    Utterance pause = new Utterance {
                        Type = UtteranceType.Pause, SubSentence = subSentence
                    };
                    yield return(pause);
                }
            }
        }