Convert Chinese lyric to pinyin

This is specially for those who want to sing Chinese song in karaoke. Recently I like to listen to Jay Chou ‘s song in his latest album ‘Exclamation Mark’, especially 水手怕水(Sailor scare of water) & 皮影戏. I get a lyrics player – 千千静听 then load the lyric file so it can display the lyric while I play the song.

Initially I try to copy paste whole content at Google translate and try to get the result what I want. But it do the proper translate of course you can get the pronunciation when you press the voice button. However this cannot be printed and bring into Karaoke room when you want to sing it. My solution is get a unicode-pinyin library at uc-to-py.tbl then created a very simple parser to convert Chinese character to pinyin pronunciation.

Example

[00:00.00]水手怕水—周杰伦
[00:02.00]
[00:02.23]大海真可怕
[00:03.41]叫我 水手 oh oh come on come on baby
[00:06.83]美人鱼勾引我这招 卑鄙
[00:00.00]shui3 shou3 pa4 shui3 —zhou1 jie2 lun2
[00:02.00]
[00:02.23]da4 hai3 zhen1 ke3 pa4
[00:03.41]jiao4 wo3 shui3 shou3 oh oh come on come on baby
[00:06.83]mei3 ren2 yu2 gou1 yin3 wo3 zhei4 zhao1 bei1 bi3

 

The library source is something like this

3007 (ling2)
4E00 (yi1)
4E01 (ding1,zheng1)
4E02 (kao3)
4E03 (qi1)
4E04 (shang4,shang3)
4E05 (xia4)

I create a dictionary collection to hold a character with the corresponding pinying value.

Dictionary<char, string[]> libs = new Dictionary<char, string[]>();
...
char key = '\0';//default empty char
int keyValue = Convert.ToInt32("4E00", 16);
key = (char)keyValue;//cast to unicode character
libs.Add(key, "ling2");
...

You can imagine the collection is holding
[一: yi1]
[丁: ding1,zheng1]
[丂: kao3]
[七: qi1]

Download
It is a console app. Put the 2 files together and your lrc or text file gonna be convert. Remember to backup your source file. It will directly overwrite the source file after conversion.

TODO: Enhancement convert Japanese Hirakana or Korean Hangul to roman character so we can sing Wonder Girls – ‘Nobody’ and Girl Generation – ‘Mr. Taxi Taxi’ 🙂
see http://code.google.com/p/cjklib/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s