Commit 76df569d by 苗权威

9.7

parent 9109fa09
...@@ -2,6 +2,7 @@ package ai.qiwu.com.tts_offline.common; ...@@ -2,6 +2,7 @@ package ai.qiwu.com.tts_offline.common;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.util.DigestUtils; import org.springframework.util.DigestUtils;
import javax.sound.sampled.AudioFileFormat; import javax.sound.sampled.AudioFileFormat;
...@@ -15,6 +16,9 @@ import java.text.Normalizer; ...@@ -15,6 +16,9 @@ import java.text.Normalizer;
import java.util.Base64; import java.util.Base64;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.List; import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;
/** /**
* @author 苗权威 * @author 苗权威
...@@ -24,6 +28,33 @@ import java.util.List; ...@@ -24,6 +28,33 @@ import java.util.List;
public class TTSUtils { public class TTSUtils {
private static final String STRIP = " /'\""; private static final String STRIP = " /'\"";
public static boolean unZip(String folder, String filePath) {
try (ZipFile zipFile = new ZipFile(filePath)){
Enumeration<?> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = (ZipEntry) entries.nextElement();
if (entry.isDirectory()) {
String dirPath = new StringBuilder(folder).append(File.separator).append(entry.getName()).toString();
new File(dirPath).mkdirs();
}
else {
File targetFile = new File(new StringBuilder(folder).append(File.separator).append(entry.getName()).toString());
if (!targetFile.getParentFile().exists()) targetFile.getParentFile().mkdirs();
targetFile.createNewFile();
try (InputStream is = zipFile.getInputStream(entry);FileOutputStream fos = new FileOutputStream(targetFile)){
int len;
byte[] buf = new byte[1024];
while ((len=is.read(buf)) != -1) fos.write(buf, 0, len);
}
}
}
} catch (Exception e) {
log.error("unzip error:{}", ExceptionUtils.getStackTrace(e));
return false;
}
return true;
}
public static boolean deleteFile(File file) { public static boolean deleteFile(File file) {
if (!file.exists()) return false; if (!file.exists()) return false;
if (file.isDirectory()) { if (file.isDirectory()) {
......
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId> <artifactId>fastjson</artifactId>
<version>1.2.58</version> <version>1.2.60</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
...@@ -65,6 +65,11 @@ ...@@ -65,6 +65,11 @@
<artifactId>commons-lang3</artifactId> <artifactId>commons-lang3</artifactId>
<version>3.9</version> <version>3.9</version>
</dependency> </dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.baidu.aip/java-sdk --> <!-- https://mvnrepository.com/artifact/com.baidu.aip/java-sdk -->
<dependency> <dependency>
<groupId>com.baidu.aip</groupId> <groupId>com.baidu.aip</groupId>
......
...@@ -111,7 +111,12 @@ public class OkHttp3Utils { ...@@ -111,7 +111,12 @@ public class OkHttp3Utils {
builder.headers(headBuilder.build()).post(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), requestJsonStr)); builder.headers(headBuilder.build()).post(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), requestJsonStr));
try (Response response = client.newCall(builder.build()).execute()){ try (Response response = client.newCall(builder.build()).execute()){
return response.body().string(); return response.body().string();
}catch (SocketTimeoutException e) {
log.error("捕获到SocketTimeoutException:{}", e.toString());
client.dispatcher().cancelAll();
client.connectionPool().evictAll();
} }
return null;
} }
public static ResponseCodeWithData doPostTimeout(String url, Map<String, String> headers, public static ResponseCodeWithData doPostTimeout(String url, Map<String, String> headers,
...@@ -182,6 +187,31 @@ public class OkHttp3Utils { ...@@ -182,6 +187,31 @@ public class OkHttp3Utils {
} }
} }
public static Integer doPostReturnCode(String url, Map<String, String> headers, Map<String, String> params) throws IOException {
Request.Builder builder = new Request.Builder();
Request request = builder.url(url).build();
Headers.Builder headBuilder = request.headers().newBuilder();
Iterator<Map.Entry<String, String>> headIterator = headers.entrySet().iterator();
headIterator.forEachRemaining(e -> headBuilder.add(e.getKey(), e.getValue()));
MultipartBody.Builder requestBuilder = new MultipartBody.Builder();
Iterator<Map.Entry<String, String>> paramsIterator = params.entrySet().iterator();
paramsIterator.forEachRemaining(e -> requestBuilder.addFormDataPart(e.getKey(), e.getValue()));
builder.headers(headBuilder.build()).post(requestBuilder.build());
try (Response response = client.newCall(builder.build()).execute(); ResponseBody body = response.body()){
return response.code();
}catch (SocketTimeoutException e) {
log.error("捕获到SocketTimeoutException:{}", e.toString());
client.dispatcher().cancelAll();
client.connectionPool().evictAll();
}
return 555;
}
public static String doPost(String url, Map<String, String> headers, Map<String, String> params, public static String doPost(String url, Map<String, String> headers, Map<String, String> params,
String fileName, byte[] fileByte) throws IOException { String fileName, byte[] fileByte) throws IOException {
Request.Builder builder = new Request.Builder(); Request.Builder builder = new Request.Builder();
......
...@@ -3,6 +3,7 @@ package ai.qiwu.com.tts_service.common; ...@@ -3,6 +3,7 @@ package ai.qiwu.com.tts_service.common;
import ai.qiwu.com.tts_service.service.Initialize; import ai.qiwu.com.tts_service.service.Initialize;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.util.DigestUtils; import org.springframework.util.DigestUtils;
import javax.sound.sampled.AudioFileFormat; import javax.sound.sampled.AudioFileFormat;
...@@ -14,6 +15,8 @@ import java.nio.charset.Charset; ...@@ -14,6 +15,8 @@ import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.text.Normalizer; import java.text.Normalizer;
import java.util.*; import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
/** /**
* @author 苗权威 * @author 苗权威
...@@ -23,18 +26,123 @@ import java.util.*; ...@@ -23,18 +26,123 @@ import java.util.*;
public class TTSUtils { public class TTSUtils {
private static final String STRIP = " /'\""; private static final String STRIP = " /'\"";
public static boolean deleteFile(File file) { public static String charset(File file) {
if (!file.exists()) return false; String charset = "GB18030";
byte[] first3Bytes = new byte[3];
try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file))){
boolean checked = false;
bis.mark(100);
int read = bis.read(first3Bytes, 0, 3);
if (read == -1) return charset;
else if (first3Bytes[0] == (byte) 0xFF && first3Bytes[1] == (byte) 0xFE) {
charset = "UTF-16LE"; // 文件编码为 Unicode
checked = true;
} else if (first3Bytes[0] == (byte) 0xFE && first3Bytes[1] == (byte) 0xFF) {
charset = "UTF-16BE"; // 文件编码为 Unicode big endian
checked = true;
} else if (first3Bytes[0] == (byte) 0xEF && first3Bytes[1] == (byte) 0xBB
&& first3Bytes[2] == (byte) 0xBF) {
charset = "UTF-8"; // 文件编码为 UTF-8
checked = true;
}
bis.reset();
if (!checked) {
while ((read = bis.read()) != -1) {
if (read >= 0xF0)
break;
if (0x80 <= read && read <= 0xBF) // 单独出现BF以下的,也算是GBK
break;
if (0xC0 <= read && read <= 0xDF) {
read = bis.read();
if (0x80 <= read && read <= 0xBF) // 双字节 (0xC0 - 0xDF)
// (0x80 - 0xBF),也可能在GB编码内
continue;
else
break;
} else if (0xE0 <= read && read <= 0xEF) { // 也有可能出错,但是几率较小
read = bis.read();
if (0x80 <= read && read <= 0xBF) {
read = bis.read();
if (0x80 <= read && read <= 0xBF) {
charset = "UTF-8";
break;
} else
break;
} else
break;
}
}
}
} catch (IOException e) {
log.warn("判断字符集出错");
}
if (!"GB18030".equals(charset)) log.info("--文件-> [" + file.getAbsolutePath() + "] 采用的字符集为: [" + charset + "]");
return charset;
}
public static boolean checkZipFile(String zipFilePath) {
try (ZipFile zipFile = new ZipFile(zipFilePath,Charset.forName("GBK"))){
Enumeration<?> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = (ZipEntry) entries.nextElement();
if (entry.isDirectory()) return false;
}
} catch (Exception e) {
log.error("判断zip文件出错:{}", ExceptionUtils.getStackTrace(e));
return false;
}
return true;
}
public static boolean unZip(String toFolder, String zipFilePath) {
try (ZipFile zipFile = new ZipFile(zipFilePath,Charset.forName("GBK"))){
Enumeration<?> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = (ZipEntry) entries.nextElement();
if (entry.isDirectory()) {
String dirPath = new StringBuilder(toFolder).append(File.separator).append(entry.getName()).toString();
new File(dirPath).mkdirs();
}
else {
File targetFile = new File(new StringBuilder(toFolder).append(File.separator).append(entry.getName()).toString());
if (!targetFile.getParentFile().exists()) targetFile.getParentFile().mkdirs();
targetFile.createNewFile();
try (BufferedInputStream is = new BufferedInputStream(zipFile.getInputStream(entry));BufferedOutputStream fos = new BufferedOutputStream(new FileOutputStream(targetFile))){
int len;
byte[] buf = new byte[1024];
while ((len=is.read(buf)) != -1) fos.write(buf, 0, len);
}
}
}
} catch (Exception e) {
log.error("压缩包解压失败:{}", ExceptionUtils.getStackTrace(e));
return false;
}
return true;
}
public static void deleteFile(File file) {
if (!file.exists()) return;
if (file.isDirectory()) { if (file.isDirectory()) {
File[] files = file.listFiles(); File[] files = file.listFiles();
for (File f : files) deleteFile(f); if (files != null && files.length != 0) {
for (File f : files) {
deleteFile(f);
}
}
}
file.delete();
}
public static void deleteFile(File[] files) {
for (File file: files) {
deleteFile(file);
} }
return file.delete();
} }
public static boolean makedir(String path) { public static boolean makedir(String path) {
File file = new File(path); File file = new File(path);
boolean createDirResult = false; boolean createDirResult = true;
if (!file.exists() || file.isFile()) { if (!file.exists() || file.isFile()) {
createDirResult = file.mkdirs(); createDirResult = file.mkdirs();
} }
...@@ -112,6 +220,7 @@ public class TTSUtils { ...@@ -112,6 +220,7 @@ public class TTSUtils {
} }
public static boolean doesFileExist(String filePath) { public static boolean doesFileExist(String filePath) {
if (filePath == null) return false;
File file = new File(filePath); File file = new File(filePath);
if (file.exists()) { if (file.exists()) {
//log.info("文件:{},大小为:{}", filePath, file.length()); //log.info("文件:{},大小为:{}", filePath, file.length());
...@@ -283,11 +392,9 @@ public class TTSUtils { ...@@ -283,11 +392,9 @@ public class TTSUtils {
} }
public static void main(String[] args) { public static void main(String[] args) {
ArrayList<String> list = new ArrayList<>(); File deleteBotDir = new File("/home/yf01/springbootdemo");
list.add("sagwsahah"); File[] needDelete = deleteBotDir.listFiles((dir, name) -> !name.equals("record"));
list.add("sgahh"); System.out.println(needDelete.length);
list.add("wrte2323"); System.out.println(Arrays.toString(needDelete));
list.add("wrt67868e2323");
pythonlistToStr(list);
} }
} }
...@@ -27,7 +27,7 @@ public class TTServiceUtil { ...@@ -27,7 +27,7 @@ public class TTServiceUtil {
out.append(ttsResJsonStr); out.append(ttsResJsonStr);
out.flush(); out.flush();
} catch (Exception e) { } catch (Exception e) {
log.error("获取PrintWriter出错:{}",e.toString()); log.error("buildOnlineCacheResponse():获取PrintWriter出错:{}",e.toString());
} }
} }
...@@ -42,7 +42,7 @@ public class TTServiceUtil { ...@@ -42,7 +42,7 @@ public class TTServiceUtil {
out.append(ttsResJsonStr); out.append(ttsResJsonStr);
out.flush(); out.flush();
} catch (Exception e) { } catch (Exception e) {
log.error("获取PrintWriter出错:{}",e.toString()); log.error("buildMp3Response():获取PrintWriter出错:{}",e.toString());
} }
} else { } else {
try (BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(fileName)); try (BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(fileName));
...@@ -84,7 +84,7 @@ public class TTServiceUtil { ...@@ -84,7 +84,7 @@ public class TTServiceUtil {
out.append(ttsResJsonStr); out.append(ttsResJsonStr);
out.flush(); out.flush();
} catch (Exception e) { } catch (Exception e) {
log.error("获取PrintWriter出错:{}",e.toString()); log.error("buildTTS_lsResponse():获取PrintWriter出错:{}",e.toString());
} }
} }
...@@ -112,8 +112,22 @@ public class TTServiceUtil { ...@@ -112,8 +112,22 @@ public class TTServiceUtil {
out.append(ttsResJsonStr); out.append(ttsResJsonStr);
out.flush(); out.flush();
} catch (Exception e) { } catch (Exception e) {
log.error("获取PrintWriter出错:{}",e.toString()); log.error("buildServletResponse():获取PrintWriter出错:{}",e.toString());
} }
} }
} }
public static void buildUploadResponse(HttpServletResponse response, TTSResponse ttsResponse,
Integer status) {
response.setStatus(status);
String ttsResJsonStr = JSON.toJSONString(ttsResponse);
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json;charset=utf-8");
try (PrintWriter out = response.getWriter()){
out.append(ttsResJsonStr);
out.flush();
} catch (Exception e) {
log.error("buildUploadOneSenResponse():获取PrintWriter出错:{}",e.toString());
}
}
} }
package ai.qiwu.com.tts_service.controller; package ai.qiwu.com.tts_service.controller;
import ai.qiwu.com.tts_service.pojo.*; import ai.qiwu.com.tts_service.pojo.*;
import ai.qiwu.com.tts_service.pojo.upload.UploadOneSenData;
import ai.qiwu.com.tts_service.service.Initialize; import ai.qiwu.com.tts_service.service.Initialize;
import ai.qiwu.com.tts_service.service.TTService; import ai.qiwu.com.tts_service.service.TTService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
...@@ -44,7 +46,7 @@ public class TTSController { ...@@ -44,7 +46,7 @@ public class TTSController {
@RequestParam(required = false) String text, @RequestParam(required = false) String botname, @RequestParam(required = false) String text, @RequestParam(required = false) String botname,
@RequestParam(required = false) String _type, @RequestParam(required = false) String volume, @RequestParam(required = false) String _type, @RequestParam(required = false) String volume,
@RequestParam(required = false) String pitch, @RequestParam(required = false) String speed, @RequestParam(required = false) String pitch, @RequestParam(required = false) String speed,
@RequestParam(required = false) String get_online, HttpServletResponse servletResponse) { @RequestParam(required = false) Boolean get_online, HttpServletResponse servletResponse) {
TTSRequest ttsRequest = new TTSRequest(person, text, _type, pitch, tone, botname, volume, speed,get_online); TTSRequest ttsRequest = new TTSRequest(person, text, _type, pitch, tone, botname, volume, speed,get_online);
ttService.tts(ttsRequest, "GET", servletResponse); ttService.tts(ttsRequest, "GET", servletResponse);
} }
...@@ -72,10 +74,10 @@ public class TTSController { ...@@ -72,10 +74,10 @@ public class TTSController {
ttService.mp3(dirs, filename, _type, response); ttService.mp3(dirs, filename, _type, response);
} }
@PostMapping("/api/chatbot") // @PostMapping("/api/chatbot")
public ChatBotResponse chatbot(@RequestBody ChatBotRequest request) { // public ChatBotResponse chatbot(@RequestBody ChatBotRequest request) {
return ttService.chatbot(request); // return ttService.chatbot(request);
} // }
@PostMapping("/api/update_db_var") @PostMapping("/api/update_db_var")
public void updateCache(HttpServletResponse response) { public void updateCache(HttpServletResponse response) {
...@@ -86,4 +88,13 @@ public class TTSController { ...@@ -86,4 +88,13 @@ public class TTSController {
} }
response.setStatus(200); response.setStatus(200);
} }
@PostMapping("/api/upload/one_sen")
public void uploadOneSen(MultipartFile file, Integer tid, String botName, String npcName,
String text, HttpServletResponse response) {
UploadOneSenData data = new UploadOneSenData(tid, botName, npcName, text, file);
ttService.uploadOneSen(data, response);
}
} }
package ai.qiwu.com.tts_service.pojo; package ai.qiwu.com.tts_service.pojo;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.ToString; import lombok.ToString;
...@@ -11,6 +12,7 @@ import lombok.ToString; ...@@ -11,6 +12,7 @@ import lombok.ToString;
@Getter @Getter
@Setter @Setter
@ToString @ToString
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class GeneralMP3Data { public class GeneralMP3Data {
private String server; private String server;
private String text; private String text;
......
...@@ -22,10 +22,11 @@ public class TTSRequest { ...@@ -22,10 +22,11 @@ public class TTSRequest {
private String botname; private String botname;
private String volume; private String volume;
private String speed; private String speed;
private String get_online; private Boolean get_online;
private String npcName;
public TTSRequest(String person, String text, String _type, String pitch, public TTSRequest(String person, String text, String _type, String pitch,
String tone, String botname, String volume, String speed,String get_online) { String tone, String botname, String volume, String speed,Boolean get_online) {
this.person = person; this.person = person;
this.text = text; this.text = text;
this._type = _type; this._type = _type;
......
...@@ -23,4 +23,5 @@ public class TextInfo { ...@@ -23,4 +23,5 @@ public class TextInfo {
private Boolean cache; private Boolean cache;
private String server; private String server;
private String botname; private String botname;
private String npcName;
} }
package ai.qiwu.com.tts_service.pojo.upload;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Getter;
import lombok.Setter;
/**
* @author 苗权威
* @dateTime 19-9-7 下午4:48
*/
@Getter
@Setter
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class RecordCallbackData {
private Integer tid;
}
package ai.qiwu.com.tts_service.pojo.upload;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
import org.springframework.web.multipart.MultipartFile;
/**
* @author 苗权威
* @dateTime 19-9-7 下午4:03
*/
@Getter
@Setter
@JsonIgnoreProperties(ignoreUnknown = true)
public class UploadOneSenData {
private Integer tid;
private String botName;
private String npcName;
private String text;
private MultipartFile file;
public UploadOneSenData() {
}
public UploadOneSenData(Integer tid, String botName, String npcName, String text, MultipartFile file) {
this.tid = tid;
this.botName = botName;
this.npcName = npcName;
this.text = text;
this.file = file;
}
public UploadOneSenData(String botName, String npcName, MultipartFile file) {
this.botName = botName;
this.npcName = npcName;
this.file = file;
}
}
...@@ -23,15 +23,17 @@ import java.util.*; ...@@ -23,15 +23,17 @@ import java.util.*;
public class Initialize implements InitializingBean { public class Initialize implements InitializingBean {
private static String init_person = "B05"; private static String init_person = "B05";
private String init_tone = "正常"; private String init_tone = "正常";
private String init_url; private String init_url; // 一定是线上url
private static final List<String> URL_LS; private static final List<String> URL_LS; //线上地址列表
private static final Map<String, PersonInfo> PERSON_INFO_ONLINE; //speakers_online private static final Map<String, PersonInfo> PERSON_INFO_ONLINE; //speakers_online
private static final Map<String, PersonInfo> PERSON_INFO_OFFLINE; //speakers_offline private static final Map<String, PersonInfo> PERSON_INFO_OFFLINE; //speakers_offline
private static final Map<String, Map<String, String>> PERSON_MOODURL; //api private static final Map<String, Map<String, String>> PERSON_MOODURL; //api
private static final Map<String, Map<String, String>> OFFLINE_2_ONLINE; private static final Map<String, Map<String, Integer>> OFFLINE_2_ONLINE;
private static final List<String> THIRD_PARTY_TTS; private static final List<String> THIRD_PARTY_TTS;
private static final Map<String, String> THIRD_PARTY_WITH_ITS_PER = new HashMap<>(); private static final Map<String, String> THIRD_PARTY_WITH_ITS_PER;
private static final Map<Integer, String> ONLINE_ID_2_URL;
private static final Map<String, List<String>> URL_2_PERSON_TON;
private static final String SERVER_NAME; private static final String SERVER_NAME;
private static final String SERVER_URL; private static final String SERVER_URL;
...@@ -40,19 +42,28 @@ public class Initialize implements InitializingBean { ...@@ -40,19 +42,28 @@ public class Initialize implements InitializingBean {
private static final String OFFLINE_SERVER; private static final String OFFLINE_SERVER;
private static final String THIRD_PARTY; private static final String THIRD_PARTY;
private static final String CHANGE_SOUND; private static final String CHANGE_SOUND;
private static final String UPLOADED_DIR;
private static final String delCacheCallbackUrl;
private static final String record_callback_url;
private final SpeakerInfoRepository speakerInfoRepository; private final SpeakerInfoRepository speakerInfoRepository;
static { static {
URL_LS = new ArrayList<>(); URL_LS = new ArrayList<>();
THIRD_PARTY_TTS = new ArrayList<>(); THIRD_PARTY_TTS = new ArrayList<>();
ONLINE_ID_2_URL = new HashMap<>();
URL_2_PERSON_TON = new HashMap<>();
PERSON_INFO_ONLINE = new HashMap<>(); PERSON_INFO_ONLINE = new HashMap<>();
PERSON_INFO_OFFLINE = new HashMap<>(); PERSON_INFO_OFFLINE = new HashMap<>();
PERSON_MOODURL = new HashMap<>(); PERSON_MOODURL = new HashMap<>();
OFFLINE_2_ONLINE = new HashMap<>(); OFFLINE_2_ONLINE = new HashMap<>();
THIRD_PARTY_WITH_ITS_PER = new HashMap<>();
SERVER_NAME = Config.getProperty("server_name"); SERVER_NAME = Config.getProperty("server_name");
SERVER_URL = Config.getProperty("server_url"); SERVER_URL = Config.getProperty("server_url");
AUDIO_DIR = Config.getProperty("audio_dir"); AUDIO_DIR = Config.getProperty("audio_dir");
UPLOADED_DIR = Config.getProperty("record_dir");
delCacheCallbackUrl = Config.getProperty("del_cache_callback_url");
record_callback_url = Config.getProperty("record_callback_url");
String[] online_sever_list = Config.getProperty("online_sever").split(","); String[] online_sever_list = Config.getProperty("online_sever").split(",");
for (String serverAdd: online_sever_list) { for (String serverAdd: online_sever_list) {
...@@ -106,6 +117,9 @@ public class Initialize implements InitializingBean { ...@@ -106,6 +117,9 @@ public class Initialize implements InitializingBean {
init_person = person; init_person = person;
} }
ONLINE_ID_2_URL.put(speakerInfo.getId(), url);
URL_2_PERSON_TON.put(url, Arrays.asList(person,mood));
PersonInfo personInfo_online = PERSON_INFO_ONLINE.computeIfAbsent(person, k -> new PersonInfo(name, sex)); PersonInfo personInfo_online = PERSON_INFO_ONLINE.computeIfAbsent(person, k -> new PersonInfo(name, sex));
personInfo_online.getMood().add(mood); personInfo_online.getMood().add(mood);
...@@ -117,8 +131,8 @@ public class Initialize implements InitializingBean { ...@@ -117,8 +131,8 @@ public class Initialize implements InitializingBean {
personInfo_offline.getMood().add(mood); personInfo_offline.getMood().add(mood);
if (jump != null && !jump.equals(speakerInfo.getId())) { if (jump != null && !jump.equals(speakerInfo.getId())) {
Map<String, String> mood2jumpUrl = OFFLINE_2_ONLINE.computeIfAbsent(person_offline, k -> new HashMap<>()); Map<String, Integer> mood2jumpUrl = OFFLINE_2_ONLINE.computeIfAbsent(person_offline, k -> new HashMap<>());
mood2jumpUrl.put(mood, String.format("%s:9%03d/synthesize", ONLINE_SERVER, jump)); mood2jumpUrl.put(mood, jump);
} }
Map<String, String> mood_url = PERSON_MOODURL.computeIfAbsent(person_offline, k -> new HashMap<>()); Map<String, String> mood_url = PERSON_MOODURL.computeIfAbsent(person_offline, k -> new HashMap<>());
...@@ -132,6 +146,7 @@ public class Initialize implements InitializingBean { ...@@ -132,6 +146,7 @@ public class Initialize implements InitializingBean {
initialize(speakerInfo); initialize(speakerInfo);
} }
//CallPython.getPythonInterpreter(); //CallPython.getPythonInterpreter();
//
if (!PERSON_INFO_ONLINE.containsKey(init_person)) { if (!PERSON_INFO_ONLINE.containsKey(init_person)) {
for (String person : PERSON_INFO_ONLINE.keySet()) { for (String person : PERSON_INFO_ONLINE.keySet()) {
if (!THIRD_PARTY_TTS.contains(person)) { if (!THIRD_PARTY_TTS.contains(person)) {
...@@ -180,7 +195,7 @@ public class Initialize implements InitializingBean { ...@@ -180,7 +195,7 @@ public class Initialize implements InitializingBean {
return init_tone; return init_tone;
} }
Map<String, String> getThePersonJumpUrls(String person) { Map<String, Integer> getThePersonJumpId(String person) {
return OFFLINE_2_ONLINE.get(person); return OFFLINE_2_ONLINE.get(person);
} }
...@@ -192,7 +207,7 @@ public class Initialize implements InitializingBean { ...@@ -192,7 +207,7 @@ public class Initialize implements InitializingBean {
return init_url; return init_url;
} }
public static List<String> getThirdPartyTts() { static List<String> getThirdPartyTts() {
return THIRD_PARTY_TTS; return THIRD_PARTY_TTS;
} }
...@@ -204,10 +219,20 @@ public class Initialize implements InitializingBean { ...@@ -204,10 +219,20 @@ public class Initialize implements InitializingBean {
return SERVER_URL; return SERVER_URL;
} }
public static String getAudioDir() { static String getAudioDir() {
return AUDIO_DIR; return AUDIO_DIR;
} }
static String getUploadedDir() {return UPLOADED_DIR;}
static String getRecord_callback_url() {
return record_callback_url;
}
public static String getDelCacheCallbackUrl() {
return delCacheCallbackUrl;
}
private static String getOnlineServer(int withOnline) { private static String getOnlineServer(int withOnline) {
return ONLINE_SERVER.get(withOnline); return ONLINE_SERVER.get(withOnline);
} }
...@@ -224,7 +249,15 @@ public class Initialize implements InitializingBean { ...@@ -224,7 +249,15 @@ public class Initialize implements InitializingBean {
return CHANGE_SOUND; return CHANGE_SOUND;
} }
public static String theThirdPartysPer(String person) { static String theThirdPartysPer(String person) {
return THIRD_PARTY_WITH_ITS_PER.get(person); return THIRD_PARTY_WITH_ITS_PER.get(person);
} }
static Map<Integer, String> getOnlineId2Url() {
return ONLINE_ID_2_URL;
}
static List<String> getUrl2PersonTon(String url) {
return URL_2_PERSON_TON.get(url);
}
} }
package ai.qiwu.com.tts_service.service;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
/**
* @author 苗权威
* @dateTime 19-9-7 下午6:35
*/
@Component("multipartResolver")
public class MultipartResolver extends CommonsMultipartResolver {
@Override
public void setDefaultEncoding(String defaultEncoding) {
super.setDefaultEncoding("UTF-8");
}
@Override
public void setMaxUploadSizePerFile(long maxUploadSizePerFile) {
super.setMaxUploadSizePerFile(524288000);
}
}
...@@ -23,7 +23,7 @@ public class ThirdPartyService { ...@@ -23,7 +23,7 @@ public class ThirdPartyService {
private static final AipSpeech CLIENT = new AipSpeech(BAI_DU.APP_ID, BAI_DU.API_KEY, BAI_DU.SECRET_KEY); private static final AipSpeech CLIENT = new AipSpeech(BAI_DU.APP_ID, BAI_DU.API_KEY, BAI_DU.SECRET_KEY);
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 = person.substring(0, 5); person = getThirdPartyName(person);
if ("Baidu".equals(person)) { if ("Baidu".equals(person)) {
return synthesis(text, Integer.parseInt(per), filepath); return synthesis(text, Integer.parseInt(per), filepath);
}else if ("Liehu".equals(person)) { }else if ("Liehu".equals(person)) {
...@@ -34,6 +34,12 @@ public class ThirdPartyService { ...@@ -34,6 +34,12 @@ public class ThirdPartyService {
return false; return false;
} }
private static String getThirdPartyName(String person) {
int i = person.length()-1;
while (Character.isDigit(person.charAt(i))) --i;
return person.substring(0,i+1);
}
public static boolean synthesis(String text, int per, String filepath) { public static boolean synthesis(String text, int per, String filepath) {
HashMap<String, Object> options = new HashMap<>(); HashMap<String, Object> options = new HashMap<>();
// options.put("spd", correctSoundParams(speed, false)); // options.put("spd", correctSoundParams(speed, false));
......
...@@ -3,6 +3,7 @@ server_name=aws-nx2 ...@@ -3,6 +3,7 @@ server_name=aws-nx2
server_url=http://aws-nx2.chewrobot.com:9663 server_url=http://aws-nx2.chewrobot.com:9663
#server_url=http://aliyun-hz1.chewrobot.com:9663 #server_url=http://aliyun-hz1.chewrobot.com:9663
audio_dir=/root/TTS-service/audio audio_dir=/root/TTS-service/audio
record_dir=record
#audio_dir=/root/GameEditor/mqw/project/tts/audio #audio_dir=/root/GameEditor/mqw/project/tts/audio
online_sever=1:http://dev01.centaurstech.com,2:http://dev01.centaurstech.com online_sever=1:http://dev01.centaurstech.com,2:http://dev01.centaurstech.com
offline_server=http://dev01.centaurstech.com:9001 offline_server=http://dev01.centaurstech.com:9001
...@@ -12,4 +13,6 @@ third_party_tts_text =third_party_tts ...@@ -12,4 +13,6 @@ third_party_tts_text =third_party_tts
python_interpreter=/usr/bin/python3 python_interpreter=/usr/bin/python3
change_sound_path=/root/GameEditor/mqw/project/tts/pythonCode/audios.py change_sound_path=/root/GameEditor/mqw/project/tts/pythonCode/audios.py
\ No newline at end of file del_cache_callback_url=http://localhost:18082/text/offline/delCache/callback
record_callback_url=http://localhost:18082/text/offline/upload/callback
\ No newline at end of file
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId> <artifactId>fastjson</artifactId>
<version>1.2.58</version> <version>1.2.60</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok --> <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency> <dependency>
......
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId> <artifactId>fastjson</artifactId>
<version>1.2.58</version> <version>1.2.60</version>
</dependency> </dependency>
</dependencies> </dependencies>
......
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