From 7542ddafd2b1502576904807f151f166fc2d7d17 Mon Sep 17 00:00:00 2001
From: 苗权威 <1160292058@qq.com>
Date: Tue, 11 Aug 2020 21:11:19 +0800
Subject: [PATCH] 8.11
---
.idea/inspectionProfiles/Project_Default.xml | 32 ++++++++++++++++++++++++++++++++
.idea/inspectionProfiles/profiles_settings.xml | 13 +++++++++++++
.idea/workspace.xml | 540 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
tts_service/src/main/java/ai/qiwu/com/tts_service/common/ApachHttpUtils.java | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------
tts_service/src/main/java/ai/qiwu/com/tts_service/common/TTSUtils.java | 26 ++++++++++++--------------
tts_service/src/main/java/ai/qiwu/com/tts_service/controller/DeployController.java | 266 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------
tts_service/src/main/java/ai/qiwu/com/tts_service/pojo/deploy/MoveBotAudio.java | 15 +++++++++++++++
tts_service/src/main/java/ai/qiwu/com/tts_service/pojo/deploy/Result.java | 32 ++++++++++++++++++++++++++++++++
tts_service/src/main/java/ai/qiwu/com/tts_service/service/Initialize.java | 4 ++--
tts_service/src/main/java/ai/qiwu/com/tts_service/service/TTService.java | 2 +-
tts_service/src/main/java/ai/qiwu/com/tts_service/service/TTServiceEdition2.java | 39 ++++++++++++++++++++-------------------
11 files changed, 716 insertions(+), 342 deletions(-)
create mode 100644 .idea/inspectionProfiles/profiles_settings.xml
create mode 100644 tts_service/src/main/java/ai/qiwu/com/tts_service/pojo/deploy/MoveBotAudio.java
create mode 100644 tts_service/src/main/java/ai/qiwu/com/tts_service/pojo/deploy/Result.java
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
index e9844ba..fe7865c 100755
--- a/.idea/inspectionProfiles/Project_Default.xml
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -1,6 +1,38 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml
new file mode 100644
index 0000000..2885a19
--- /dev/null
+++ b/.idea/inspectionProfiles/profiles_settings.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 11331ed..cd0e773 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -5,25 +5,14 @@
+
-
-
-
-
-
-
-
-
-
-
-
-
@@ -61,114 +50,106 @@
-
+
-
-
+
+
-
+
-
+
-
-
-
-
-
+
+
-
+
-
-
+
+
+
+
+
-
+
-
-
+
+
-
-
+
-
+
-
-
+
+
-
+
-
-
-
-
-
+
+
-
-
+
+
-
-
-
-
-
-
-
-
+
+
-
+
-
-
-
-
-
-
+
+
-
+
-
-
+
+
+
+
+
-
-
+
+
-
-
+
+
+
+
+
@@ -185,15 +166,6 @@
- task
- dealWithEndRequest
- path
- changeAudioUrlTemp
- token
- onclick
- mark file create fail
- i
- recordFolder
notVariableTextPath
THIRD_PARTY_TTS
usDir
@@ -202,7 +174,6 @@
variablePathInUsDir
text
tts_ls
- genRecordWithChange
23
SERVER_URL
BASE_HOST_URL
@@ -211,14 +182,24 @@
GAME_EDITOR_HOST
requestTerminate
offlineStr
- response
CHANGE_SOUND
filepath
POOL
+ generalMP3
+ App.LOGGER
+ auth
+ response
+ type
+ params
+ asyncDelete
+ checkZipFile
+ referenceName
+ genRecordWithChange
+ zipDir
- log
!CollectionUtils.isEmpty
+ log
@@ -227,9 +208,6 @@
-
-
-
@@ -269,15 +247,18 @@
-
-
+
+
+
+
+
+
-
-
+
@@ -309,8 +290,8 @@
-
-
+
+
@@ -332,25 +313,25 @@
-
+
-
+
-
+
-
+
@@ -358,40 +339,41 @@
-
+
-
+
-
+
-
-
+
+
-
+
-
+
-
+
+
@@ -408,7 +390,7 @@
-
+
@@ -422,12 +404,12 @@
-
-
-
+
+
+
-
+
@@ -435,12 +417,12 @@
-
-
-
+
+
+
-
+
@@ -518,27 +500,30 @@
-
-
+
+
-
+
+
+
-
-
+
+
+
@@ -701,29 +686,42 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
+
-
+
-
+
@@ -734,7 +732,7 @@
-
+
@@ -746,10 +744,12 @@
-
+
+
+
@@ -796,102 +796,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -899,13 +803,6 @@
-
-
-
-
-
-
-
@@ -999,13 +896,6 @@
-
-
-
-
-
-
-
@@ -1077,17 +967,38 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
+
-
-
+
+
@@ -1098,92 +1009,179 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
-
-
-
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
-
+
-
-
+
+
-
+
+
+
+
+
+
+
+
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
+
-
-
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
+
diff --git a/tts_service/src/main/java/ai/qiwu/com/tts_service/common/ApachHttpUtils.java b/tts_service/src/main/java/ai/qiwu/com/tts_service/common/ApachHttpUtils.java
index 7a8ba99..e1179e8 100644
--- a/tts_service/src/main/java/ai/qiwu/com/tts_service/common/ApachHttpUtils.java
+++ b/tts_service/src/main/java/ai/qiwu/com/tts_service/common/ApachHttpUtils.java
@@ -80,38 +80,39 @@ public class ApachHttpUtils {
connManager.setMaxTotal(1000);//最大连接数设置
connManager.setDefaultMaxPerRoute(800);//per route最大连接数设置
-// ConnectionKeepAliveStrategy myStrategy = (response, context) -> {
-// HeaderElementIterator it = new BasicHeaderElementIterator(
-// response.headerIterator(HTTP.CONN_KEEP_ALIVE));
-// while (it.hasNext()) {
-// HeaderElement he = it.nextElement();
+ ConnectionKeepAliveStrategy myStrategy = (response, context) -> {
+ HeaderElementIterator it = new BasicHeaderElementIterator(
+ response.headerIterator(HTTP.CONN_KEEP_ALIVE));
+ while (it.hasNext()) {
+ HeaderElement he = it.nextElement();
+ String param = he.getName();
+ String value = he.getValue();
+// log.info("CONN_KEEP_ALIVE:{}:{}",param,value);
+ if ("timeout".equalsIgnoreCase(param)) {
+ try {
+ return Long.parseLong(value) * 1000;
+ } catch(NumberFormatException ignore) {
+ }
+ break;
+ }
+ }
+
+// HeaderElementIterator connectionClose = new BasicHeaderElementIterator(
+// response.headerIterator(HTTP.CONN_DIRECTIVE));
+// while (connectionClose.hasNext()) {
+// HeaderElement he = connectionClose.nextElement();
// String param = he.getName();
// String value = he.getValue();
-// log.info("CONN_KEEP_ALIVE:{}:{}",param,value);
-// if (value != null && param.equalsIgnoreCase("timeout")) {
-// try {
-// return Long.parseLong(value) * 1000;
-// } catch(NumberFormatException ignore) {
-// }
-// }
+// log.info("CONN_DIRECTIVE:{}:{}",param,value);
// }
-//
-//// HeaderElementIterator connectionClose = new BasicHeaderElementIterator(
-//// response.headerIterator(HTTP.CONN_DIRECTIVE));
-//// while (connectionClose.hasNext()) {
-//// HeaderElement he = connectionClose.nextElement();
-//// String param = he.getName();
-//// String value = he.getValue();
-//// log.info("CONN_DIRECTIVE:{}:{}",param,value);
-//// }
-// return 1;
-// };
+ return 0;
+ };
httpClient = HttpClients.custom()
.setConnectionManager(connManager)
.setRetryHandler(new CustomRetry())
.setDefaultRequestConfig(requestConfig)
- .setKeepAliveStrategy(new DefaultConnectionKeepAliveStrategy())
+ .setKeepAliveStrategy(myStrategy)
.evictIdleConnections(5, TimeUnit.SECONDS)
.build();
@@ -526,6 +527,46 @@ public class ApachHttpUtils {
return null;
}
+ public static String delete(String url, Map headers, Map params) {
+ try {
+ URIBuilder builder = new URIBuilder(url, StandardCharsets.UTF_8);
+ if (!CollectionUtils.isEmpty(params)) {
+ List list = new ArrayList<>();
+ BasicNameValuePair param;
+ for (Map.Entry entry: params.entrySet()) {
+ param = new BasicNameValuePair(entry.getKey(), entry.getValue());
+ list.add(param);
+ }
+ builder.setParameters(list);
+ }
+ HttpDelete httpDelete = new HttpDelete(builder.build());
+ if (!CollectionUtils.isEmpty(headers)) {
+ for (Map.Entry entry:headers.entrySet()) {
+ httpDelete.setHeader(entry.getKey(), entry.getValue());
+ }
+ }
+ RequestConfig requestConfig = RequestConfig.custom()
+ .setConnectionRequestTimeout(3000)
+ .setSocketTimeout(20000)
+ .setConnectTimeout(10000).build();
+ httpDelete.setConfig(requestConfig);
+ try (CloseableHttpResponse response = getHttpClient().execute(httpDelete)){
+ int status = response.getStatusLine().getStatusCode();//获取返回状态值
+ if (status == 200) {
+ HttpEntity httpEntity = response.getEntity();
+ if(httpEntity != null){
+ String result = EntityUtils.toString(httpEntity, "UTF-8");
+ EntityUtils.consume(httpEntity);//关闭资源
+ return result;
+ }
+ }
+ }
+ } catch (Exception e) {
+ log.error(ExceptionUtils.getStackTrace(e));
+ }
+ return null;
+ }
+
public static String requestByPostParts(Map map, String url, Charset charset, Map headers) {
try {
HttpPost post = new HttpPost(url);
diff --git a/tts_service/src/main/java/ai/qiwu/com/tts_service/common/TTSUtils.java b/tts_service/src/main/java/ai/qiwu/com/tts_service/common/TTSUtils.java
index 5664dce..b726f24 100755
--- a/tts_service/src/main/java/ai/qiwu/com/tts_service/common/TTSUtils.java
+++ b/tts_service/src/main/java/ai/qiwu/com/tts_service/common/TTSUtils.java
@@ -693,19 +693,17 @@ public class TTSUtils {
}
public static void main(String[] args) throws IOException, UnsupportedAudioFileException {
-// UploadCallbackUnzip("/home/yf01/下载/tts/testzip","/home/yf01/下载/testUnzip.zip");
-// Files.copy(Paths.get("/home/yf01/下载/d46f2708a6a79f5bcc4623b1030b8aca.mp3"), Paths.get("/home/yf01/下载/d46Test.mp3"));
-// System.out.println(buildMP3Filename("你是八星团的杜磊吧!我等你很久了,我叫周笑笑"));
-// System.out.println(buildMP3Filename("先进来坐坐吧"));
-// System.out.println(buildMP3Filename(" 先进来坐坐吧"));
-// System.out.println(buildMP3Filename("周笑笑把门打开,露出了女性特有的粉色公主房,坐在软绵绵的坐垫上,12岁的小女孩有点手足无措"));
-// System.out.println(buildMP3Filename("你要喝些什么吗?我这里有果汁和可乐"));
-
- List list = new ArrayList<>();
- list.add("12345");
- list.add("abcdg");
- list.add("w35252");
- System.out.println(Arrays.toString(list.toArray()));
-// System.out.println(pythonlistToStr(list));
+// List filePathList = new ArrayList<>();
+// filePathList.add("/home/yf01/下载/audioConcate/1.wav");
+// filePathList.add("/home/yf01/下载/audioConcate/2.wav");
+// List str = filePathList.stream().map(s -> "-i "+s).collect(Collectors.toList());
+// StringBuilder builder = new StringBuilder("ffmpeg ").append(StringUtils.join(str, " ")).append(" -filter_complex ");
+// for (int i = 0; i < filePathList.size(); i++) {
+// builder.append("[").append(i).append(":a:0]");
+// }
+// builder.append("concat=n=").append(filePathList.size()).append(":v=0:a=1[a] -map [a] ").append("/home/yf01/下载/audioConcate/result.wav");
+// System.out.println(builder.toString());
+// System.out.println(buildMP3Filename("苹果"));
+// System.out.println(buildMP3Filename("没有了哦,换其他的水果"));
}
}
diff --git a/tts_service/src/main/java/ai/qiwu/com/tts_service/controller/DeployController.java b/tts_service/src/main/java/ai/qiwu/com/tts_service/controller/DeployController.java
index 64d9ba6..05de4de 100644
--- a/tts_service/src/main/java/ai/qiwu/com/tts_service/controller/DeployController.java
+++ b/tts_service/src/main/java/ai/qiwu/com/tts_service/controller/DeployController.java
@@ -2,30 +2,35 @@ package ai.qiwu.com.tts_service.controller;
import ai.qiwu.com.tts_service.common.ApachHttpUtils;
import ai.qiwu.com.tts_service.common.FileUtil;
+import ai.qiwu.com.tts_service.common.TTSUtils;
+import ai.qiwu.com.tts_service.pojo.deploy.MoveBotAudio;
+import ai.qiwu.com.tts_service.pojo.deploy.Result;
import ai.qiwu.com.tts_service.service.Initialize;
import ai.qiwu.com.tts_service.service.TTService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
+import org.apache.catalina.connector.ClientAbortException;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.redis.core.StringRedisTemplate;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestHeader;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
+import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
+import java.nio.channels.WritableByteChannel;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
-import java.util.HashMap;
-import java.util.Map;
+import java.nio.file.StandardCopyOption;
+import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Semaphore;
+import java.util.stream.Collectors;
/**
* painter
@@ -39,7 +44,8 @@ public class DeployController {
@GetMapping("/syn/download")
public String synSysImgTargetServerDownInThread(Long length, String path, String sourceServer,String zipDir,
- String targetDir, String type, @RequestHeader("Authorization") String auth) {
+ String targetDir, String type, @RequestParam(required = false) String gameServer,
+ @RequestHeader("Authorization") String auth) {
if (StringUtils.startsWith(zipDir, ".")) {
log.warn("zipDir start with .");
return "failure";
@@ -60,13 +66,13 @@ public class DeployController {
return "failure";
}
TTService.POOL.submit(() -> synSysImgTargetServerDown(length, path, sourceServer, zipDir,
- targetDir, auth, botAccount,type));
+ targetDir, auth, botAccount,type, gameServer));
return "success";
}
private void synSysImgTargetServerDown(Long length, String path, String sourceServer,String zipDir,String targetDir,
- String auth, String botAccount, String type) {
- log.info("/upload/syn/download 开始:"+path);
+ String auth, String botAccount, String type, String gameServer) {
+ log.warn("/upload/syn/download 开始:"+path);
long startTime = System.currentTimeMillis();
int sliceSize = 6*1024*1024;
long start = 0, end = sliceSize-1;
@@ -116,6 +122,7 @@ public class DeployController {
log.error("180s仍未获取到响应信息");
deleteSlice(zipDir, prefix, botAccount);
params.put("result", "failure");
+ params.put("gameServer", gameServer);
ApachHttpUtils.asyncDelete(sourceServer, params, headers);
return;
}
@@ -134,6 +141,7 @@ public class DeployController {
} while (!success && count < 10);
if (!success) {
params.put("result", "failure");
+ params.put("gameServer", gameServer);
ApachHttpUtils.asyncDelete(sourceServer, params, headers);
return;
}
@@ -148,10 +156,12 @@ public class DeployController {
FileUtil.decompress(tempSliceName+".zip", targetDir);
deleteSlice(zipDir, prefix, botAccount);
params.put("result", "success");
+ params.put("gameServer", gameServer);
ApachHttpUtils.asyncDelete(sourceServer, params, headers);
} catch (IOException e) {
deleteSlice(zipDir, prefix, botAccount);
params.put("result", "failure");
+ params.put("gameServer", gameServer);
ApachHttpUtils.asyncDelete(sourceServer, params, headers);
log.error("分段下载出错:"+e);
}
@@ -174,4 +184,238 @@ public class DeployController {
log.error("分片文件删除出错ss:{},prefix:{},botAccount:{}",e, prefix, botAccount);
}
}
+
+ /**
+ *
+ * @param path 被压缩文件路径
+ * @param sourceDir 压缩包文件目录
+ * @param targetName 压缩包名
+ * @param targetServer 下载服务器地址
+ * @param zipDir 下载服务器存放分片数据及合成后的压缩包的目录
+ * @param targetDir 下载服务器解压目录
+ * @return
+ */
+ @GetMapping("/syn")
+ public String synSysFile(String path, String sourceDir, String targetName, String targetServer,String zipDir,
+ String targetDir, String type, String gameServer, @RequestHeader("Authorization") String auth) {
+ // 将文件压缩好,将大小,路径发给目标服务器
+ try {
+ String zipPath;
+ Path pt = Paths.get((zipPath=sourceDir+File.separator+targetName+".zip"));
+ boolean zipFileExist = true;
+ synchronized (DeployController.class) {
+ if (!Files.exists(pt)) {
+ log.info("开始压缩:"+targetName+","+targetServer);
+ zipFileExist = FileUtil.compress(path, sourceDir, targetName) != null;
+ }
+ }
+ if (zipFileExist) {
+ Map headers = new HashMap<>();
+ headers.put("Authorization", auth);
+ Map params = new HashMap<>();
+ params.put("length", String.valueOf(Files.size(pt)));
+ params.put("path", zipPath);
+ params.put("sourceServer", Initialize.SERVER_URL);
+ params.put("gameServer", gameServer);
+ params.put("zipDir", zipDir);
+ params.put("targetDir", targetDir);
+ params.put("type", type);
+ return ApachHttpUtils.get(targetServer+"/upload/syn/download", headers, params);
+ }
+ } catch (IOException e) {
+ log.error("synSysFile:"+e);
+ }
+ return "fail";
+ }
+
+ @DeleteMapping("/range/download")
+ public Result delete(String path, String pass, String serverName, String gameServer,@RequestParam(required = false) String result,
+ @RequestHeader("Authorization") String auth) {
+ if (StringUtils.isNotBlank(pass) && StringUtils.startsWith(pass,"mqw") && pass.length() == 6) {
+ try {
+ Path pt = Paths.get(path);
+ if (Files.exists(pt)) {
+ Map headers = new HashMap<>();
+ headers.put("Authorization", auth);
+ Map params = new HashMap<>();
+ params.put("path", path);
+ params.put("pass", pass);
+ params.put("serverName", serverName);
+ params.put("result", result);
+ if (StringUtils.startsWith(path, "/var/www/html/Editor/upload/img/zip")) {
+ String deleteResponse = ApachHttpUtils.delete(gameServer+"/upload/range/download/tts", headers, params);
+ if (!"success".equals(deleteResponse)) {
+ log.error("图片同步出现同时同步到多个服务器的情况");
+ } else {
+ Files.list(pt.getParent()).forEach(path1 -> {
+ try {
+ Files.deleteIfExists(path1);
+ } catch (IOException e) {
+ log.error("删除图片服务器同步目录下的文件出错:"+e);
+ }
+ });
+ }
+ } else {
+ String deleteResponse = ApachHttpUtils.delete(gameServer+"/upload/range/download/tts", headers, params);
+ String botAccount = path.substring(path.lastIndexOf(File.separator)+1, path.lastIndexOf("."));
+ if (!"success".equals(deleteResponse)) {
+ log.error("音频/图片同步出现同时同步到多个服务器的情况:"+botAccount);
+ } else {
+ Files.list(pt.getParent()).filter(path1 -> {
+ String str = path1.getFileName().toString();
+ return StringUtils.startsWith(str, botAccount);
+ }).forEach(path1 -> {
+ try {
+ if (Files.isDirectory(path1)) {
+ FileUtil.deleteFile(path1.toAbsolutePath().toFile());
+ } else {
+ Files.deleteIfExists(path1);
+ }
+ } catch (IOException e) {
+ log.error("删除音频/图片同步目录下的文件出错:"+e+","+path1);
+ }
+ });
+ }
+ }
+ } else {
+ log.error("删除同步目录下的文件不存在:"+path);
+ }
+ } catch (Exception e) {
+ log.error("异步删除压缩包出错:"+e);
+ }
+ }
+ return Result.success();
+ }
+
+ @GetMapping("/range/download")
+ public void downloadSliceFile(String path, HttpServletRequest request, HttpServletResponse response) {
+ File downloadFile = new File(path);
+ long fileLength = downloadFile.length();// 记录文件大小
+ long pastLength = 0;// 记录已下载文件大小
+ int rangeSwitch = 0;// 0:从头开始的全文下载;1:从某字节开始的下载(bytes=27000-);2:从某字节开始到某字节结束的下载(bytes=27000-39000)
+ long toLength;// 记录客户端需要下载的字节段的最后一个字节偏移量(比如bytes=27000-39000,则这个值是为39000)
+ long contentLength;// 客户端请求的字节总量
+ String rangeBytes;// 记录客户端传来的形如“bytes=27000-”或者“bytes=27000-39000”的内容
+// int bsize = 1024;// 缓冲区大小
+// byte[] b = new byte[bsize];// 暂存容器
+
+ String range = request.getHeader("Range");
+// log.error("/upload/range/download:"+range);
+ int responseStatus = HttpServletResponse.SC_OK;
+ if (StringUtils.isNotBlank(range)) {
+ responseStatus = HttpServletResponse.SC_PARTIAL_CONTENT;
+ rangeBytes = range.replaceAll("bytes=", "");
+ if (rangeBytes.endsWith("-")) {// bytes=969998336-
+ rangeSwitch = 1;
+ rangeBytes = rangeBytes.substring(0, rangeBytes.indexOf('-'));
+ pastLength = Long.parseLong(rangeBytes.trim());
+ contentLength = fileLength - pastLength;// 客户端请求的是969998336之后的字节(包括bytes下标索引为969998336的字节)
+ } else { // bytes=1275856879-1275877358
+ rangeSwitch = 2;
+ String temp0 = rangeBytes.substring(0, rangeBytes.indexOf('-')).trim();
+ String temp2 = rangeBytes.substring(rangeBytes.indexOf('-') + 1).trim();
+ // bytes=1275856879-1275877358,从第1275856879个字节开始下载
+ pastLength = Long.parseLong(temp0);
+ toLength = Long.parseLong(temp2);// bytes=1275856879-1275877358,到第1275877358 个字节结束
+ contentLength = toLength - pastLength + 1;
+ }
+ } else {// 从开始进行下载
+ contentLength = fileLength;// 客户端要求全文下载
+ }
+ response.reset();
+ // 告诉客户端允许断点续传多线程连接下载,响应的格式是:Accept-Ranges: bytes
+ response.setHeader("Accept-Ranges", "bytes");
+ response.setHeader("Content-Length", String.valueOf(contentLength));
+ response.setContentType("application/octet-stream");
+ response.setStatus(responseStatus);
+ switch (rangeSwitch) {
+ case 0: {
+ // 是从开始下载
+ String contentRange = new StringBuilder("bytes ").append("0-")
+ .append(fileLength - 1).append("/").append(fileLength)
+ .toString();
+ response.setHeader("Content-Range", contentRange);
+ }
+ case 1: {// 针对 bytes=27000- 的请求
+ String contentRange = new StringBuilder("bytes ").append(pastLength).append("-")
+ .append(fileLength - 1).append("/").append(fileLength).toString();
+ response.setHeader("Content-Range", contentRange);
+ break;
+ }
+ case 2: {// 针对 bytes=27000-39000 的请求
+ String contentRange = range.replace("=", " ") + "/"
+ + fileLength;
+ response.setHeader("Content-Range", contentRange);
+ break;
+ }
+ }
+
+ try (WritableByteChannel outChannel = Channels.newChannel(response.getOutputStream());
+ FileChannel fileChannel = new RandomAccessFile(downloadFile, "r").getChannel()){
+ fileChannel.transferTo(pastLength, contentLength, outChannel);
+ } catch (ClientAbortException ce) {
+ //在写数据的时候, 对于 ClientAbortException 之类的异常,是因为客户端取消了下载,
+ // 而服务器端继续向浏览器写入数据时, 抛出这个异常,这个是正常的
+ log.error("ClientAbortException:"+ce);
+ } catch (IOException e) {
+ log.error("downloadSliceFile error:"+e);
+ }
+ }
+
+ @PostMapping("/audio/move")
+ public String moveBotAudio(@RequestBody MoveBotAudio moveBotAudio) {
+ try {
+ FileUtil.deleteFile(new File(Initialize.AUDIO_DIR + "/" + moveBotAudio.getDestBotAccount()));
+ moveAudio(moveBotAudio.getSrcBotAccount(), moveBotAudio.getDestBotAccount());
+ return "success";
+ } catch (Exception e) {
+ log.error("导入人工语音项目移动音频出错:" + e);
+ }
+ return "fail";
+ }
+
+ private void moveAudio(String srcBotAccount, String targetBotAccount) throws IOException {
+ Path pt = Paths.get(Initialize.AUDIO_DIR + "/" + srcBotAccount);
+ if (Files.exists(pt)) {
+ List needDir = Files.list(pt).filter(path -> path.endsWith("record") || path.endsWith("Liehu1") ||
+ path.getFileName().toString().contains("Baidu")).map(path -> path.toAbsolutePath().toString()).collect(Collectors.toList());
+ for (String dir : needDir) {
+ copyDir(dir, dir.replace(srcBotAccount, targetBotAccount));
+ }
+ }
+ }
+
+ private void getRecursion(Path path, final List result) {
+ if (Files.isDirectory(path)) {
+ try {
+ Files.list(path).forEach(path1 -> getRecursion(path1, result));
+ } catch (Exception e) {
+ log.error("递归获取音频路径出错:"+e);
+ }
+ } else {
+ result.add(path);
+ }
+ }
+
+ private void copyDir(final String source, final String target) {
+ Path sourcePath = Paths.get(source);
+ if (!Files.exists(sourcePath)) {
+ return;
+ }
+ List allSourceFilePath = new ArrayList<>();
+ getRecursion(sourcePath, allSourceFilePath);
+ allSourceFilePath.forEach(path -> {
+ try {
+ Path dest = Paths.get(path.toAbsolutePath().toString().replace(source, target));
+ Files.createDirectories(dest.getParent());
+ Files.copy(path, dest, StandardCopyOption.REPLACE_EXISTING);
+ } catch (Exception e) {
+ log.error("FileUtil#copyDir 复制出错:"+e);
+ }
+ });
+ }
+
+ public static void main(String[] args) {
+ System.out.println(TTSUtils.buildMP3Filename("这是一段测试文本,请听下音效,选择你认为合适的一套声音"));
+ }
}
diff --git a/tts_service/src/main/java/ai/qiwu/com/tts_service/pojo/deploy/MoveBotAudio.java b/tts_service/src/main/java/ai/qiwu/com/tts_service/pojo/deploy/MoveBotAudio.java
new file mode 100644
index 0000000..521fde1
--- /dev/null
+++ b/tts_service/src/main/java/ai/qiwu/com/tts_service/pojo/deploy/MoveBotAudio.java
@@ -0,0 +1,15 @@
+package ai.qiwu.com.tts_service.pojo.deploy;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * painter
+ * 20-8-3 上午10:35
+ */
+@Getter
+@Setter
+public class MoveBotAudio {
+ private String srcBotAccount;
+ private String destBotAccount;
+}
diff --git a/tts_service/src/main/java/ai/qiwu/com/tts_service/pojo/deploy/Result.java b/tts_service/src/main/java/ai/qiwu/com/tts_service/pojo/deploy/Result.java
new file mode 100644
index 0000000..b2b0bb2
--- /dev/null
+++ b/tts_service/src/main/java/ai/qiwu/com/tts_service/pojo/deploy/Result.java
@@ -0,0 +1,32 @@
+package ai.qiwu.com.tts_service.pojo.deploy;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.io.Serializable;
+
+@Getter
+@Setter
+public class Result implements Serializable {
+
+ private static final long serialVersionUID = -3948389268046368059L;
+
+ private Integer code;
+
+ private String msg;
+
+ private Object data;
+
+ public static Result success() {
+ Result result = new Result();
+ result.setCode(1);
+ return result;
+ }
+
+ public static Result failure(String msg) {
+ Result result = new Result();
+ result.setCode(500);
+ result.setMsg(msg);
+ return result;
+ }
+}
\ No newline at end of file
diff --git a/tts_service/src/main/java/ai/qiwu/com/tts_service/service/Initialize.java b/tts_service/src/main/java/ai/qiwu/com/tts_service/service/Initialize.java
index efc29c5..32cf586 100755
--- a/tts_service/src/main/java/ai/qiwu/com/tts_service/service/Initialize.java
+++ b/tts_service/src/main/java/ai/qiwu/com/tts_service/service/Initialize.java
@@ -96,13 +96,13 @@ public class Initialize implements InitializingBean {
/**
* 程序部署地址
*/
- private static final String SERVER_URL;
+ public static final String SERVER_URL;
private static final String SERVER_URL_CDN;
/**
* 音频文件目录
*/
- private static final String AUDIO_DIR;
+ public static final String AUDIO_DIR;
/**
* 压缩包上传目录
*/
diff --git a/tts_service/src/main/java/ai/qiwu/com/tts_service/service/TTService.java b/tts_service/src/main/java/ai/qiwu/com/tts_service/service/TTService.java
index a291ecd..0f466a7 100755
--- a/tts_service/src/main/java/ai/qiwu/com/tts_service/service/TTService.java
+++ b/tts_service/src/main/java/ai/qiwu/com/tts_service/service/TTService.java
@@ -122,7 +122,7 @@ public class TTService {
final AtomicInteger hasRecord = new AtomicInteger();
// 过滤掉record目录
File[] needDelete = deleteBotDir.listFiles((dir, name) -> {
- if (name.equals(Initialize.getUploadedDir())) {
+ if (StringUtils.equalsAny(name, Initialize.getUploadedDir(), "Liehu1") || name.startsWith("Baidu")) {
hasRecord.set(1);
return false;
}
diff --git a/tts_service/src/main/java/ai/qiwu/com/tts_service/service/TTServiceEdition2.java b/tts_service/src/main/java/ai/qiwu/com/tts_service/service/TTServiceEdition2.java
index 864c039..da7ee63 100644
--- a/tts_service/src/main/java/ai/qiwu/com/tts_service/service/TTServiceEdition2.java
+++ b/tts_service/src/main/java/ai/qiwu/com/tts_service/service/TTServiceEdition2.java
@@ -555,30 +555,31 @@ public class TTServiceEdition2 {
.append((filename=TTSUtils.buildMP3Filename(notVariableText))).toString();
//log.info("notVariableTextPath:{}",notVariableTextPath);
if (!TTSUtils.doesFileExist(notVariableTextPath)) {
- if (Initialize.getThirdPartyTts().contains(data.getPerson()) && !"Liehu1".equals(data.getPerson())) {
- String thirdPath = new StringBuilder(usDir).append(File.separator).append(filename).toString();
- if (!TTSUtils.doesFileExist(thirdPath)) {
- if (notVariableTextArray.length == 1) {
+ if ("Liehu1".equals(data.getPerson())) return false;
+ String thirdPath = new StringBuilder(usDir).append(File.separator).append(filename).toString();
+ if (!TTSUtils.doesFileExist(thirdPath)) {
+ if (notVariableTextArray.length == 1) {
+ GeneralMP3Data variableData = new GeneralMP3Data(data.getServer(), notVariableText,data.getPerson(),
+ data.getTone(), data.getBotname(), data.getCache(),data.getVolume(),data.getSpeed(),data.getPitch());
+ ResponseCodeWithData response = generalMP3(url, variableData, thirdPath, requestMethod, getOnline);
+ if (response == null || response.getCode() != 200) return false;
+ } else {
+ if (asynResultList == null) asynResultList = new ArrayList<>(notVariableTextArray.length);
+ Future result = POOL.submit(() -> {
GeneralMP3Data variableData = new GeneralMP3Data(data.getServer(), notVariableText,data.getPerson(),
data.getTone(), data.getBotname(), data.getCache(),data.getVolume(),data.getSpeed(),data.getPitch());
ResponseCodeWithData response = generalMP3(url, variableData, thirdPath, requestMethod, getOnline);
- if (response == null || response.getCode() != 200) return false;
- } else {
- if (asynResultList == null) asynResultList = new ArrayList<>(notVariableTextArray.length);
- Future result = POOL.submit(() -> {
- GeneralMP3Data variableData = new GeneralMP3Data(data.getServer(), notVariableText,data.getPerson(),
- data.getTone(), data.getBotname(), data.getCache(),data.getVolume(),data.getSpeed(),data.getPitch());
- ResponseCodeWithData response = generalMP3(url, variableData, thirdPath, requestMethod, getOnline);
- if (response == null || response.getCode() != 200) return "0";
- return "1";
- });
- asynResultList.add(result);
- }
+ if (response == null || response.getCode() != 200) return "0";
+ return "1";
+ });
+ asynResultList.add(result);
}
- notVariableTextPath = thirdPath;
- } else {
- return false;
}
+ notVariableTextPath = thirdPath;
+// if (Initialize.getThirdPartyTts().contains(data.getPerson())) {
+// } else {
+// return false;
+// }
}
combineMp3Text2FilePath.put(notVariableText, notVariableTextPath);
}
--
libgit2 0.27.1