想知道是否有人知道可以將中文拼音轉換成音調的類庫,比如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