更新
This commit is contained in:
parent
1f98b82090
commit
e50e7eac37
@ -39,10 +39,25 @@ public class ChatHttpApi {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("/getChatInfo")
|
@PostMapping("/getChatInfo")
|
||||||
public AjaxResult getChatInfo(@RequestBody Map<String, String> requestData) throws Exception {
|
public AjaxResult getChatInfo(@RequestBody Map<String, String> requestData) throws Exception {
|
||||||
if ("Chinese".equals(requestData.get("lang").toString())) {
|
if (isChinese(requestData.get("q").toString()) ){
|
||||||
return AjaxResult.success(requestData.get("q").toString());
|
return AjaxResult.success(requestData.get("q").toString());
|
||||||
}
|
}
|
||||||
requestData.put("to", "zh-CHS");
|
requestData.put("to", "zh-CHS");
|
||||||
|
requestData.put("strict", "true");
|
||||||
return AjaxResult.success(chatService.textTranslators(requestData));
|
return AjaxResult.success(chatService.textTranslators(requestData));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isChinese(String str) {
|
||||||
|
for (int i=0; i<str.length(); i++) {
|
||||||
|
int codePoint = str.codePointAt(i);
|
||||||
|
if (!(codePoint >= 0x4e00 && codePoint <= 0x9fff) &&
|
||||||
|
!(codePoint >= 0x3400 && codePoint <= 0x4dbf) &&
|
||||||
|
!(codePoint >= 0x20000 && codePoint <= 0x2a6df) &&
|
||||||
|
!(codePoint >= 0xf900 && codePoint <= 0xfaff)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -304,6 +304,12 @@ public class ChatService {
|
|||||||
*/
|
*/
|
||||||
public String textTranslators(Map<String, String> requestData) throws Exception {
|
public String textTranslators(Map<String, String> requestData) throws Exception {
|
||||||
requestData.put("url", "https://openapi.youdao.com/api");
|
requestData.put("url", "https://openapi.youdao.com/api");
|
||||||
|
if (requestData.get("strict") == null || !requestData.get("strict").equals("true")) {
|
||||||
|
if ((requestData.get("lang").equals("zh-CHS") && requestData.get("to").equals("en")) || (requestData.get("lang").equals("en") && requestData.get("to").equals("zh-CHS"))) {
|
||||||
|
requestData.remove("to");
|
||||||
|
requestData.remove("lang");
|
||||||
|
}
|
||||||
|
}
|
||||||
JSONObject jsonObject = translatorsCommon(requestData);
|
JSONObject jsonObject = translatorsCommon(requestData);
|
||||||
// 获取translation数组
|
// 获取translation数组
|
||||||
JSONArray translationArray = jsonObject.getJSONArray("translation");
|
JSONArray translationArray = jsonObject.getJSONArray("translation");
|
||||||
@ -338,7 +344,9 @@ public class ChatService {
|
|||||||
//翻译
|
//翻译
|
||||||
Map<String, String[]> data = new HashMap<>();
|
Map<String, String[]> data = new HashMap<>();
|
||||||
data.put("q", new String[]{requestData.get("q")});
|
data.put("q", new String[]{requestData.get("q")});
|
||||||
data.put("from", new String[]{requestData.get("lang")});
|
if (requestData.get("lang") != null) {
|
||||||
|
data.put("from", new String[]{requestData.get("lang")});
|
||||||
|
}
|
||||||
if (requestData.get("to") != null) {
|
if (requestData.get("to") != null) {
|
||||||
data.put("to", new String[]{requestData.get("to")});
|
data.put("to", new String[]{requestData.get("to")});
|
||||||
}
|
}
|
||||||
|
@ -6,4 +6,5 @@ import lombok.Data;
|
|||||||
public class TtsRequest {
|
public class TtsRequest {
|
||||||
private String q;
|
private String q;
|
||||||
private String voiceName;
|
private String voiceName;
|
||||||
|
private String language;
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ public class YoudaoServiceServiceImpl implements YoudaoService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String tts(TtsRequest ttsRequest, HttpServletResponse response) throws IOException, NoSuchAlgorithmException {
|
public String tts(TtsRequest ttsRequest, HttpServletResponse response) throws IOException, NoSuchAlgorithmException {
|
||||||
ttsRequest.setVoiceName("youxiaomei");
|
ttsRequest.setVoiceName(getYInSe(ttsRequest.getLanguage()));
|
||||||
List<String> result = new ArrayList<>();
|
List<String> result = new ArrayList<>();
|
||||||
String appKey = sysConfigMapper.getcheckConfigKeyUnique("YOUDAO_APP_KEY");
|
String appKey = sysConfigMapper.getcheckConfigKeyUnique("YOUDAO_APP_KEY");
|
||||||
String appSecret = sysConfigMapper.getcheckConfigKeyUnique("YOUDAO_APP_SECRET");
|
String appSecret = sysConfigMapper.getcheckConfigKeyUnique("YOUDAO_APP_SECRET");
|
||||||
@ -78,5 +78,25 @@ public class YoudaoServiceServiceImpl implements YoudaoService {
|
|||||||
return "profile/upload/tts"+File.separator +tempPath +".mp3";
|
return "profile/upload/tts"+File.separator +tempPath +".mp3";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getYInSe(String lang) {
|
||||||
|
switch (lang) {
|
||||||
|
case "Japanese":
|
||||||
|
return "youkejiang";
|
||||||
|
case "Korean":
|
||||||
|
return "piaozhiyou";
|
||||||
|
case "Italian":
|
||||||
|
return "yixiaomei";
|
||||||
|
case "French":
|
||||||
|
return "faxiaomei";
|
||||||
|
case "Spanish":
|
||||||
|
return "xixiaomei";
|
||||||
|
case "German":
|
||||||
|
return "dexiaomei";
|
||||||
|
case "Russian":
|
||||||
|
return "exiaomei";
|
||||||
|
}
|
||||||
|
return "youxiaowei";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user