Example #1
0
 /// <summary>
 /// Calculate the target cost for position in syllable feature.
 /// </summary>
 /// <param name="src">Source PosInSyllable feature.</param>
 /// <param name="target">Target PosInSyllable feature.</param>
 /// <returns>Cost.</returns>
 private float CalcTargetCostPosInSyl(PosInSyllable src, PosInSyllable target)
 {
     return CalcTargetCost(TtsFeature.PosInSyllable, (int)src, (int)target);
 }
Example #2
0
        /// <summary>
        /// Build unit full name, this is, prefix "os_", "nc_" or "cd_" to the unit name.
        /// </summary>
        /// <param name="name">Unit name.</param>
        /// <param name="slicePos">Position in syllable feature of the unit.</param>
        /// <returns>Full name string of the unit.</returns>
        public static string BuildUnitFullName(string name, PosInSyllable slicePos)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            if (name.StartsWith("os_", StringComparison.Ordinal) || 
                        name.StartsWith("nc_", StringComparison.Ordinal) || 
                        name.StartsWith("cd_", StringComparison.Ordinal))
            {
                throw new ArgumentException("unit name [{0}] should be start with os_, nc_ or cd_", name);
            }

            switch (slicePos)
            {
                case PosInSyllable.Onset:
                case PosInSyllable.OnsetNext:
                    return "os_" + name;
                case PosInSyllable.NucleusInV:
                case PosInSyllable.NucleusInVC:
                case PosInSyllable.NucleusInCV:
                case PosInSyllable.NucleusInCVC:
                    return "nc_" + name;
                case PosInSyllable.CodaNext:
                case PosInSyllable.Coda:
                    return "cd_" + name;
                default:
                    Debug.Assert(false);
                    string str1 = "Only Onset, OnsetNext, NucleusInV, NucleusInVC, NucleusInCV, NucleusInCVC, CodaNext or Code is ";
                    string str2 = "supported for unit full name generation. ";
                    string str3 = "But position in syllable [{0}] is found.";
                    string message = string.Format(CultureInfo.InvariantCulture, str1 + str2 + str3, slicePos);
                    throw new NotSupportedException(message);
            }
        }
 /// <summary>
 /// Whether is vowel for position in syllable.
 /// </summary>
 /// <param name="posInSyllable">Position in syllable.</param>
 /// <returns>True for vowel.</returns>
 public static bool IsVowel(PosInSyllable posInSyllable)
 {
     return posInSyllable == PosInSyllable.NucleusInV ||
         posInSyllable == PosInSyllable.NucleusInVC ||
         posInSyllable == PosInSyllable.NucleusInCV ||
         posInSyllable == PosInSyllable.NucleusInCVC;
 }
Example #4
0
        /// <summary>
        /// Estimate position in syllable for each slice in a slice set.
        /// </summary>
        /// <param name="slices">Slice collection to estimate.</param>
        /// <returns>Estimated result of position in syllable.</returns>
        private PosInSyllable[] EstimatePosInSyllable(string[] slices)
        {
            PosInSyllable[] pis = new PosInSyllable[slices.Length];
            int nucleusIndex = -1;

            for (int sliceIndex = 0; sliceIndex < slices.Length; sliceIndex++)
            {
                SliceData slicedata = Localor.GetSliceData(this.Language);
                TtsMetaUnit ttsMetaUnit = new TtsMetaUnit(this.Language);
                ttsMetaUnit.Name = slices[sliceIndex];

                if (slicedata.IsNucleus(ttsMetaUnit))
                {
                    if (sliceIndex == 0)
                    {
                        if (sliceIndex == slices.Length - 1)
                        {
                            pis[sliceIndex] = PosInSyllable.NucleusInV;
                        }
                        else
                        {
                            pis[sliceIndex] = PosInSyllable.NucleusInVC;
                        }
                    }
                    else
                    {
                        if (sliceIndex == slices.Length - 1)
                        {
                            pis[sliceIndex] = PosInSyllable.NucleusInCV;
                        }
                        else
                        {
                            pis[sliceIndex] = PosInSyllable.NucleusInCVC;
                        }
                    }

                    nucleusIndex = sliceIndex;
                    break;
                }
            }

            for (int sliceIndex = 0; sliceIndex < nucleusIndex; sliceIndex++)
            {
                pis[sliceIndex] = PosInSyllable.Onset;
            }

            for (int sliceIndex = nucleusIndex + 1; sliceIndex < slices.Length; sliceIndex++)
            {
                pis[sliceIndex] = PosInSyllable.Coda;
            }

            return pis;
        }
Example #5
0
 /// <summary>
 /// Map slice position.
 /// </summary>
 /// <param name="slicePos">Slice Position.</param>
 /// <returns>Prefix string of slice position.</returns>
 public static string MapSlicePos(PosInSyllable slicePos)
 {
     switch (slicePos)
     {
         case PosInSyllable.Onset:
         case PosInSyllable.OnsetNext:
             return "os_";
         case PosInSyllable.NucleusInV:
         case PosInSyllable.NucleusInVC:
         case PosInSyllable.NucleusInCV:
         case PosInSyllable.NucleusInCVC:
             return "nc_";
         case PosInSyllable.CodaNext:
         case PosInSyllable.Coda:
             return "cd_";
         default:
             System.Diagnostics.Debug.Assert(false);
             string str1 = "Only Onset, OnsetNext, NucleusInV, NucleusInVC, NucleusInCV, NucleusInCVC, CodaNext or Coda is ";
             string str2 = "supported for mapping position to syllable to string. ";
             string str3 = "But position to syllable [{0}] is found.";
             string message = string.Format(CultureInfo.InvariantCulture, str1 + str2 + str3, slicePos);
             throw new NotSupportedException(message);
     }
 }