1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package helper;
import com.yanzuoguang.util.ChineseHelper;
import com.yanzuoguang.util.vo.BaiduConfig;
import com.yanzuoguang.util.vo.HanziVo;
import com.yanzuoguang.util.helper.JsonHelper;
import org.junit.Test;
import java.io.File;
import java.util.List;
public class TestChineseHelper {
@Test
public void testConvert() {
String text = "颜佐光还喜欢游泳";
List<HanziVo> items = ChineseHelper.getPinyin(text);
System.out.println("json:" + JsonHelper.serialize(items, true));
}
@Test
public void testConvertMp3() {
String text = "三分钟前,由北京市顺义区二经路与二纬路交汇处北侧,北京首都国际机场T3航站楼 去往 东城区北三环东路36号喜来登大酒店(北京金隅店)";
BaiduConfig config = new BaiduConfig(
"20624068",
"aeo4CBIjiW4wLuiIAKD4ZMrk",
"BLzIf80xq6v1cN4n231dSGPYqD1GDHy8");
ChineseHelper.saveVideo(config, text, getTargetFile("test.mp3"));
}
@Test
public void testConvertMp3Yzg() {
String text = "成人票15元";
BaiduConfig config = new BaiduConfig(
"20624068",
"aeo4CBIjiW4wLuiIAKD4ZMrk",
"BLzIf80xq6v1cN4n231dSGPYqD1GDHy8");
ChineseHelper.saveVideo(config, text, getTargetFile("product.mp3"));
}
private File getTargetFile(String to) {
// 注意,路径应为文件在工程中的相对路径
File f = new File("target/" + to);
return f;
}
}