directives = new ArrayList<>();
+ directives.add(directive);
+ responseInfo.setDirectives(directives);
+
+ ToDisplay display = new ToDisplay();
+ display.setType(0);
+ display.setText(text);
+ responseInfo.setTo_display(display);
+
+ return response;
+ }
+
/**
* 构建文字返回信息
* @param text 文字
@@ -179,8 +206,16 @@ public class XiaoAiService {
// }
LAST_OUTTIME_RESULT.remove(getUserId(request));
LAST_OUTTIME_MARK.remove(getUserId(request));
- if (NumberUtils.INTEGER_ONE.equals(request.getType())) return buildTextResponse(XiaoAiConstants.TTS.WELCOME_WORD_CHILD);
- else if (NumberUtils.INTEGER_TWO.equals(request.getType())) return buildTextResponse(XiaoAiConstants.TTS.WELCOME_WORD_Adult);
+ LAST_AUDIO_PLAY.remove(getUserId(request));
+ Integer type;
+ if ((type = request.getType()) != null) {
+ switch (type) {
+ case 1: return buildTextResponse(XiaoAiConstants.TTS.WELCOME_WORD_CHILD);
+ case 2: return buildTextResponse(XiaoAiConstants.TTS.WELCOME_WORD_Adult);
+ case 3: return buildTextResponse(XiaoAiConstants.TTS.WELCOME_WORD_CHILD_STORY);
+ case 4: return buildTextResponse(XiaoAiConstants.TTS.WELCOME_WORD_Adult_literature);
+ }
+ }
return buildTextResponse(XiaoAiConstants.TTS.WELCOME_WORD);
}
@@ -194,15 +229,8 @@ public class XiaoAiService {
private XiaoAiResponse dealWithIntentRequest(XiaoAiRequest request, String userId) {
Boolean idle = request.getRequest().getNo_response();
Byte waitType;
- if ((waitType=LAST_OUTTIME_MARK.get(userId)) != null) {
+ if ((waitType=LAST_OUTTIME_MARK.remove(userId)) != null) {
boolean firstTime = waitType == 0;
- try {
- //log.info("开始等待");
- Thread.sleep(1600);
- //log.info("等待OVER");
- } catch (InterruptedException e) {
- log.warn("等待中断");
- }
if (LAST_OUTTIME_RESULT.get(userId) == null) {
if (Boolean.TRUE.equals(idle)) {
if (firstTime) {
@@ -210,6 +238,7 @@ public class XiaoAiService {
return buildTextResponse((RandomUtils.nextInt() & 1) == 1 ? XiaoAiConstants.TTS.WAIT_WORD_1 :
XiaoAiConstants.TTS.WAIT_WORD_2);
} else {
+ LAST_OUTTIME_MARK.put(userId, OUTTIME_TYPE_2);
return buildTextResponse(WAIT_WORD_3);
}
}
@@ -217,13 +246,12 @@ public class XiaoAiService {
return buildTextResponse((RandomUtils.nextInt() & 1) == 1 ? XiaoAiConstants.TTS.WAIT_WORD_1 :
XiaoAiConstants.TTS.WAIT_WORD_2);
}
- LAST_OUTTIME_MARK.remove(userId);
return LAST_OUTTIME_RESULT.remove(userId);
}
- if (idle != null && idle) {
+ if (Boolean.TRUE.equals(idle)) {
try {
//log.info("开始等待");
- Thread.sleep(1900);
+ Thread.sleep(2000);
//log.info("等待OVER");
} catch (InterruptedException e) {
log.warn("等待中断");
@@ -235,11 +263,15 @@ public class XiaoAiService {
return buildTextResponse((RandomUtils.nextInt() & 1) == 1 ? XiaoAiConstants.TTS.USER_IDLE :
XiaoAiConstants.TTS.ANOTHER_USER_IDLE);
}
+ String path;
+ if ((path = LAST_AUDIO_PLAY.get(userId)) != null) {
+ return buildAudioResponse(changeAudioUrl(path, userId));
+ }
// XiaoAiResponse response = getLastResult(userId);
// if (response != null) return response;
try {
Future future = DplbotServiceUtil.getPool().submit(new Task(userId, request.getQuery(), request.getType()));
- future.get(2100, TimeUnit.MILLISECONDS);
+ future.get(2250, TimeUnit.MILLISECONDS);
} catch (InterruptedException | ExecutionException e) {
log.error("获取任务执行结果出错:{}", e.toString());
return buildTextResponse(SORRY_REPEAT);
@@ -260,17 +292,21 @@ public class XiaoAiService {
* @return 返回信息
*/
private XiaoAiResponse dealWithEndRequest(String userId, Integer type) {
- DplbotServiceUtil.getPool().submit(() -> {
- try {
- RequestTerminal.requestTerminate(userId, XiaoAiConstants.TTS.END_WORD, type);
- } catch (Exception e) {
- log.error("向终端发出的退出请求失败:{}", e.toString());
- }
- });
+// DplbotServiceUtil.getPool().submit(() -> {
+// try {
+// RequestTerminal.backBotRequest(userId, type);
+// } catch (Exception e) {
+// log.error("向终端发出的退出请求失败:{}", e.toString());
+// }
+// });
+ RequestTerminal.backBotRequest(userId, type);
LAST_OUTTIME_MARK.remove(userId);
LAST_OUTTIME_RESULT.remove(userId);
- if (NumberUtils.INTEGER_ONE.equals(type)) return buildTextResponse(XiaoAiConstants.TTS.END_BYE_CHILD);
- else if (NumberUtils.INTEGER_TWO.equals(type)) return buildTextResponse(XiaoAiConstants.TTS.END_BYE_Adult);
+ LAST_AUDIO_PLAY.remove(userId);
+ if (type != null) {
+ if ((type & 1) == 1) return buildTextResponse(XiaoAiConstants.TTS.END_BYE_CHILD);
+ else return buildTextResponse(XiaoAiConstants.TTS.END_BYE_Adult);
+ }
return buildTextResponse(XiaoAiConstants.TTS.END_BYE);
}
@@ -287,6 +323,7 @@ public class XiaoAiService {
if (userId == null) {
userId = Utils.useIPAsItsID();
}
+ userId = PREFIX_USERID+userId;
return Utils.modifyDeviceId(userId);
}
@@ -316,32 +353,98 @@ public class XiaoAiService {
throw new RequestWordNullException("user word can not be null");
}
log.info("小爱,用户说的话:{}", userWord);
- QiWuResponse response;
+ String response;
try {
response = RequestTerminal.requestTerminate(userId, userWord, type);
+ log.info("小爱,小悟返回:{}", response);
} catch (Exception e) {
log.error("向终端发出的请求信息失败:{}", e.toString());
- throw new RequestTerminateFail(e.toString());
+ xiaoAiResponse = buildTextResponse(SORRY_REPEAT);
+ LAST_OUTTIME_RESULT.put(userId, xiaoAiResponse);
+ return;
}
- if (response == null || StringUtils.isBlank(response.getAudio())) {
- log.error("中控返回结果或是url链接为空");
+ if (StringUtils.isBlank(response)) {
+ log.error("中控返回结果为空");
xiaoAiResponse = buildTextResponse(SORRY_REPEAT);
} else {
- log.info("小爱,小悟返回:{}, audio:{}", response.getText(),response.getAudio());
- final String audioUrl = response.getAudio();
- xiaoAiResponse = buildAudioResponse(audioUrl);
- final String word = userWord;
- DplbotServiceUtil.getPOOL().submit(() -> {
- if (deviceId.equals(userId)) {
- WebSocketLog.sendInfo(new StringBuilder(word).append(File.separator)
- .append(response.getText()).toString(), "ai1");
+ String path;
+ try {
+ boolean one;
+ if ((one=userId.equals(deviceId))) {
+ path = OkHttp3Utils.doPostJsonStr(XiaoAiConstants.TTS_DIDI4, response);
+ } else {
+ path = OkHttp3Utils.doPostJsonStr(XiaoAiConstants.TTS_DIDI3, response);
+ }
+ if (StringUtils.isBlank(path) || path.equals("null")) {
+ log.error("没有获取到TTS返回的路径path");
+ LAST_OUTTIME_RESULT.put(userId, buildTextResponse(SORRY_REPEAT));
+ return;
+ }
+ if (one) {
+ xiaoAiResponse = buildAudioResponse(changeAudioUrlTemp(path, userId));
+ } else {
+ xiaoAiResponse = buildAudioResponse(changeAudioUrl(path, userId));
+ }
+ LAST_AUDIO_PLAY.put(userId, path);
+ if (userId.equals(deviceId)) {
+ DplbotServiceUtil.getPool().submit(() -> {
+ JSONObject ob = JSONObject.parseObject(response);
+ JSONArray array = ob.getJSONArray("dialogs");
+ StringBuilder builder = new StringBuilder(userWord).append(File.separator);
+ for (Object item: array) {
+ String str = ((JSONObject) item).getString("text");
+ builder.append(str.replaceAll("\\{/.*?/}", "")).append(";");
+ }
+ WebSocketLog.sendInfo(builder.toString(), "ai1");
+ });
} else {
- WebSocketLog.sendInfo(new StringBuilder(word).append(File.separator)
- .append(response.getText()).toString(), "ai2");
+ DplbotServiceUtil.getPool().submit(() -> {
+ JSONObject ob = JSONObject.parseObject(response);
+ JSONArray array = ob.getJSONArray("dialogs");
+ StringBuilder builder = new StringBuilder(userWord).append(File.separator);
+ for (Object item: array) {
+ String str = ((JSONObject) item).getString("text");
+ builder.append(str.replaceAll("\\{/.*?/}", "")).append(";");
+ }
+ WebSocketLog.sendInfo(builder.toString(), "ai2");
+ });
}
- });
+ } catch (Exception e) {
+ log.error("没有获取到TTS返回的路径path");
+ xiaoAiResponse = buildTextResponse(SORRY_REPEAT);
+ }
+// final String word = userWord;
+// DplbotServiceUtil.getPOOL().submit(() -> {
+// if (deviceId.equals(userId)) {
+// WebSocketLog.sendInfo(new StringBuilder(word).append(File.separator)
+// .append(response.getText()).toString(), "ai1");
+// } else {
+// WebSocketLog.sendInfo(new StringBuilder(word).append(File.separator)
+// .append(response.getText()).toString(), "ai2");
+// }
+// });
}
LAST_OUTTIME_RESULT.put(userId, xiaoAiResponse);
}
}
+
+ private String changeAudioUrl(String path, String userId) {
+ return new StringBuilder(TTS_DIDI3_GET_XIAOAI).append(userId).append("&path=").append(path).toString();
+ }
+
+ private String changeAudioUrlTemp(String path, String userId) {
+ path = path.replaceAll("%2F", "/");
+// return new StringBuilder(TTS_DIDI4_GET_XIAOAI_STATIC).append(path.substring(path.indexOf("audio")+6)).toString();
+ return new StringBuilder(TTS_DIDI4_GET_XIAOAI).append(userId).append("&path=").append(path).toString();
+ }
+
+ public void changeAudioPlayMark(String userId) {
+ LAST_AUDIO_PLAY.remove(userId);
+ }
+
+ public static void main(String[] args) {
+ System.out.println(Utils.modifyDeviceId("XIAOAI_nbNGwo/tZIS8A/mRGVqHog=="));
+// oIOWfYEFbZGFHB5DzoMA==;
+// oItOWfYEFbtZGFHB5DzoMA==
+ }
}
diff --git a/xiaoduhome/src/main/resources/application.yml b/xiaoduhome/src/main/resources/application.yml
index 2c15216..198d0aa 100755
--- a/xiaoduhome/src/main/resources/application.yml
+++ b/xiaoduhome/src/main/resources/application.yml
@@ -7,12 +7,17 @@ spring:
jdbc-url: jdbc:mysql://localhost:3306/game_editor_db?useUnicode=true&characterEncoding=utf-8&serverTimezone=Hongkong&useSSL=false
username: root
password: 38A0O1jEPOE
- driver-class-name: com.mysql.jdbc.Driver
+ driver-class-name: com.mysql.cj.jdbc.Driver
secondary:
jdbc-url: jdbc:mysql://localhost:3306/audiobox?useUnicode=true&characterEncoding=utf-8&serverTimezone=Hongkong&useSSL=false
username: root
password: 38A0O1jEPOE
- driver-class-name: com.mysql.jdbc.Driver
+ driver-class-name: com.mysql.cj.jdbc.Driver
+ analysis:
+ jdbc-url: jdbc:mysql://localhost:3306/analysis?useUnicode=true&characterEncoding=utf-8&serverTimezone=Hongkong&useSSL=false
+ username: root
+ password: 38A0O1jEPOE
+ driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
database: mysql
#控制台显示SQL
@@ -27,4 +32,6 @@ logging:
level:
root: info
okhttp3:
- OkHttpClient: FINE
\ No newline at end of file
+ OkHttpClient: FINE
+
+csvDic: /home/dc2-user/projects/audiobox/duai/csv/
\ No newline at end of file
diff --git a/xiaoduhome/src/main/resources/static/aligenie/0b6b193b8b26ae5875b6d4e4f69a4103.txt b/xiaoduhome/src/main/resources/static/aligenie/0b6b193b8b26ae5875b6d4e4f69a4103.txt
new file mode 100644
index 0000000..687e42a
--- /dev/null
+++ b/xiaoduhome/src/main/resources/static/aligenie/0b6b193b8b26ae5875b6d4e4f69a4103.txt
@@ -0,0 +1 @@
+Jfc4Z4Ur15JwUBuvUQD5wg7Nu8+l+HscqYlfofbyJdYGH+f3XrduI0FLgVW7gXyV
\ No newline at end of file
diff --git a/xiaoduhome/src/main/resources/static/aligenie/aliGenie-intent-sematic.jar b/xiaoduhome/src/main/resources/static/aligenie/aliGenie-intent-sematic.jar
new file mode 100644
index 0000000..27df896
Binary files /dev/null and b/xiaoduhome/src/main/resources/static/aligenie/aliGenie-intent-sematic.jar differ
diff --git a/xiaoduhome/src/main/resources/templates/0b6b193b8b26ae5875b6d4e4f69a4103.txt b/xiaoduhome/src/main/resources/templates/0b6b193b8b26ae5875b6d4e4f69a4103.txt
new file mode 100644
index 0000000..687e42a
--- /dev/null
+++ b/xiaoduhome/src/main/resources/templates/0b6b193b8b26ae5875b6d4e4f69a4103.txt
@@ -0,0 +1 @@
+Jfc4Z4Ur15JwUBuvUQD5wg7Nu8+l+HscqYlfofbyJdYGH+f3XrduI0FLgVW7gXyV
\ No newline at end of file
diff --git a/xiaoduhome/src/main/resources/templates/29eafc27fdf31dfc7feae0d495fb8ead.txt b/xiaoduhome/src/main/resources/templates/29eafc27fdf31dfc7feae0d495fb8ead.txt
new file mode 100644
index 0000000..d05d0aa
--- /dev/null
+++ b/xiaoduhome/src/main/resources/templates/29eafc27fdf31dfc7feae0d495fb8ead.txt
@@ -0,0 +1 @@
+Jfc4Z4Ur15JwUBuvUQD5wg7Nu8+l+HscqYlfofbyJdaEr7275aEMVjPWxwUQXYKO
\ No newline at end of file
diff --git a/xiaoduhome/src/main/resources/templates/567d9451c6f346cf203e6143455a6653.txt b/xiaoduhome/src/main/resources/templates/567d9451c6f346cf203e6143455a6653.txt
new file mode 100644
index 0000000..b55becc
--- /dev/null
+++ b/xiaoduhome/src/main/resources/templates/567d9451c6f346cf203e6143455a6653.txt
@@ -0,0 +1 @@
+Jfc4Z4Ur15JwUBuvUQD5wg7Nu8+l+HscqYlfofbyJdbWemsw1KjF/K5sTmFtefcK
\ No newline at end of file
diff --git a/xiaoduhome/src/main/resources/templates/648cbc29675eff7e6f337ffc66c907de.txt b/xiaoduhome/src/main/resources/templates/648cbc29675eff7e6f337ffc66c907de.txt
new file mode 100644
index 0000000..e30775e
--- /dev/null
+++ b/xiaoduhome/src/main/resources/templates/648cbc29675eff7e6f337ffc66c907de.txt
@@ -0,0 +1 @@
+Jfc4Z4Ur15JwUBuvUQD5wg7Nu8+l+HscqYlfofbyJdYl1WV0wUh0suAg2swzr9op
\ No newline at end of file
diff --git a/xiaoduhome/src/main/resources/templates/bc4751bfc694b4ac41ef56c6fadb8512.txt b/xiaoduhome/src/main/resources/templates/bc4751bfc694b4ac41ef56c6fadb8512.txt
new file mode 100644
index 0000000..20f66f9
--- /dev/null
+++ b/xiaoduhome/src/main/resources/templates/bc4751bfc694b4ac41ef56c6fadb8512.txt
@@ -0,0 +1 @@
+Jfc4Z4Ur15JwUBuvUQD5wg7Nu8+l+HscqYlfofbyJdYHaA0JQeSQDRWj5Va+HtGy
\ No newline at end of file
diff --git a/xiaoduhome/src/main/resources/templates/eae846c7d1ca51474ebc7230ace47bf2.txt b/xiaoduhome/src/main/resources/templates/eae846c7d1ca51474ebc7230ace47bf2.txt
new file mode 100644
index 0000000..21af354
--- /dev/null
+++ b/xiaoduhome/src/main/resources/templates/eae846c7d1ca51474ebc7230ace47bf2.txt
@@ -0,0 +1 @@
+Jfc4Z4Ur15JwUBuvUQD5wg7Nu8+l+HscqYlfofbyJdabUWNw9gpRzUrkhpgKK2YY
\ No newline at end of file
diff --git a/xiaoduhome/src/main/resources/templates/f282242afef97d009d90f7c360fb1882.txt b/xiaoduhome/src/main/resources/templates/f282242afef97d009d90f7c360fb1882.txt
new file mode 100644
index 0000000..6257e3b
--- /dev/null
+++ b/xiaoduhome/src/main/resources/templates/f282242afef97d009d90f7c360fb1882.txt
@@ -0,0 +1 @@
+Jfc4Z4Ur15JwUBuvUQD5wg7Nu8+l+HscqYlfofbyJdaEZbglH1ruVqu+Lzfq0fGo
\ No newline at end of file
diff --git a/xiaoduhome/src/main/resources/templates/index.html b/xiaoduhome/src/main/resources/templates/index.html
index b1b8a97..7a55629 100644
--- a/xiaoduhome/src/main/resources/templates/index.html
+++ b/xiaoduhome/src/main/resources/templates/index.html
@@ -9,10 +9,10 @@
-
+
-
+