예제 #1
0
        /// <summary>
        /// Parsing the syllable string to a script syllable
        /// Here we suppose syllable is a valid pronunciation string.
        /// </summary>
        /// <param name="syllable">Syllable string, doesn't include unit boundary.</param>
        /// <param name="phoneSet">TtsPhoneSet.</param>
        /// <returns>The constructed script syllable.</returns>
        public static ScriptSyllable ParseStringToSyllable(string syllable, TtsPhoneSet phoneSet)
        {
            if (string.IsNullOrEmpty(syllable))
            {
                throw new ArgumentNullException("syllable");
            }

            if (phoneSet == null)
            {
                throw new ArgumentNullException("phoneSet");
            }

            ScriptSyllable scriptSyllable = new ScriptSyllable(phoneSet.Language);
            ErrorSet errors = new ErrorSet();
            Phone[] phones = Pronunciation.SplitIntoPhones(syllable, phoneSet, errors);
            if (errors.Count > 0)
            {
                string message = Helper.NeutralFormat(
                    "The syllable string [{0}] isn't valid : {1}{2}",
                    syllable, Environment.NewLine, errors.ErrorsString());
                throw new InvalidDataException(message);
            }

            Collection<ScriptPhone> scriptPhones = new Collection<ScriptPhone>();
            foreach (Phone phone in phones)
            {
                if (phone.HasFeature(PhoneFeature.MainStress) ||
                    phone.HasFeature(PhoneFeature.SubStress))
                {
                    switch (phone.Name)
                    {
                        case "1":
                            scriptSyllable.Stress = TtsStress.Primary;
                            break;
                        case "2":
                            scriptSyllable.Stress = TtsStress.Secondary;
                            break;
                        case "3":
                            scriptSyllable.Stress = TtsStress.Tertiary;
                            break;
                    }
                }
                else if (phone.HasFeature(PhoneFeature.Tone))
                {
                    scriptPhones[scriptPhones.Count - 1].Tone = phone.Name;
                }
                else
                {
                    ScriptPhone scriptPhone = new ScriptPhone(phone.Name);
                    scriptPhone.Syllable = scriptSyllable;
                    scriptPhones.Add(scriptPhone);
                }
            }

            scriptSyllable.Phones.Clear();
            Helper.AppendCollection(scriptSyllable.Phones, scriptPhones);
            return scriptSyllable;
        }