diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 32930e0..1f090ba 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -6,26 +6,11 @@
-
-
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
@@ -63,72 +48,55 @@
-
+
-
-
+
+
-
+
-
+
-
-
-
-
-
-
-
+
+
-
+
-
-
+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
-
+
-
-
+
+
+
+
+
@@ -193,8 +161,6 @@
@@ -260,11 +228,11 @@
-
+
-
+
@@ -275,7 +243,7 @@
-
+
@@ -288,7 +256,6 @@
-
@@ -299,25 +266,25 @@
-
+
-
+
-
+
-
+
@@ -325,63 +292,27 @@
-
+
-
+
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -393,7 +324,7 @@
-
+
@@ -421,7 +352,7 @@
-
+
@@ -534,18 +465,18 @@
+
-
-
+
@@ -755,15 +686,17 @@
-
+
+
+
-
+
-
+
@@ -774,10 +707,10 @@
-
+
-
-
+
+
@@ -786,7 +719,7 @@
-
+
@@ -797,7 +730,7 @@
-
+
@@ -812,34 +745,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -996,13 +901,6 @@
-
-
-
-
-
-
-
@@ -1010,30 +908,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1041,20 +915,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1062,13 +922,6 @@
-
-
-
-
-
-
-
@@ -1097,13 +950,6 @@
-
-
-
-
-
-
-
@@ -1139,37 +985,68 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
-
+
-
+
-
-
+
+
-
+
-
-
+
+
+
+
+
-
+
@@ -1179,15 +1056,77 @@
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
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 e1179e8..843fc12 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
@@ -515,9 +515,11 @@ public class ApachHttpUtils {
if (status == 200) {
HttpEntity httpEntity = response.getEntity();
if(httpEntity != null){
- String result = EntityUtils.toString(httpEntity, "UTF-8");
+ byte[] bytes = EntityUtils.toByteArray(httpEntity);
+// String result = EntityUtils.toString(httpEntity, "UTF-8");
EntityUtils.consume(httpEntity);//关闭资源
- return result;
+// return result;
+ return String.valueOf(bytes.length);
}
}
}
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 ec07cc2..2473bd6 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
@@ -29,14 +29,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestHeader;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
@@ -59,6 +52,7 @@ import lombok.extern.slf4j.Slf4j;
* painter
* 20-6-11 下午7:57
*/
+@CrossOrigin
@RestController
@RequestMapping("/upload")
@Slf4j
diff --git a/tts_service/src/main/java/ai/qiwu/com/tts_service/controller/TTSController.java b/tts_service/src/main/java/ai/qiwu/com/tts_service/controller/TTSController.java
index e60b588..15d8449 100755
--- a/tts_service/src/main/java/ai/qiwu/com/tts_service/controller/TTSController.java
+++ b/tts_service/src/main/java/ai/qiwu/com/tts_service/controller/TTSController.java
@@ -1,14 +1,18 @@
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.ServerResponse;
import ai.qiwu.com.tts_service.common.TTSUtils;
import ai.qiwu.com.tts_service.pojo.*;
import ai.qiwu.com.tts_service.pojo.upload.UploadOneSenData;
import ai.qiwu.com.tts_service.service.*;
+import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.csv.CSVFormat;
+import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVPrinter;
+import org.apache.commons.csv.CSVRecord;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -25,6 +29,7 @@ import java.io.*;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -413,16 +418,109 @@ public class TTSController {
// return cdnService.getDirPugeState(botAccount);
// }
+ private static void buildTTSTime(String sentence, String noCdnBytes, Long noCdnTime, String cdnOnceBytes,
+ Long cdnOnceTime, String cdnBytes, Long cdnTime) {
+ synchronized(TTServiceEdition2.class) {
+ CSVFormat format;
+ if (Files.exists(Paths.get("/home/yf01/下载/audioCut/timeAccount/cdnTest.csv"))) format = CSVFormat.DEFAULT;
+ else format = CSVFormat.DEFAULT.withHeader("sentence", "noCdnBytes", "noCdnTime", "cdnOnceBytes", "cdnOnceTime", "cdnBytes", "cdnTime");
+ try (CSVPrinter csvPrinter = new CSVPrinter(new OutputStreamWriter(
+ new FileOutputStream("/home/yf01/下载/audioCut/timeAccount/cdnTest.csv", true), Charset.forName("UTF-8")),format)){
+ csvPrinter.printRecord(sentence, noCdnBytes, noCdnTime, cdnOnceBytes, cdnOnceTime, cdnBytes, cdnTime);
+ } catch (IOException e) {
+ log.error("buildTTSTime:"+e);
+ }
+ }
+ }
+
public static void main(String[] args) throws IOException {
- String text = "今天是第";
- String text2 = "6";
- String text3 = "天,知道吗?,";
- String text4 = "知道";
-
- System.out.println(TTSUtils.buildMP3Filename(text));
- System.out.println(TTSUtils.buildMP3Filename(text2));
- System.out.println(TTSUtils.buildMP3Filename(text3));
- System.out.println(TTSUtils.buildMP3Filename(text4));
+// String[] arr = {"为咱们人类的共同命运。", "我们应该要展现大国的担当。","还有我们中国同各国一道重温使命。","当然要共同构建人类命运共同体。",
+// "这仅仅是他们的交流方式。","当然这些对他们的自由权起到限制。", "除此之外美国宣扬所谓国家安全。","这就会意味着案件会呈递联邦法庭。", "还有这项裁决很可能会继续有效。",
+// "当然这些在美国什么不能发生。", "推测很可能美国又出台新禁令。", "美国的最高法院的大法官是谁。", "特朗普总统又开始挑剔施压。", "尊重市场经济和公平竞争的原则。", "外国企业在美国投资经营。"};
+// String[] seq = {"所以你们要买什么\uD83C\uDD70蔬菜", "所以你们要买什么\uD83C\uDD70水果", "所以你们要买什么\uD83C\uDD70肉类",
+// "所以你们要买什么\uD83C\uDD70干货", "所以你们要买什么\uD83C\uDD70鱼类", "所以你们要买什么\uD83C\uDD70水产品",
+// "所以你们要买什么\uD83C\uDD70瓜果蔬菜", "所以你们要买什么\uD83C\uDD70东西"};
+// String[] seqPost = {"呢\uD83C\uDD71","哦\uD83C\uDD71","吧\uD83C\uDD71","嘿\uD83C\uDD71","呵\uD83C\uDD71",
+// "吒\uD83C\uDD71","哼\uD83C\uDD71","哈\uD83C\uDD71","吼\uD83C\uDD71","嘀\uD83C\uDD71","兹\uD83C\uDD71"};
+// List list = new ArrayList<>();
+// for (int i = 0; i < 11; i++) {
+// for (int j = 0; j < 8; j++) {
+// list.add(arr[i]+seq[j]+seqPost[i]);
+// }
+// }
+
+// list = Collections.singletonList("在美国句子重复会更快吗,你说呢有可能吗谁知道呢");
+// Map header = Collections.singletonMap("Content-Type", "application/json");
+// for (String str: list) {
+// TTSLSRequest request = new TTSLSRequest();
+// request.setBotname("miaoTestSeqTime");
+// request.set_type("url");
+//
+// TextInfo textInfo = new TextInfo();
+// textInfo.setBotAccount("miaoTestSeqTime");
+// textInfo.setNpcName("默笙");
+// textInfo.setPerson("Liehu1");
+// textInfo.setTone("正常");
+// textInfo.setPitch("0.5");
+// textInfo.setSpeed("1.36");
+// textInfo.setVolume("12.5");
+// textInfo.setText(str);
+// request.setText_info_ls(Collections.singletonList(textInfo));
+//
+// ApachHttpUtils.post("http://hw-gz25.heyqiwu.cn:9663/api/tts_ls", JSON.toJSONString(request), header);
+// try {
+// Thread.sleep(3000);
+// } catch (Exception e) {
+//
+// }
+// }
+ String preCsvPath = "/home/yf01/下载/audioCut/timeAccount/A13.csv";
+ try (CSVParser csvRecords = CSVFormat.EXCEL.parse(new BufferedReader(
+ new InputStreamReader(new FileInputStream(new File(preCsvPath)), StandardCharsets.UTF_8)))) {
+ boolean first = true;
+ String prefix ="http://hw-gz25.heyqiwu.cn:9663/api/audio/cache/miaoTestTime/?filename=/miaoTestTime/A13/正常/";
+ String cdnPrefix = "http://cdntest.heyqiwu.cn/api/audio/cache/miaoTestTime/?filename=/miaoTestTime/A13/正常/";
+ for (CSVRecord line: csvRecords) {
+ if (first) {
+ first = false;
+ continue;
+ }
+ // "person", "mood", "md5", "id", "upUrl"
+ String text = line.get(0);
+ String url = prefix+TTSUtils.buildMP3Filename(text);
+ long t1 = System.currentTimeMillis();
+ String noCdnSize = ApachHttpUtils.get(url, null, null);
+ long noCdnTime = System.currentTimeMillis()-t1;
+
+ try {
+ Thread.sleep(1000);
+ } catch (Exception e) {
+
+ }
+
+ url = cdnPrefix+TTSUtils.buildMP3Filename(text);
+ t1 = System.currentTimeMillis();
+ String cdnOnceSize = ApachHttpUtils.get(url, null, null);
+ long cdnOnceTime = System.currentTimeMillis()-t1;
+
+ try {
+ Thread.sleep(1000);
+ } catch (Exception e) {
+
+ }
+
+ t1 = System.currentTimeMillis();
+ String cdnSize = ApachHttpUtils.get(url, null, null);
+ long cdnTime = System.currentTimeMillis()-t1;
+
+ buildTTSTime(text, noCdnSize, noCdnTime, cdnOnceSize, cdnOnceTime, cdnSize, cdnTime);
+ try {
+ Thread.sleep(1000);
+ } catch (Exception e) {
+
+ }
+ }
+ }
}
}
diff --git a/tts_service/src/main/java/ai/qiwu/com/tts_service/filter/CorsFilter.java b/tts_service/src/main/java/ai/qiwu/com/tts_service/filter/CorsFilter.java
index 0f1b527..2329bb1 100644
--- a/tts_service/src/main/java/ai/qiwu/com/tts_service/filter/CorsFilter.java
+++ b/tts_service/src/main/java/ai/qiwu/com/tts_service/filter/CorsFilter.java
@@ -13,25 +13,17 @@ import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
-@Component
-public class CorsFilter implements Filter {
-
- final static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(CorsFilter.class);
-
- public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
- throws IOException, ServletException {
- HttpServletResponse response = (HttpServletResponse) res;
- response.setHeader("Access-Control-Allow-Origin", "*");
- response.setHeader("Access-Control-Allow-Credentials", "true");
- response.setHeader("Access-Control-Allow-Methods", "*");
- response.setHeader("Access-Control-Max-Age", "3600");
- response.setHeader("Access-Control-Allow-Headers", "*");
- chain.doFilter(req, res);
- }
-
- public void init(FilterConfig filterConfig) {
- }
-
- public void destroy() {
- }
+//@Component
+public class CorsFilter {
+
+// public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
+// throws IOException, ServletException {
+// HttpServletResponse response = (HttpServletResponse) res;
+// response.setHeader("Access-Control-Allow-Origin", "*");
+// response.setHeader("Access-Control-Allow-Credentials", "true");
+// response.setHeader("Access-Control-Allow-Methods", "*");
+// response.setHeader("Access-Control-Max-Age", "3600");
+// response.setHeader("Access-Control-Allow-Headers", "*");
+// chain.doFilter(req, res);
+// }
}
\ No newline at end of file
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 fdd1cf7..a6cefb1 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
@@ -15,8 +15,7 @@ import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.servlet.http.HttpServletResponse;
-import java.io.File;
-import java.io.UnsupportedEncodingException;
+import java.io.*;
import java.net.URLEncoder;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -261,6 +260,8 @@ public class TTServiceEdition2 {
}
public void tts_ls(TTSLSRequest request, HttpServletResponse response) {
+// long start = System.currentTimeMillis();
+
String _type = request.get_type();
String platform = request.getPlatform();
List infoList = request.getText_info_ls();
@@ -364,6 +365,7 @@ public class TTServiceEdition2 {
if (!TTSUtils.doesFileExist(path)) {
ResponseCodeWithData response1 = generalMP3(moodUrl, data, path, "GET",true);
if (response1 == null) response1 = new ResponseCodeWithData(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "tts_ls:generalMP3 return null");
+// buildTTSTime(data.getText(), data.getPerson(), data.getText().length(), System.currentTimeMillis()-start);
return response1;
}
} catch (Exception e) {
@@ -403,6 +405,20 @@ public class TTServiceEdition2 {
}
}
+// private void buildTTSTime(String sentence, String person, Integer length, Long time) {
+// synchronized(TTServiceEdition2.class) {
+// CSVFormat format;
+// if (Files.exists(Paths.get("/root/TTS-service/accountTime.csv"))) format = CSVFormat.DEFAULT;
+// else format = CSVFormat.DEFAULT.withHeader("sentence", "person", "length", "time");
+// try (CSVPrinter csvPrinter = new CSVPrinter(new OutputStreamWriter(
+// new FileOutputStream("/root/TTS-service/accountTime.csv", true), Charset.forName("UTF-8")),format)){
+// csvPrinter.printRecord(sentence, person, length, time);
+// } catch (IOException e) {
+// log.error("buildTTSTime:"+e);
+// }
+// }
+// }
+
private ResponseCodeWithData generalMP3(String url, GeneralMP3Data data, String filePath, String requestMethod,
boolean getOnline) {
ResponseCodeWithData res = null;