Commit 87733188 by 李进峰

讯飞SSML标记修改,添加默认读音

parent 4c433f5e
...@@ -1008,6 +1008,7 @@ public class TTServiceEdition2 { ...@@ -1008,6 +1008,7 @@ public class TTServiceEdition2 {
// 代码作用是替换标音符号,讯非标音要求查看讯非文档 // 代码作用是替换标音符号,讯非标音要求查看讯非文档
// http://bbs.xfyun.cn/forum.php?mod=viewthread&tid=15340 // http://bbs.xfyun.cn/forum.php?mod=viewthread&tid=15340
StringBuilder temp = new StringBuilder(); StringBuilder temp = new StringBuilder();
temp.append("<?xml version=\"1.0\" encoding=\"GB2312\"?><speak>");
int sliceStart = 0; int sliceStart = 0;
for (int i = 0; i < text.length()-1; i++) { for (int i = 0; i < text.length()-1; i++) {
if (text.charAt(i) == '{' && text.charAt(i+1) == '/') { if (text.charAt(i) == '{' && text.charAt(i+1) == '/') {
...@@ -1043,6 +1044,7 @@ public class TTServiceEdition2 { ...@@ -1043,6 +1044,7 @@ public class TTServiceEdition2 {
if (sliceStart < text.length()) { if (sliceStart < text.length()) {
temp.append(text.substring(sliceStart)); temp.append(text.substring(sliceStart));
} }
temp.append("</speak>");
text = temp.toString(); text = temp.toString();
} else { } else {
text = text.replaceAll("\\{/", "[="); text = text.replaceAll("\\{/", "[=");
...@@ -1139,6 +1141,9 @@ public class TTServiceEdition2 { ...@@ -1139,6 +1141,9 @@ public class TTServiceEdition2 {
// return new ResponseCodeWithData(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "文本标音不正确"); // return new ResponseCodeWithData(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "文本标音不正确");
return null; return null;
} }
if(!Character.isDigit(mark.charAt(mark.length()-1))) {
mark = mark+"5";
}
temp.append(text, sliceStart, j).append("<phoneme alphabet=\"py\" ph=\"").append(mark).append("\">").append(text.charAt(j)).append("</phoneme>"); temp.append(text, sliceStart, j).append("<phoneme alphabet=\"py\" ph=\"").append(mark).append("\">").append(text.charAt(j)).append("</phoneme>");
for (; markEnd < text.length(); markEnd++) { for (; markEnd < text.length(); markEnd++) {
if (text.charAt(markEnd) == '}') { if (text.charAt(markEnd) == '}') {
......
...@@ -93,8 +93,8 @@ public class ThirdPartyService { ...@@ -93,8 +93,8 @@ public class ThirdPartyService {
*/ */
public static boolean thirdPartyCall(String text, String per, String filepath, String person) { public static boolean thirdPartyCall(String text, String per, String filepath, String person) {
// person = getThirdPartyName(person); // person = getThirdPartyName(person);
person = person.substring(0, 5); String subPerson = person.substring(0, 5);
switch (person) { switch (subPerson) {
// 文本小于2048个中文字或者英文数字 // 文本小于2048个中文字或者英文数字
case "Baidu" : { case "Baidu" : {
return synthesis(text, Integer.parseInt(per), filepath); return synthesis(text, Integer.parseInt(per), filepath);
...@@ -115,7 +115,7 @@ public class ThirdPartyService { ...@@ -115,7 +115,7 @@ public class ThirdPartyService {
// 最大长度需小于8000字节,约2000汉字 // 最大长度需小于8000字节,约2000汉字
case "XunFe": { case "XunFe": {
try { try {
return xunFeiTTS(per, text, filepath); return xunFeiTTS(per, text, filepath, person);
} catch (Exception e) { } catch (Exception e) {
log.error("xunFeiTTS error:{}, text:{}, filepath:{}", e, text, filepath); log.error("xunFeiTTS error:{}, text:{}, filepath:{}", e, text, filepath);
return false; return false;
...@@ -348,7 +348,7 @@ public class ThirdPartyService { ...@@ -348,7 +348,7 @@ public class ThirdPartyService {
// ============== XUN FEI =================== // ============== XUN FEI ===================
private static boolean xunFeiTTS(String per, String text, String filepath) throws Exception { private static boolean xunFeiTTS(String per, String text, String filepath, String person) throws Exception {
// 构建鉴权url // 构建鉴权url
// String authUrl = getAuthUrl(); // String authUrl = getAuthUrl();
//将url中的 schema http://和https://分别替换为ws:// 和 wss:// //将url中的 schema http://和https://分别替换为ws:// 和 wss://
...@@ -380,6 +380,21 @@ public class ThirdPartyService { ...@@ -380,6 +380,21 @@ public class ThirdPartyService {
//填充business //填充business
XunFeiRequestDataBusiness business = audioRequest.getBusiness(); XunFeiRequestDataBusiness business = audioRequest.getBusiness();
business.setVcn(per); business.setVcn(per);
if (Initialize.xunfeiUseSSMLPerson.contains(person)) {
try {
audioRequest.getData().setText(Base64.getEncoder().encodeToString(text.getBytes("GBK")));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
audioRequest.getData().setText(Base64.getEncoder().encodeToString(text.getBytes(StandardCharsets.UTF_8)));
}
}else {
//填充data
audioRequest.getData().setText(Base64.getEncoder().encodeToString(text.getBytes(StandardCharsets.UTF_8)));
//使用小语种须使用下面的代码,此处的unicode指的是 utf16小端的编码方式,即"UTF-16LE"”
//data.addProperty("text", Base64.getEncoder().encodeToString(text.getBytes("UTF-16LE")));
}
//填充data //填充data
audioRequest.getData().setText(Base64.getEncoder().encodeToString(text.getBytes(StandardCharsets.UTF_8))); audioRequest.getData().setText(Base64.getEncoder().encodeToString(text.getBytes(StandardCharsets.UTF_8)));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment