标签:读音 TONE format pinyin4j import net sourceforge 句子
给定一个汉字句子,可以输出句子的读音。可以借鉴第三方库:pinyin4j 。这个是网址:https://mvnrepository.com/artifact/com.belerweb/pinyin4j 。要求工程是Maven项目。
第一次使用创建maven项目,在eclipse的配置上就花费了不少的时间。
依赖:
<!-- https://mvnrepository.com/artifact/com.belerweb/pinyin4j -->
<dependency>
<groupId>com.belerweb</groupId>
<artifactId>pinyin4j</artifactId>
<version>2.5.0</version>
</dependency>
测试类:
package it.qijian.cn;
import net.sourceforge.pinyin4j.*;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
public class chinasetopinyin {
public static void main(String[] args) throws BadHanyuPinyinOutputFormatCombination {
String chineseString = "中国加油,武汉加油!";
HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
/*
* HanyuPinyinVCharType := WITH_U_AND_COLON
HanyuPinyinCaseType := LOWERCASE
HanyuPinyinToneType := WITH_TONE_NUMBER
*/
format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
/*
Options Output
WITH_TONE_NUMBER da3
WITHOUT_TONE da
WITH_TONE_MARK d菐
*/
format.setToneType(HanyuPinyinToneType.WITH_TONE_MARK);
/*
Options Output
WITH_U_AND_COLON u:
WITH_V v
WITH_U_UNICODE 眉
*/
format.setVCharType(HanyuPinyinVCharType.WITH_U_UNICODE);
/*
* A class provides several utility functions to convert Chinese characters
* (both Simplified and Tranditional) into various Chinese Romanizationrepresentations
*/
String pinyinString = PinyinHelper.toHanyuPinyinString(chineseString, format," ");
System.out.println(chineseString);
System.out.println(pinyinString);
}
}
运行结果:
很明显没有完美的完成这个题目,继续努力。
标签:读音,TONE,format,pinyin4j,import,net,sourceforge,句子 来源: https://blog.csdn.net/qq_43663493/article/details/104695102
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。