Commit b3beb8bf by 苗权威

Merge branch 'master' of http://192.168.1.81:8000/Foxes/SmartBox

parents 397c4fda 3d3ba9d2
...@@ -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)));
......
...@@ -124,7 +124,7 @@ public class OkHttp3Utils { ...@@ -124,7 +124,7 @@ public class OkHttp3Utils {
urlBuild.addQueryParameter("uid", uid); urlBuild.addQueryParameter("uid", uid);
builder.headers(headBuilder.build()).post(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), requestJsonStr)); builder.url(urlBuild.build()).headers(headBuilder.build()).post(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), requestJsonStr));
Response response = client.newCall(builder.build()).execute(); Response response = client.newCall(builder.build()).execute();
try (ResponseBody body = response.body()){ try (ResponseBody body = response.body()){
return body.string(); return body.string();
......
...@@ -10,6 +10,7 @@ import com.alibaba.fastjson.JSON; ...@@ -10,6 +10,7 @@ import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import java.io.IOException; import java.io.IOException;
import java.net.URLEncoder;
import java.util.HashMap; import java.util.HashMap;
/** /**
...@@ -98,7 +99,13 @@ public class RequestTerminal { ...@@ -98,7 +99,13 @@ public class RequestTerminal {
requestPojo.setUid(userId); requestPojo.setUid(userId);
requestPojo.setMsg(XiaoAiConstants.TTS.END_WORD); requestPojo.setMsg(XiaoAiConstants.TTS.END_WORD);
String requestJsonStr = JSON.toJSONString(requestPojo); String requestJsonStr = JSON.toJSONString(requestPojo);
OkHttp3Utils.xiaoaiBackPostAsync(ScheduleServiceNew.BASE_HOST_URL+"?uid="+userId, requestJsonStr, type); String uid = userId;
try {
uid = URLEncoder.encode(userId, "UTF-8");
}catch(Exception e) {
uid = userId;
}
OkHttp3Utils.xiaoaiBackPostAsync(ScheduleServiceNew.BASE_HOST_URL+"?uid="+uid, requestJsonStr, type);
// if (userId.equals(XiaoAiService.deviceId)) { // if (userId.equals(XiaoAiService.deviceId)) {
// OkHttp3Utils.backPostAsync(XiaoAiConstants.QI_WU_TERMINATE_DIDI, requestJsonStr, type); // OkHttp3Utils.backPostAsync(XiaoAiConstants.QI_WU_TERMINATE_DIDI, requestJsonStr, type);
// }else { // }else {
......
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