Commit ff2f944f by 苗权威

9.20

parent d6419d69
......@@ -2,6 +2,7 @@
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile default="true" name="Default" enabled="true" />
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
......
......@@ -118,6 +118,27 @@ public class OkHttp3Utils {
return null;
}
public static Integer doPostJsonStrReturnCode(String url, String requestJsonStr) throws IOException {
Request.Builder builder = new Request.Builder();
Request request = builder.url(url).build();
Headers.Builder headBuilder = request.headers().newBuilder();
headBuilder.add("Content-Type","application/json; charset=utf-8");
builder.headers(headBuilder.build()).post(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), requestJsonStr));
try (Response response = client.newCall(builder.build()).execute()){
int code = response.code();
response.body().string();
return code;
}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,
String requestJsonStr, File file, boolean longTime) throws IOException {
OkHttpClient timeoutClient;
......
package ai.qiwu.com.tts_service.common;
import ai.qiwu.com.tts_service.pojo.TTSRequest;
import ai.qiwu.com.tts_service.service.Initialize;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
......@@ -135,6 +136,8 @@ public class TTSUtils {
return true;
}
public static void deleteFile(File file) {
if (!file.exists()) return;
if (file.isDirectory()) {
......@@ -414,11 +417,7 @@ public class TTSUtils {
}
public static void main(String[] args) {
File deleteBotDir = new File("/home/yf01/springbootdemo");
File[] needDelete = deleteBotDir.listFiles((dir, name) -> !name.equals("record"));
//System.out.println(needDelete.length);
//System.out.println(Arrays.toString(needDelete));
System.out.println(charset(new File("/usr/local/sublimeWorkplace/font/play.json")));
String test2 = "{\"_type\":\"json\",\"person\":\"A04_offline\",\"tone\":\"正常\",\"text\":\"你认为水星有水存在吗\",\"curDate\":1568879455745,\"botname\":\"6854303973\",\"pitch\":0,\"speed\":1.36,\"volume\":5,\"npcName\":\"旁白\",\"get_online\":false}";
System.out.println(JSON.parseObject(test2, TTSRequest.class));
}
}
......@@ -6,6 +6,7 @@ import ai.qiwu.com.tts_service.pojo.TTSResponse;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
......@@ -63,8 +64,8 @@ public class TTServiceUtil {
out.write(buffer, 0, ln);
}
out.flush();
} catch (Exception e) {
log.error("写入音频流到HttpServletResponse失败:{}", e.toString());
} catch (IOException e) {
log.error("buildMp3Response:写入音频流到HttpServletResponse失败:{}", ExceptionUtils.getStackTrace(e));
}
}
}
......@@ -101,8 +102,8 @@ public class TTServiceUtil {
out.write(buffer, 0, ln);
}
out.flush();
} catch (Exception e) {
log.error("写入音频流到HttpServletResponse失败:{}", e.toString());
} catch (IOException e) {
log.error("buildServletResponse:写入音频流到HttpServletResponse失败:{}", ExceptionUtils.getStackTrace(e));
}
} else {
String ttsResJsonStr = JSON.toJSONString(ttsResponse);
......
......@@ -8,6 +8,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
......@@ -46,8 +47,8 @@ public class TTSController {
@RequestParam(required = false) String text, @RequestParam(required = false) String botname,
@RequestParam(required = false) String _type, @RequestParam(required = false) String volume,
@RequestParam(required = false) String pitch, @RequestParam(required = false) String speed,
@RequestParam(required = false) Boolean get_online, HttpServletResponse servletResponse) {
TTSRequest ttsRequest = new TTSRequest(person, text, _type, pitch, tone, botname, volume, speed,get_online);
@RequestParam(required = false) Boolean get_online, @RequestParam(required = false) String npcName,HttpServletResponse servletResponse) {
TTSRequest ttsRequest = new TTSRequest(person, text, _type, pitch, tone, botname, volume, speed,get_online,npcName);
ttService.tts(ttsRequest, "GET", servletResponse);
}
......@@ -89,16 +90,40 @@ public class TTSController {
response.setStatus(200);
}
// @PostMapping("/api/upload/record/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);
// }
@PostMapping("/api/upload/record/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);
public void uploadOneSen(HttpServletRequest request, HttpServletResponse response) {
MultipartHttpServletRequest mulRequest = (MultipartHttpServletRequest) request;
MultipartFile file = mulRequest.getFile("file");
String botName = mulRequest.getParameter("botName");
String npcName = mulRequest.getParameter("npcName");
String text = mulRequest.getParameter("text");
String tid = mulRequest.getParameter("tid");
UploadOneSenData data = new UploadOneSenData(Integer.valueOf(tid), botName, npcName, text, file);
ttService.uploadOneSen(data, response);
}
// @PostMapping("/api/upload/record/one_npc")
// public void uploadOneNpc(MultipartFile file, String botName, String npcName,
// HttpServletResponse response) {
// UploadOneSenData data = new UploadOneSenData(botName, npcName, file);
// ttService.uploadOneNpc(data, response);
// }
@PostMapping("/api/upload/record/one_npc")
public void uploadOneNpc(MultipartFile file, String botName, String npcName,
HttpServletResponse response) {
public void uploadOneNpc(HttpServletRequest request, HttpServletResponse response) {
MultipartHttpServletRequest mulRequest = (MultipartHttpServletRequest) request;
MultipartFile file = mulRequest.getFile("file");
String botName = mulRequest.getParameter("botName");
String npcName = mulRequest.getParameter("npcName");
UploadOneSenData data = new UploadOneSenData(botName, npcName, file);
ttService.uploadOneNpc(data, response);
}
......@@ -109,8 +134,8 @@ public class TTSController {
}
@PostMapping("/api/offline_callback")
public void offlineCallback(MultipartFile file, String url, String ids, HttpServletResponse response) {
ttService.offlineCallback(file, url, ids, response);
public void offlineCallback(MultipartFile file, HttpServletResponse response) {
ttService.offlineCallback(file, response);
}
}
package ai.qiwu.com.tts_service.pojo;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
/**
* @author 苗权威
* @dateTime 19-9-20 上午10:03
*/
@Getter
@Setter
@ToString
public class DelCacheCallbackUrlRequest {
private String botname;
}
package ai.qiwu.com.tts_service.pojo;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.*;
/**
* @author 苗权威
......@@ -12,6 +10,8 @@ import lombok.ToString;
@Getter
@Setter
@ToString
@AllArgsConstructor
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class TTSRequest {
private String person;
......@@ -24,17 +24,4 @@ public class TTSRequest {
private String speed;
private Boolean get_online;
private String npcName;
public TTSRequest(String person, String text, String _type, String pitch,
String tone, String botname, String volume, String speed,Boolean get_online) {
this.person = person;
this.text = text;
this._type = _type;
this.pitch = pitch;
this.tone = tone;
this.botname = botname;
this.volume = volume;
this.speed = speed;
this.get_online = get_online;
}
}
......@@ -3,6 +3,7 @@ package ai.qiwu.com.tts_service.pojo.upload;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.web.multipart.MultipartFile;
/**
......@@ -11,6 +12,7 @@ import org.springframework.web.multipart.MultipartFile;
*/
@Getter
@Setter
@ToString
@JsonIgnoreProperties(ignoreUnknown = true)
public class UploadOneSenData {
private Integer tid;
......
......@@ -46,7 +46,7 @@ public class ThirdPartyService {
options.put("spd", 5);
// options.put("pit", correctSoundParams(pitch, true));
options.put("vol", 5);
options.put("aue", 4);
options.put("aue", 6);
options.put("per", per);
TtsResponse res = CLIENT.synthesis(text, "zh", 1, options);
if (res.getResult() == null) {
......
......@@ -32,3 +32,4 @@ server:
pattern: '%h %l %u %t "%r" %s %b bytes %D ms'
directory: /home/ubuntu/project/tts/tomcat
#directory: /root/GameEditor/mqw/project/ttsTest/tomcat
connection-timeout: 240000
......@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
import com.eclipsesource.json.JsonObject;
import lombok.*;
import java.net.URLDecoder;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.sql.Timestamp;
......@@ -12,6 +13,7 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......@@ -106,34 +108,10 @@ public class TestBuild {
return sb.toString() ;
}
public static void main(String[] args) {
String s = "\uD83C\uDD70(.*?)\uD83C\uDD71";
String test = "23424ijoij\uD83C\uDD70\uD83C\uDD71ghoiwugh\uD83C\uDD70oihjoihoih\uD83C\uDD71gerwgwgh";
String test2 = "342gsegsergh";
//test = new String(test.getBytes(), Charset.forName("UTF-8"));
Pattern pattern = Pattern.compile(s);
Matcher matcher = pattern.matcher(test2);
//System.out.println(matcher.groupCount());
System.out.println(matcher.find());
// while (matcher.find()) {
// System.out.println(matcher.group(1));
// }
System.out.println(Arrays.toString(pattern.split(test2)));
String test3 = "sgiejogwi{/sgrg/}sgkw{/3432iuh/}sge4g{/sfg/}fs/gerg/}";
String test4 = "gewgewghwhwh";
System.out.println(test3.replaceAll("\\{/(.+?)/}", ""));
System.out.println(test3.replaceAll("\\{/(.+?)/\\}", ""));
System.out.println(test4.replaceAll("\\{/(.+?)/}", ""));
System.out.println(test4.replaceAll("\\{/(.+?)/\\}", ""));
System.out.println(JSON.toJSONString(new Long[]{}));
String test5 = "[1, 2, 3]";
String[] idList = test5.substring(1, test5.length()-1).split(",");
String[] idTrimList = new String[idList.length];
for (int i = 0; i < idList.length; i++) idTrimList[i] = idList[i].trim();
System.out.println(JSON.toJSONString(idTrimList));
String test6 = "[ ]";
String test7 = "";
String[] idList2 = test6.substring(1, test6.length()-1).split(",");
System.out.println(Arrays.toString(idList2));
System.out.println(test6.length());
String test = "%5B6854303973%2CA04_offline%2C%E6%AD%A3%E5%B8%B8%5D";
System.out.println(URLDecoder.decode(test));
String test2 = "{/(sgeg)/}11woier11{/sdg/}11gj{//}23424k11{/234g/}11sg11{/sgg/}";
System.out.println(test2.replaceAll("\\{/.+?/}", ""));
System.out.println(test2.replaceAll("\\{/.*?/}", ""));
}
}
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