public static String chineseToPinyin(String str){
HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
format.setVCharType(HanyuPinyinVCharType.WITH_V);
format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
StringBuilder result = new StringBuilder();
for (int i = 0; i < str.length(); i++) {
char ch = str.charAt(i);
String[] pinyins;
try {
pinyins = PinyinHelper.toHanyuPinyinStringArray(ch,format);
if (pinyins != null){
result.append(pinyins[0]);
} else {
result.append(ch);
}
} catch (BadHanyuPinyinOutputFormatCombination e) {
e.printStackTrace();
}
}
return result.toString();
}