/// <summary> /// Set nucleus vowel stress mark. /// </summary> /// <param name="phoneme">Phoneme of the language to process.</param> /// <param name="pronunciation">Pronunciation to set pronunciation.</param> /// <param name="stress">Stress mark to set for the vowel in the pronunciation.</param> /// <returns>Pronunciation with stress.</returns> public static string SetVowelStress(Phoneme phoneme, string pronunciation, TtsStress stress) { if (phoneme == null) { throw new ArgumentNullException("phoneme"); } if (string.IsNullOrEmpty(pronunciation)) { return null; } if (stress > TtsStress.None) { string[] phones = pronunciation.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); int vowelIndex = phoneme.GetFirstVowelIndex(phones); if (vowelIndex < 0) { string message = string.Format(CultureInfo.InvariantCulture, "There is no vowel found in the syllable pronunciation [{0}]", phones); throw new InvalidDataException(message); } phones[vowelIndex] = string.Format(CultureInfo.InvariantCulture, "{0} {1}", phones[vowelIndex], (int)stress); return string.Join(" ", phones); } else { return pronunciation; } }
/// <summary> /// Calculate the target cost for stress feature. /// </summary> /// <param name="src">Source TtsStress feature.</param> /// <param name="target">Target TtsStress feature.</param> /// <returns>Cost.</returns> private float CalcTargetCostTtsStress(TtsStress src, TtsStress target) { return CalcTargetCost(TtsFeature.TtsStress, (int)src, (int)target); }
/// <summary> /// Convert TtsStress to string used in script file. /// </summary> /// <param name="stress">TtsStress.</param> /// <returns> /// String representation of TtsStress. /// </returns> public static string StressToString(TtsStress stress) { string name = string.Empty; switch (stress) { case TtsStress.Primary: name = @"1"; break; case TtsStress.Secondary: name = @"2"; break; case TtsStress.Tertiary: name = @"3"; break; } return name; }