Esempio n. 1
0
        /// <summary>
        /// Build units from syllable.
        /// </summary>
        /// <param name="syllable">Syllable.</param>
        /// <param name="sliceData">Slice data.</param>
        /// <param name="pronunciationSeparator">Pronunciation separator.</param>
        /// <returns>Units.</returns>
        private static Collection<TtsUnit> BuildUnitsForSyllable(ScriptSyllable syllable,
            SliceData sliceData, PronunciationSeparator pronunciationSeparator)
        {
            Debug.Assert(syllable != null);
            Debug.Assert(sliceData != null);

            string syllableText = Core.Pronunciation.RemoveStress(syllable.Text.Trim());
            string[] slices = pronunciationSeparator.SplitSlices(syllableText);

            PosInSyllable[] pis = EstimatePosInSyllable(slices, sliceData);

            Collection<TtsUnit> units = new Collection<TtsUnit>();
            for (int sliceIndex = 0; sliceIndex < slices.Length; sliceIndex++)
            {
                string slice = slices[sliceIndex].Trim();
                if (string.IsNullOrEmpty(slice))
                {
                    continue;
                }

                TtsUnit unit = new TtsUnit(sliceData.Language);

                // break level
                unit.TtsBreak = (sliceIndex == slices.Length - 1) ? syllable.TtsBreak : TtsBreak.Phone;

                // pos in syllable
                unit.Feature.PosInSyllable = pis[sliceIndex];

                // NONE: punctuation type

                // emphasis
                unit.Feature.TtsEmphasis = syllable.TtsEmphasis;

                // stress mark
                unit.Feature.TtsStress = syllable.Stress;

                // fill unit name
                // remove stress mark and replace white space with '+' for unit name
                unit.MetaUnit.Name = Regex.Replace(slice, " +", @"+");
                unit.MetaUnit.Language = unit.Language;

                units.Add(unit);
            }

            return units;
        }
Esempio n. 2
0
        /// <summary>
        /// Build word unit without filling features.
        /// </summary>
        /// <param name="sliceData">Slice data.</param>
        /// <param name="pronunciationSeparator">Pronunciation separator.</param>
        public void BuildUnitWithoutFeature(SliceData sliceData,
            PronunciationSeparator pronunciationSeparator)
        {
            if (Units.Count > 0)
            {
                return;
            }

            UpdateUnitSyllables();

            for (int syllableIndex = 0; syllableIndex < UnitSyllables.Count; syllableIndex++)
            {
                ScriptSyllable syllable = UnitSyllables[syllableIndex];
                syllable.Tag = this;

                Collection<TtsUnit> syllableUnits = BuildUnitsForSyllable(syllable, sliceData, pronunciationSeparator);
                for (int i = 0; i < syllableUnits.Count; i++)
                {
                    syllableUnits[i].WordType = WordType;
                    syllableUnits[i].Tag = syllable;
                    syllableUnits[i].Word = this;

                    Units.Add(syllableUnits[i]);
                }
            }

            // Parse TCGPP score to TtsMetaPhone
            if (!string.IsNullOrEmpty(_tcgppScores))
            {
                string[] tcgppScores = _tcgppScores.Split(new char[] { TcgppScoreDelimeter },
                    StringSplitOptions.RemoveEmptyEntries);
                int index = 0;
                foreach (TtsUnit unit in Units)
                {
                    foreach (TtsMetaPhone phone in unit.MetaUnit.Phones)
                    {
                        if (index >= tcgppScores.Length)
                        {
                            throw new InvalidDataException(Helper.NeutralFormat(
                                "Invalid TCGPP score format [{0}]", _tcgppScores));
                        }

                        phone.TcgppScore = int.Parse(tcgppScores[index]);
                        index++;
                    }
                }
            }
        }