想知道是否有人知道可以将中文拼音转换成音调的类库,比如nin2 hao3 ma到nínhǎoma。这将类似于this answer,但希望使用.NET框架。任何图书馆将数字拼音转换为拼音与音色标记?
3
A
回答
1
2
这里是我将@ Greg-Hewgill python algorithm移植到C#。到目前为止我还没有遇到任何问题。
public static string ConvertNumericalPinYinToAccented(string input)
{
Dictionary<int, string> PinyinToneMark = new Dictionary<int, string>
{
{0, "aoeiuv\u00fc"},
{1, "\u0101\u014d\u0113\u012b\u016b\u01d6\u01d6"},
{2, "\u00e1\u00f3\u00e9\u00ed\u00fa\u01d8\u01d8"},
{3, "\u01ce\u01d2\u011b\u01d0\u01d4\u01da\u01da"},
{4, "\u00e0\u00f2\u00e8\u00ec\u00f9\u01dc\u01dc"}
};
string[] words = input.Split(' ');
string accented = "";
string t = "";
foreach (string pinyin in words)
{
foreach (char c in pinyin)
{
if (c >= 'a' && c <= 'z')
{
t += c;
}
else if (c == ':')
{
if (t[t.Length - 1] == 'u')
{
t = t.Substring(0, t.Length - 2) + "\u00fc";
}
}
else
{
if (c >= '0' && c <= '5')
{
int tone = (int)Char.GetNumericValue(c) % 5;
if (tone != 0)
{
Match match = Regex.Match(t, "[aoeiuv\u00fc]+");
if (!match.Success)
{
t += c;
}
else if (match.Groups[0].Length == 1)
{
t = t.Substring(0, match.Groups[0].Index) +
PinyinToneMark[tone][PinyinToneMark[0].IndexOf(match.Groups[0].Value[0])]
+ t.Substring(match.Groups[0].Index + match.Groups[0].Length);
}
else
{
if (t.Contains("a"))
{
t = t.Replace("a", PinyinToneMark[tone][0].ToString());
}
else if (t.Contains("o"))
{
t = t.Replace("o", PinyinToneMark[tone][1].ToString());
}
else if (t.Contains("e"))
{
t = t.Replace("e", PinyinToneMark[tone][2].ToString());
}
else if (t.Contains("ui"))
{
t = t.Replace("i", PinyinToneMark[tone][3].ToString());
}
else if (t.Contains("iu"))
{
t = t.Replace("u", PinyinToneMark[tone][4].ToString());
}
else
{
t += "!";
}
}
}
}
accented += t;
t = "";
}
}
accented += t + " ";
}
accented = accented.TrimEnd();
return accented;
}
0
我觉得这条线
t = t.Substring(0, t.Length - 2) + "\u00fc";
应该是这个,而不是
t = t.Substring(0, t.Length - 1) + "\u00fc";
+0
我认为这是作为评论http://stackoverflow.com/a/20106483/6872499 – silentsod 2017-01-25 17:05:52
相关问题
- 1. 如何将汉字转换为拼音
- 2. 转换为突出拼音?
- 3. 将中文转换为拼音
- 4. 将单词转换为Sphinx4的拼音发音
- 5. 转换中国字汉语拼音
- 6. 拼音字母和数字
- 7. 将带有口音的汉语拼音转换为数字形式
- 8. 将字符串转换为OTAN拼音字母表的字典
- 9. Python CJKLIB:无拼音色调
- 10. 使用拼音声音的文字转语音
- 11. 编码拼音
- 12. lua中的拼音字体
- 13. 语音识别将单词拼音到音素水平
- 14. Python和Java中的拼音拼写
- 15. 是否有关于如何将汉字转换为拼音的官方文档?
- 16. 使用语音标记将声音与SAPI 5.1文本交换为语音
- 17. 如何在Linux上拼音IronPython
- 18. TTS课堂:如何TTS中文拼音?
- 19. 在Ivona中传递ssml格式时音频拼写标记
- 20. 与音频转换
- 21. 将原始字节转换为音频声音
- 22. C#返回语音拼音而不识别它
- 23. 如何管理口音标记(书面口音)
- 24. 将音频加倍转换为字节
- 25. 如何填充一个二维字符数组用拼音
- 26. 有没有任何算法将图像转换为声音?
- 27. 从地板拼接文件读取/写入拼音张量
- 28. MySQL的ORDER BY结果不是拼音
- 29. 苹果的拼音排名算法
- 30. MySQL中文拼音编码问题
@贾斯汀:你会介意给个例子吗?在帮助文件(或任何少数代码示例)中没有任何提及,我发现它显示了是否可以在数字拼音和单音拼音之间进行转换。 – LittleTiger 2012-08-21 10:56:23