diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index 3cb42ad..8982f58 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -33,7 +33,7 @@
-
+
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index a90f492..1c77f34 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -2,6 +2,11 @@
+
+
+
+
+
@@ -60,40 +65,59 @@
-
-
+
+
+
+
+
+
+
-
+
-
-
+
+
+
+
+
+
-
-
+
+
+
+
+
+
-
+
-
-
+
+
+
+
+
+
-
-
+
+
-
+
+
+
@@ -102,7 +126,7 @@
-
+
@@ -111,7 +135,7 @@
-
+
@@ -180,9 +204,6 @@
@@ -272,8 +296,8 @@
-
-
+
+
@@ -285,6 +309,8 @@
+
+
@@ -311,8 +337,6 @@
-
-
@@ -326,7 +350,7 @@
-
+
@@ -892,7 +916,8 @@
-
+
+
@@ -902,7 +927,7 @@
-
+
@@ -914,7 +939,7 @@
-
+
@@ -927,13 +952,13 @@
-
+
-
+
@@ -1000,54 +1025,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -1208,13 +1186,6 @@
-
-
-
-
-
-
-
@@ -1229,16 +1200,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -1246,17 +1207,6 @@
-
-
-
-
-
-
-
-
-
-
-
@@ -1271,13 +1221,6 @@
-
-
-
-
-
-
-
@@ -1316,9 +1259,6 @@
-
-
-
@@ -1333,16 +1273,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -1357,13 +1287,6 @@
-
-
-
-
-
-
-
@@ -1378,21 +1301,121 @@
-
-
-
-
+
+
+
+
+
+
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/readme.md b/readme.md
index e69de29..6011077 100644
--- a/readme.md
+++ b/readme.md
@@ -0,0 +1 @@
+tts_service项目,xiaoai项目,xiaoduhome项目下有上传与启动的脚本
\ No newline at end of file
diff --git a/tts_service/pom.xml b/tts_service/pom.xml
index b752100..745aa00 100644
--- a/tts_service/pom.xml
+++ b/tts_service/pom.xml
@@ -70,6 +70,12 @@
commons-fileupload
1.4
+
+
+ net.sourceforge.javacsv
+ javacsv
+ 2.0
+
com.baidu.aip
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 6b7901e..4d9e211 100644
--- 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
@@ -138,7 +138,11 @@ public class TTSUtils {
return true;
}
-
+ public static void deleteFile(String path) {
+ File file = new File(path);
+ if (!file.exists()) return;
+ file.delete();
+ }
public static void deleteFile(File file) {
if (!file.exists()) return;
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 3789d8c..13ef4aa 100644
--- 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
@@ -7,6 +7,7 @@ import ai.qiwu.com.tts_service.pojo.upload.UploadCallbackResponse;
import ai.qiwu.com.tts_service.pojo.upload.UploadOneSenData;
import ai.qiwu.com.tts_service.service.baidu.ThirdPartyService;
import com.alibaba.fastjson.JSON;
+import com.csvreader.CsvReader;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
@@ -1248,6 +1249,120 @@ public class TTService {
TTServiceUtil.buildUploadResponse(response, new TTSResponse(200, msg), 200);
}
+
+ public void uploadOneNpc2(UploadOneSenData data, HttpServletResponse response) {
+ // audio_dir/botname/record/npcname
+ final String folder = StringUtils.join(new String[]{Initialize.getAudioDir(), data.getBotName(),
+ Initialize.getUploadedDir(), data.getNpcName()}, File.separator);
+ TTSUtils.makedir(folder);
+ long currentTime = System.currentTimeMillis();
+ // zipDir(专门存放压缩包及解压缩后的文件的)/botname+timestamp(确保文件名唯一,防止统一用户删除操作与上传操作的冲突)
+ final String zipFolder = new StringBuilder(Initialize.getZipDir()).append(File.separator)
+ .append(data.getBotName()).append(currentTime).toString();
+ TTSUtils.makedir(zipFolder);
+
+ // 构建服务器上该压缩包的绝对路径
+ String zipFilename = data.getFile().getName();
+ if (zipFilename == null) zipFilename = new StringBuilder(String.valueOf(currentTime)).append(".zip").toString();
+ else if (!StringUtils.endsWith(zipFilename, ".zip")) zipFilename = zipFilename+".zip";
+ String filename = new StringBuilder(zipFolder).append(File.separator).append(zipFilename).toString();
+
+ // 写入文件
+ try {
+ data.getFile().transferTo(new File(filename));
+ } catch (IOException e) {
+ log.error("写入上传文件出错:{}",ExceptionUtils.getStackTrace(e));
+ TTServiceUtil.buildUploadResponse(response, new TTSResponse(555, "写入上传文件出错:"+filename), 555);
+ return;
+ }
+ // 检查压缩包格式是否正确,标准是不含有目录
+ if (!TTSUtils.checkZipFile(filename)){
+ TTServiceUtil.buildUploadResponse(response, new TTSResponse(400, "压缩包结构不正确"), 400);
+ return;
+ }
+ // 解压
+ if (!TTSUtils.unZip(zipFolder, filename)) {
+ TTServiceUtil.buildUploadResponse(response, new TTSResponse(555, "压缩包解压失败"), 555);
+ return;
+ }
+ // 压缩包中之应该只含有一个csv文件
+ File[] csvFiles = new File(zipFolder).listFiles((dir, name) -> StringUtils.endsWith(name, ".csv"));
+ if (csvFiles == null || csvFiles.length != 1) {
+ int count = csvFiles == null ? 0 : csvFiles.length;
+ TTServiceUtil.buildUploadResponse(response, new TTSResponse(400, "csv文件数量为"+count), 400);
+ return;
+ }
+ File csvFile = csvFiles[0];
+ // 判断该文件的编码
+ String encoding = TTSUtils.charset(csvFile);
+
+
+ // 意料之外的错误发生,无法判断程序进度,记录该种情况最后根据情况返回相应的信息
+ final List needDeleteB64File = new ArrayList<>();
+ List successUpLoadFileIds = new ArrayList<>();
+ HashSet textSet = new HashSet<>();
+ List failList = new ArrayList<>();
+ try {
+ CsvReader reader = new CsvReader(csvFile.getAbsolutePath(), ',',Charset.forName(encoding));
+ while (reader.readRecord()) {
+ // id,text,isUpload,filename
+ if (StringUtils.isBlank(reader.get(3))) continue;
+ if (!textSet.add(reader.get(1))) {
+ successUpLoadFileIds.add(reader.get(0));
+ continue;
+ }
+ String audioFileName = reader.get(3);
+ boolean hasSuffix = StringUtils.endsWith(audioFileName,".mp3") || StringUtils.endsWith(audioFileName,".MP3");
+ if (!hasSuffix) audioFileName = audioFileName+".mp3";
+ String fileInPackage = new StringBuilder(zipFolder).append(File.separator).append(audioFileName).toString();
+ String md5Name = TTSUtils.buildMP3Filename(reader.get(1)); //构造mp3文件名
+ final String usFilename = new StringBuilder(folder).append(File.separator).append(md5Name).toString();
+ boolean doesFileExit = TTSUtils.doesFileExist(fileInPackage);
+ if (!doesFileExit && !hasSuffix) {
+ fileInPackage = new StringBuilder(zipFolder).append(File.separator)
+ .append(reader.get(3)).append(".MP3").toString();
+ doesFileExit = TTSUtils.doesFileExist(fileInPackage);
+ }
+ if (doesFileExit) {
+ File usFile = new File(usFilename);
+ boolean result=true;
+ // 删除之前的旧文件
+ if (TTSUtils.doesFileExist(usFilename)) {
+ result = usFile.delete();
+ }
+ // 删除成功后删除其b64文件,且将压缩包中的文件移到安置目录下,即
+ // /root/TTS-service/mqwZip/audioFilename -> audio_dir/botname/record/npcname/xxx.mp3
+ if (result) {
+ needDeleteB64File.add(new StringBuilder());
+ try {
+ Files.copy(new File(fileInPackage).toPath(), usFile.toPath());
+ successUpLoadFileIds.add(reader.get(0));
+ } catch (Exception e) {
+ textSet.remove(reader.get(1));
+ }
+ }else {
+ textSet.remove(reader.get(1));
+ log.error("删除之前的就音频失败:{}",fileInPackage);
+ }
+ } else {
+ failList.add(reader.get(0));
+ }
+ }
+ } catch (Exception e) {
+ log.error("解析csv文件出错:{}",ExceptionUtils.getStackTrace(e));
+ TTServiceUtil.buildUploadResponse(response, new TTSResponse(200, "程序出错"), 200);
+ return;
+ }
+ POOL.submit(() -> {
+ TTSUtils.deleteFile(new File(zipFolder));
+ for (String path: needDeleteB64File) {
+ TTSUtils.deleteFile(path);
+ }
+ });
+ //log.info("msg:{}",msg);
+ TTServiceUtil.buildUploadResponse(response, new TTSResponse(200, failList.toString()), 200);
+ }
+
/**
* 删除单个上传音频文件,
* 参数说明:tid:句子id;botName:作品标识;npcName:npc名称;text:要删除的音频的内容
diff --git a/xiaoduhome/readme.md b/xiaoduhome/readme.md
new file mode 100644
index 0000000..a52844e
--- /dev/null
+++ b/xiaoduhome/readme.md
@@ -0,0 +1,2 @@
+upload.sh:将jar包上传到服务器;
+start.sh:服务器上执行该文件,启动项目
\ No newline at end of file
diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/TestBuild.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/TestBuild.java
index 0704c3b..439c4c9 100644
--- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/TestBuild.java
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/TestBuild.java
@@ -194,9 +194,14 @@ public class TestBuild {
srcReader.readHeaders();
HashSet set = new HashSet<>();
while (srcReader.readRecord()) {
- String[] arr = srcReader.getRawRecord().split(",");
- if (arr.length != 4) continue;
- set.add(arr[0]);
+ //String[] arr = srcReader.getRawRecord().split(",");
+ if (StringUtils.isBlank(srcReader.get(3))) {
+ System.out.print(srcReader.get(0)+" ");
+ continue;
+ }
+ if (srcReader.get(3).lastIndexOf(".") != -1 &&
+ (!StringUtils.endsWith(srcReader.get(3),".mp3") && !StringUtils.endsWith(srcReader.get(3),".MP3"))) continue;
+ set.add(srcReader.get(0));
}
System.out.println(set.size());
}
diff --git a/xiaoduhome/start.sh b/xiaoduhome/start.sh
new file mode 100644
index 0000000..7434a3a
--- /dev/null
+++ b/xiaoduhome/start.sh
@@ -0,0 +1 @@
+nohup java -jar /root/GameEditor/mqw/xiaoduhome/xiaoduhome.jar > nohup.log 2>&1 &
\ No newline at end of file
diff --git a/xiaoduhome/upload.sh b/xiaoduhome/upload.sh
new file mode 100644
index 0000000..582a341
--- /dev/null
+++ b/xiaoduhome/upload.sh
@@ -0,0 +1 @@
+scp /usr/local/intellij/workplace/smartbox/xiaoduhome/target/xiaoduhome.jar root@aliyun-hz1.chewrobot.com:/root/GameEditor/mqw/xiaoduhome/
\ No newline at end of file