Commit fc461663 by 苗权威

11.20

parent 2da3ac05
......@@ -114,6 +114,19 @@ public class Code {
}
}
public static boolean isMatch2(String s, String p) {
char[] sArr = s.toCharArray();
char[] pArr = p.toCharArray();
boolean[][] matrix = new boolean[sArr.length+1][pArr.length+1];
matrix[0][0] = true;
for (int j = 1; j <= pArr.length; j++) {
}
return true;
}
public static void main(String[] args) {
// // test 41
// System.out.println(firstMissingPso(new int[]{3, 4, -1, 1}));
......
......@@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<version>2.2.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>ai.qiwu.com</groupId>
......
......@@ -23,12 +23,12 @@ import java.util.concurrent.TimeUnit;
@Slf4j
public class OkHttp3Utils {
/**
* 客户端,超时时间设为15s
* 客户端,超时时间设为30s
*/
private static final OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(15, TimeUnit.SECONDS)
.readTimeout(15, TimeUnit.SECONDS)
.writeTimeout(20, TimeUnit.SECONDS)
.connectTimeout(45, TimeUnit.SECONDS)
.readTimeout(45, TimeUnit.SECONDS)
.writeTimeout(45, TimeUnit.SECONDS)
.build();
/**
......
package ai.qiwu.com.tts_service.controller;
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.Initialize;
......@@ -14,6 +15,8 @@ import org.springframework.web.multipart.MultipartHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import static ai.qiwu.com.tts_service.common.TTSConstants.TTS_REMOTE_ADDR;
......@@ -188,7 +191,10 @@ public class TTSController {
String botName = mulRequest.getParameter("botName");
String npcName = mulRequest.getParameter("npcName");
UploadOneSenData data = new UploadOneSenData(botName, npcName, file);
ttService.uploadOneNpc(data, response, request.getHeader("Authorization"));
final String result = ttService.uploadOneNpc(data, response, request.getHeader("Authorization"));
if (result != null) {
TTService.getPOOL().submit(() -> TTSUtils.deleteFile(new File(result)));
}
}
/**
......
......@@ -1541,7 +1541,7 @@ public class TTService {
* @param response
* @param head
*/
public void uploadOneNpc(UploadOneSenData data, HttpServletResponse response, String head) {
public String uploadOneNpc(UploadOneSenData data, HttpServletResponse response, String head) {
// audio_dir/botname/record/npcname
final String folder = StringUtils.join(new String[]{Initialize.getAudioDir(), data.getBotName(),
Initialize.getUploadedDir(), data.getNpcName()}, File.separator);
......@@ -1564,24 +1564,24 @@ public class TTService {
} catch (IOException e) {
log.error("写入上传文件出错:{}",ExceptionUtils.getStackTrace(e));
TTServiceUtil.buildUploadResponse(response, new TTSResponse(555, "写入上传文件出错:"+filename), 555);
return;
return zipFolder;
}
// 检查压缩包格式是否正确,标准是不含有目录
if (!TTSUtils.checkZipFile(filename)){
TTServiceUtil.buildUploadResponse(response, new TTSResponse(400, "压缩包结构不正确"), 400);
return;
return zipFolder;
}
// 解压
if (!TTSUtils.unZip(zipFolder, filename)) {
TTServiceUtil.buildUploadResponse(response, new TTSResponse(555, "压缩包解压失败"), 555);
return;
return zipFolder;
}
// 压缩包中之应该只含有一个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;
return zipFolder;
}
File csvFile = csvFiles[0];
// 判断该文件的编码
......@@ -1616,7 +1616,7 @@ public class TTService {
}
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 fileInPackage = zipFolder + File.separator + audioFileName;
String md5Name = TTSUtils.buildMP3Filename(record.get(1)); //构造mp3文件名
final String usFilename = new StringBuilder(folder).append(File.separator).append(md5Name).toString();
boolean doesFileExit = TTSUtils.doesFileExist(fileInPackage);
......@@ -1635,7 +1635,7 @@ public class TTService {
// 删除成功后删除其b64文件,且将压缩包中的文件移到安置目录下,即
// /root/TTS-service/mqwZip/audioFilename -> audio_dir/botname/record/npcname/xxx.mp3
if (result) {
needDeleteB64File.add(new StringBuilder(usFilename).append(".b64").toString());
needDeleteB64File.add(usFilename + ".b64");
try {
Files.copy(new File(fileInPackage).toPath(), usFile.toPath());
boolean bn = successUpLoadFileIds.add(record.get(0));
......@@ -1657,7 +1657,7 @@ public class TTService {
} catch (IOException e) {
log.error("解析csv文件出错:{}",ExceptionUtils.getStackTrace(e));
TTServiceUtil.buildUploadResponse(response, new TTSResponse(500, "程序出错"), 500);
return;
return zipFolder;
}
// CsvReader reader = null;
// try {
......@@ -1739,6 +1739,7 @@ public class TTService {
// }
// });
try {
log.info("打包上传成功id个数:{}",successUpLoadFileIds.size());
String requestCall = JSON.toJSONString(successUpLoadFileIds);
//log.info("requestCall:{}",requestCall);
HashMap<String, String> headers = new HashMap<>();
......@@ -1750,13 +1751,13 @@ public class TTService {
if (callbackResponse == null || callbackResponse.getCode() != 1) {
log.warn("打包上传回调返回信息:{}",str);
TTServiceUtil.buildUploadResponse(response, new TTSResponse(500, "打包上传回调出现错误"), 500);
return;
return zipFolder;
}
}
} catch (Exception e) {
log.error("打包上传回调出现错误:{}",ExceptionUtils.getStackTrace(e));
TTServiceUtil.buildUploadResponse(response, new TTSResponse(500, "打包上传回调出现错误,请确认下csv文件第四列是否全为空"), 500);
return;
return zipFolder;
}
POOL.submit(() -> {
TTSUtils.deleteFile(new File(zipFolder));
......@@ -1784,10 +1785,11 @@ public class TTService {
.append(repeate).append("; noeTextSameId:").append(noeTextSameId).append("; empty:"+empty).toString();
TTServiceUtil.buildUploadResponse(response, new TTSResponse(200, info), 200);
}
return;
return null;
}
TTServiceUtil.buildUploadResponse(response, new TTSResponse(200, "没有全部成功,失败的id有:"+failList), 200);
}
return null;
}
/**
......@@ -1869,4 +1871,7 @@ public class TTService {
TTServiceUtil.buildUploadResponse(response, new TTSResponse(200), 200);
}
public static ThreadPoolExecutor getPOOL() {
return POOL;
}
}
......@@ -14,6 +14,8 @@ import org.apache.commons.lang3.exception.ExceptionUtils;
import java.io.*;
import java.math.BigInteger;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.text.ParseException;
......@@ -221,18 +223,44 @@ public class Test {
System.out.println(TTSUtils.buildMP3Filename("回答错误,正确答案为 :黄河入海流。 当前体力值为 2"));
}
private static String cpRecordMp3() {
try {
String srcPath = "/home/yf01/下载/tts/bot1/record/";
File srcFile = new File(srcPath);
String destPath = "/home/yf01/下载/tts/bot2/record/";
if (srcFile.exists()) {
File destRecordPath = new File(destPath);
if (!destRecordPath.exists()) destRecordPath.mkdirs();
File[] npcNameDir = srcFile.listFiles();
if (npcNameDir == null || npcNameDir.length == 0) return "1";
for (File recordDic: npcNameDir) {
if (!recordDic.isDirectory()) continue;
String npcName = recordDic.getName();
String destNpcNameFolder = destPath+npcName+File.separator;
File destNpcNameFolderFile = new File(destNpcNameFolder);
if (!destNpcNameFolderFile.exists()) destNpcNameFolderFile.mkdir();
File[] npcNameMp3Files = recordDic.listFiles((dir, name) -> StringUtils.endsWith(name,".mp3"));
if (npcNameMp3Files == null || npcNameMp3Files.length == 0) return "2";
for (File file: npcNameMp3Files) {
Files.copy(file.toPath(), new File(destNpcNameFolder+file.getName()).toPath());
}
}
return "true";
}
} catch (Exception e) {
System.out.println(e);
}
return "3";
}
public static void main(String[] args) throws IOException, ParseException {
Date date = new Date(1572522571234L);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(format.format(date));
// BigInteger bigInteger = new BigInteger("1572522571");
// BigInteger[] mas = bigInteger.divideAndRemainder(new BigInteger("60"));
// BigInteger second = mas[1];
// BigInteger[] ham = mas[0].divideAndRemainder((new BigInteger("60")));
// BigInteger minute = ham[1];
// BigInteger hour = ham[0].remainder(new BigInteger("24"));
// System.out.println(hour+":"+minute+":"+second);
System.out.println(TTSUtils.buildMP3Filename("你看向铁塔,发现一个男人正站在斜塔的高处,手里拿着一大一小两个铁球,而你身边的人也在不断的议论纷纷,一个身穿褐色长袍的男人愤愤的说,"));
System.out.println(TTSUtils.buildMP3Filename("你看向铁塔,发现一个男人正站在斜塔的高处,手里拿着一大一小两个铁球,而你身边的人也在不断的议论纷纷,一个穿褐色长袍的男人愤愤的说,"));
List<String> paths = new ArrayList<>();
for (int i = 1; i < 6; i++) {
paths.add("/home/yf01/下载/tts/"+i+".mp3");
}
System.out.println(URLDecoder.decode("http://didi-gz4.jiaoyou365.com:9663/api/tts/get_audio?dirs=%5B39474830%2Crecord%2C%E6%9E%97%E8%80%81%E5%B8%88%5D&filename=2693006153fb900642c931d9304e650a.mp3"));
}
}
......@@ -28,6 +28,10 @@
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
......@@ -100,7 +104,6 @@
<artifactId>commons-csv</artifactId>
<version>1.7</version>
</dependency>
</dependencies>
<build>
......
......@@ -6,7 +6,8 @@ package ai.qiwu.com.xiaoduhome.common;
*/
public interface Constants {
String QI_WU_INTERFACE = "http://didi-gz5.jiaoyou365.com:8070/api/chat2";
String QI_WU_INTERFACE = "http://didi-gz4.jiaoyou365.com:8070/api/chat2";
String INTERFACE_DI = "http://didi-gz3.jiaoyou365.com:8070/api/chat2";
String SERVICE_NAME = "BAIDU";
String PRIVATE_KEY = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBANMWIYduiQZt0B7s" +
"IZ6PW15gpcO7Yn+9ZbaMSHwzJqNeDAZzh6HXF7r0ZpQcw3XEWKPAPWyuJ5eqZf46" +
......@@ -103,7 +104,7 @@ public interface Constants {
}
interface EndMsg {
String BYE_BYE = "我们的作品库在不断的扩充,下次会有更大的惊喜哦";
String BYE_BYE = "我们的作品库在不断的扩充,欢迎下次再来玩";
String CAN_NOT_UNDERSTAND = "用户无输入或多次输入无法理解";
String USER_SAY_CANCEL = "用户直接说退出";
}
......
......@@ -68,6 +68,7 @@ public class OkHttp3Utils {
Headers.Builder headBuilder = request.headers().newBuilder();
headBuilder.add("Content-Type", "application/json;charset=utf-8");
headBuilder.add("App-Channel-Id", "jiaoyou-audio-test");
// Iterator<Map.Entry<String, String>> headIterator = headers.entrySet().iterator();
// headIterator.forEachRemaining(e -> headBuilder.add(e.getKey(), e.getValue()));
......
package ai.qiwu.com.xiaoduhome.common.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
/**
* @author 苗权威
* @dateTime 19-11-18 下午5:51
*/
@Configuration
public class WebSocketConfig {
@Bean
public ServerEndpointExporter serverEndpointExporter() {
return new ServerEndpointExporter();
}
}
package ai.qiwu.com.xiaoduhome.controller;
import lombok.extern.slf4j.Slf4j;
import okhttp3.WebSocket;
import org.springframework.stereotype.Component;
import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* @author 苗权威
* @dateTime 19-11-18 下午5:34
*/
@ServerEndpoint("/webSocket/{username}")
@Component
@Slf4j
public class WebSocketLog {
private static Map<String, List<WebSocketLog>> clients = new ConcurrentHashMap<>();
//与某个客户端的连接会话,需要通过它来给客户端发送数据
private Session session;
@OnOpen
public void opOpen(@PathParam("username") String username, Session session) {
this.session = session;
List<WebSocketLog> logClients = clients.computeIfAbsent(username, k -> new ArrayList<>());
logClients.add(this);
}
@OnClose
public void onClose(@PathParam("username") String username) {
List<WebSocketLog> logClients = clients.get(username);
logClients.remove(this);
}
@OnMessage
public void onMessage(String message, Session session) {
// for (WebSocketLog item: webSocketLogs) {
// try {
// item.sendMessage(message);
// } catch (Exception e) {
// log.error("websocket onMessage出现错误:{}",e);
// }
// }
log.info("onMessage() called:"+message);
}
@OnError
public void onError(Session session, Throwable error) {
log.error("websocket出现错误"+error.toString());
}
/**
* 实现服务器主动推送
*/
private void sendMessage(String message) throws IOException {
this.session.getBasicRemote().sendText(message);
}
public static void sendInfo(String message, String userName) {
try {
for (WebSocketLog log: clients.get(userName)) {
log.sendMessage(message);
}
} catch (IOException e) {
log.error("log sendInfo 出现错误:{}",e);
}
}
}
package ai.qiwu.com.xiaoduhome.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
/**
* @author 苗权威
* @dateTime 19-11-18 下午6:37
*/
@Controller
public class WebSocketLogController {
// @GetMapping("/audio/webSocket/du")
// public String duLog(ModelMap modelMap) {
// return "Log";
// }
//
// @GetMapping("/audio/webSocket/aigz3")
// public String aigz3Log(ModelMap modelMap) {
// return "aigz3";
// }
//
// @GetMapping("/audio/webSocket/aigz4")
// public String aigz4Log(ModelMap modelMap) {
// return "aigz4";
// }
@GetMapping("/audio/index")
public String logIndexPage(ModelMap modelMap) {
return "index.html";
}
@GetMapping("/audio/Log1.html")
public String logduPage(ModelMap modelMap) {
return "Log1.html";
}
@GetMapping("/audio/Log2.html")
public String logai1Page(ModelMap modelMap) {
return "Log2.html";
}
@GetMapping("/audio/Log3.html")
public String logai2Page(ModelMap modelMap) {
return "Log3.html";
}
@GetMapping("/audio/Log4.html")
public String logdu2Page(ModelMap modelMap) {
return "Log4.html";
}
}
......@@ -7,6 +7,7 @@ import ai.qiwu.com.xiaoduhome.xiaoai.model.request.XiaoAiRequest;
import ai.qiwu.com.xiaoduhome.xiaoai.model.response.XiaoAiResponse;
import ai.qiwu.com.xiaoduhome.xiaoai.service.XiaoAiService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.*;
......@@ -39,7 +40,7 @@ public class XiaoDuHomeController {
public XiaoAiResponse xiaoai(@RequestBody XiaoAiRequest request) {
//log.info("请求:"+request);
XiaoAiResponse response = xiaoAiService.getResponse(request);
log.info("响应:"+response);
// log.info("响应:"+response);
return response;
// return xiaoAiService.getResponse(request);
}
......@@ -49,7 +50,8 @@ public class XiaoDuHomeController {
try {
//log.info("--------------分界线-------------------");
DplBotService service = new DplBotService(Utils.getHttpServletRequest());
//log.info("请求信息中的attributes:{}", service.getRequest().getSession().getAttributes());
log.info("请求信息中的attributes:{}", service.getRequest().getSession().getAttributes());
// log.info(service.getStrRequest());
//service.disableVerify();
service.enableVerify();
String str = service.run();
......
......@@ -46,6 +46,12 @@ public class AppFlowerTB {
@Column
private Integer status;
@Column(name = "channel_id")
private String channelId;
@Column(name = "workname")
private String workName;
@CreatedDate
@Column(name = "gmt_create", updatable = false, nullable = false)
private Timestamp createTime;
......
......@@ -57,6 +57,9 @@ public class XiaoDuOrderTB {
@Column(name = "status")
private Boolean status;
@Column
private Integer device;
@CreatedDate
@Column(name = "create_time", updatable = false, nullable = false)
private Timestamp createTime;
......
......@@ -12,7 +12,7 @@ import lombok.ToString;
@Setter
@ToString
public class QiWuRequest {
private String user_id;
private String text;
private String access;
private String uid;
private String msg;
// private String access;
}
......@@ -12,6 +12,5 @@ import lombok.ToString;
public class QiWuResponse {
private String audio;
private String text;
private String length;
private String aipioneerUsername;
}
......@@ -154,7 +154,7 @@ public class DplbotServiceUtil {
}
static ThreadPoolExecutor getPOOL() {
public static ThreadPoolExecutor getPOOL() {
return POOL;
}
......@@ -411,7 +411,7 @@ public class DplbotServiceUtil {
}
static boolean dealChargeCallback(ChargeEvent chargeEvent, final String userId, final String accessToken,
final String jytUserId) {
final String jytUserId, String workName, String channelId) {
Payload payload = chargeEvent.getPayload();
final String chOrderId = chargeEvent.getSellerOrderId();
String token = chargeEvent.getToken();
......@@ -435,12 +435,16 @@ public class DplbotServiceUtil {
}
try {
String appUserId = jytUserId;
if (appUserId == null) appUserId = getUsUserId(userId,accessToken);
if (appUserId == null) {
if (StringUtils.isBlank(jytUserId)) appUserId = getUsUserId(userId,accessToken);
if (StringUtils.isBlank(jytUserId)) {
log.error("像app_flower_tb中添加数据失败因为无法获取到用户的id,数据信息:botAccount:{},num:{},xiaoduUserId:{}",
botAccount,num,userId);
return;
}
if ("null".equals(jytUserId)) {
log.error("小度无屏在向app-flower_tb插入数据时没有获取到此用户登录的userID,数据信息:botAccount:{},num:{},xiaoduUserId:{}",
botAccount,num,userId);
}
AppFlowerTBRepository flower = BaseHolder.getBean("appFlowerTBRepository");
AppFlowerTB flowerTB = new AppFlowerTB();
flowerTB.setBotName(botAccount);
......@@ -450,6 +454,8 @@ public class DplbotServiceUtil {
flowerTB.setStatus(1);
flowerTB.setUnitPrice(Double.parseDouble(Config.getProperty("unitPrice", Constants.UNIT_PRICE))/100);
flowerTB.setUserId(appUserId);
flowerTB.setWorkName(workName);
flowerTB.setChannelId(channelId);
flower.save(flowerTB);
} catch (Exception e) {
log.error("像app_flower_tb中添加数据失败,{},数据信息:botAccount:{},num:{},xiaoduUserId:{}",
......
......@@ -24,22 +24,35 @@ class RequestTerminal {
static QiWuResponse requestTerminate(String userWord, String userId) throws IOException {
QiWuRequest requestPojo = new QiWuRequest();
requestPojo.setUser_id(userId);
requestPojo.setAccess(Constants.SERVICE_NAME);
requestPojo.setText(userWord);
requestPojo.setUid(userId);
// requestPojo.setAccess(Constants.SERVICE_NAME);
requestPojo.setMsg(userWord);
String requestJsonStr = JSON.toJSONString(requestPojo);
log.info("向小悟发送的请求信息:{}", requestJsonStr);
// log.info("向小悟发送的请求信息:{}", requestJsonStr);
String resStr = OkHttp3Utils.doPostJsonStr(Constants.QI_WU_INTERFACE, requestJsonStr);
if (resStr == null) return null;
log.info("返回信息:{}", resStr);
// log.info("返回信息:{}", resStr);
return JSON.parseObject(resStr, QiWuResponse.class);
}
static QiWuResponse requestTerminateDU2(String userWord, String userId) throws IOException {
QiWuRequest requestPojo = new QiWuRequest();
requestPojo.setUid(userId);
// requestPojo.setAccess(Constants.SERVICE_NAME);
requestPojo.setMsg(userWord);
String requestJsonStr = JSON.toJSONString(requestPojo);
// log.info("向小悟发送的请求信息:{}", requestJsonStr);
String resStr = OkHttp3Utils.doPostJsonStr(Constants.INTERFACE_DI, requestJsonStr);
if (resStr == null) return null;
// log.info("返回信息:{}", resStr);
return JSON.parseObject(resStr, QiWuResponse.class);
}
static void backRequest(String userId) {
QiWuRequest requestPojo = new QiWuRequest();
requestPojo.setUser_id(userId);
requestPojo.setAccess(Constants.SERVICE_NAME);
requestPojo.setText("退出");
requestPojo.setUid(userId);
// requestPojo.setAccess(Constants.SERVICE_NAME);
requestPojo.setMsg("退出");
String requestJsonStr = JSON.toJSONString(requestPojo);
OkHttp3Utils.backPostAsync(Constants.QI_WU_INTERFACE, requestJsonStr);
}
......
......@@ -251,11 +251,11 @@ public class ScheduleService implements InitializingBean {
}
private void tian(){
EXCEPT_BOT_ACCOUNT.add("682031219");
EXCEPT_BOT_ACCOUNT.add("963477460");
EXCEPT_BOT_ACCOUNT.add("9256014607");
EXCEPT_BOT_ACCOUNT.add("1778815830");
EXCEPT_BOT_ACCOUNT.add("4151097686");
EXCEPT_BOT_ACCOUNT.add("6823941516");
EXCEPT_BOT_ACCOUNT.add("2850282206");
EXCEPT_BOT_ACCOUNT.add("3528512723");
EXCEPT_BOT_ACCOUNT.add("743677363");
}
public static List<OnProductDetail> getRANK_ORDER_IDs() {
......
......@@ -26,13 +26,14 @@ public class RequestTerminal {
*/
public static QiWuResponse requestTerminate(String userId, String userWord) throws IOException {
QiWuRequest requestPojo = new QiWuRequest();
requestPojo.setUser_id(userId);
requestPojo.setAccess(XiaoAiConstants.DEVICE_NAME);
requestPojo.setText(userWord);
requestPojo.setUid(userId);
// requestPojo.setAccess(XiaoAiConstants.DEVICE_NAME);
requestPojo.setMsg(userWord);
String requestJsonStr = JSON.toJSONString(requestPojo);
//log.info("向终端发出请求的参数信息:{}", requestJsonStr);
HashMap<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json;charset=utf-8");
headers.put("App-Channel-Id", "jiaoyou-audio-test");
String resStr;
if (userId.equals(XiaoAiService.deviceId)) {
resStr = OkHttp3Utils.doPostJsonStr(XiaoAiConstants.QI_WU_TERMINATE_DIDI, requestJsonStr, headers);
......
......@@ -6,8 +6,8 @@ package ai.qiwu.com.xiaoduhome.xiaoai.common;
* @dateTime 19-7-5 下午8:56
*/
public interface XiaoAiConstants {
String QI_WU_TERMINATE_DIDI = "http://didi-gz2.jiaoyou365.com:8070/api/chat2";
String QI_WU_TERMINATE_nx2 = "http://didi-gz5.jiaoyou365.com:8070/api/chat2";
String QI_WU_TERMINATE_DIDI = "http://didi-gz3.jiaoyou365.com:8070/api/chat2";
String QI_WU_TERMINATE_nx2 = "http://didi-gz3.jiaoyou365.com:8070/api/chat2";
String DEVICE_NAME = "XIAOAI";
String CONTENT_TYPE = "application/json;charset=utf-8";
String PLAYBACK_NEARLY_FINISHED = "mediaplayer.playbacknearlyfinished";
......
......@@ -12,7 +12,7 @@ import lombok.ToString;
@Setter
@ToString
public class QiWuRequest {
private String user_id;
private String text;
private String access;
private String uid;
private String msg;
// private String access;
}
package ai.qiwu.com.xiaoduhome.xiaoai.service;
import ai.qiwu.com.xiaoduhome.controller.WebSocketLog;
import ai.qiwu.com.xiaoduhome.service.DplbotServiceUtil;
import ai.qiwu.com.xiaoduhome.xiaoai.common.*;
import ai.qiwu.com.xiaoduhome.xiaoai.model.QiWuResponse;
......@@ -11,8 +12,11 @@ import ai.qiwu.com.xiaoduhome.xiaoai.model.response.innerResponse.directive.Audi
import ai.qiwu.com.xiaoduhome.xiaoai.model.response.innerResponse.directive.Directive;
import ai.qiwu.com.xiaoduhome.xiaoai.model.response.innerResponse.toSpeak.ToSpeak;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.stereotype.Service;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
......@@ -41,7 +45,7 @@ public class XiaoAiService {
*/
private static final ConcurrentHashMap<String, XiaoAiResponse> LAST_OUTTIME_RESULT = new ConcurrentHashMap<>();
public static volatile String deviceId;
public static final String deviceId = "oIOWfYEFbZGFHB5DzoMA==";
/**
* 处理不同意图,type为0则说明是启动,为1则说明是会话进行中,为2则说明用户退出
......@@ -163,7 +167,10 @@ public class XiaoAiService {
* @return 响应信息
*/
private XiaoAiResponse dealWithLaunchRequest(XiaoAiRequest request) {
if (deviceId == null) deviceId = getUserId(request);
// if (deviceId == null) {
// deviceId = getUserId(request);
// log.info("didi-gz3 deviceId:"+deviceId);
// }
return buildTextResponse(XiaoAiConstants.TTS.WELCOME_WORD);
}
......@@ -177,10 +184,6 @@ public class XiaoAiService {
private XiaoAiResponse dealWithIntentRequest(XiaoAiRequest request, String userId) {
Boolean idle = request.getRequest().getNo_response();
if (idle != null && idle) {
XiaoAiResponse response = getLastResult(userId);
if (response != null) return response;
//log.info("用户没说话");
//return buildTextResponse(".");
try {
//log.info("开始等待");
Thread.sleep(1800);
......@@ -188,7 +191,11 @@ public class XiaoAiService {
} catch (InterruptedException e) {
log.warn("等待中断");
}
return buildTextResponse((new Random(47).nextInt() & 1) == 1 ? XiaoAiConstants.TTS.USER_IDLE :
XiaoAiResponse response = getLastResult(userId);
if (response != null) return response;
//log.info("用户没说话");
//return buildTextResponse(".");
return buildTextResponse((RandomUtils.nextInt() & 1) == 1 ? XiaoAiConstants.TTS.USER_IDLE :
XiaoAiConstants.TTS.ANOTHER_USER_IDLE);
}
XiaoAiResponse response = getLastResult(userId);
......@@ -265,7 +272,7 @@ public class XiaoAiService {
log.info("请求中没有带有用户的话");
throw new RequestWordNullException("user word can not be null");
}
log.info("用户说的话:{}", userWord);
log.info("小爱,用户说的话:{}", userWord);
QiWuResponse response;
try {
response = RequestTerminal.requestTerminate(userId, userWord);
......@@ -276,8 +283,19 @@ public class XiaoAiService {
if (response == null) {
xiaoAiResponse = buildTextResponse(SORRY_REPEAT);
} else {
log.info("小悟返回:{}", response);
xiaoAiResponse = buildAudioResponse(response.getAudio());
log.info("小爱,小悟返回:{}", response.getText());
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");
} else {
WebSocketLog.sendInfo(new StringBuilder(word).append(File.separator)
.append(response.getText()).toString(), "ai2");
}
});
}
LAST_OUTTIME_RESULT.put(userId, xiaoAiResponse);
}
......
server:
port: 8088
port: 8188
spring:
datasource:
......
This source diff could not be displayed because it is too large. You can view the blob instead.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>音箱日志</title>
<script>
var socket;
if(typeof(WebSocket) == "undefined") {
console.log("您的浏览器不支持WebSocket");
}else{
console.log("您的浏览器支持WebSocket");
//实现化WebSocket对象,指定要连接的服务器地址与端口 建立连接
//等同于socket = new WebSocket("ws://localhost:8083/checkcentersys/websocket/20");
// socket = new WebSocket("${basePath}webSocket/${username}".replace("https","ws"));
socket = new WebSocket("ws://didi-gz4.jiaoyou365.com:8188/webSocket/du");
//打开事件
socket.onopen = function() {
console.log("Socket 已打开");
//socket.send("这是来自客户端的消息" + location.href + new Date());
};
//获得消息事件
socket.onmessage = function(msg) {
console.log(msg.data);
//发现消息进入 开始处理前端触发逻辑
};
//关闭事件
socket.onclose = function() {
console.log("Socket已关闭");
};
//发生了错误事件
socket.onerror = function() {
alert("Socket发生了错误");
//此时可以尝试刷新页面
}
//离开页面时,关闭socket
//jquery1.8中已经被废弃,3.0中已经移除
// $(window).unload(function(){
// socket.close();
//});
}
</script>
</head>
<body>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>音箱日志(小度)</title>
<!--<link rel="stylesheet" href="../static/layui.css">-->
<link rel="stylesheet" type="text/css" th:href="@{/layui.css}">
<script th:src="@{/vue.js}"></script>
</head>
<body>
<div id="app">
<div class="mainbox" id="mainbox">
<div v-for="item in datalist">
<p class=" one_tack ai">{{item.ai}}</p>
<p class="one_tack self">{{item.self}}</p>
</div>
</div>
</div>
</body>
<script>
var app = new Vue({
el: '#app',
data: {
seen: "131",
datalist: [
{
ai: "",
self: ""
}
]
},
methods: {
},
mounted: function () {
let that = this;
var socket;
if (typeof (WebSocket) == "undefined") {
console.log("您的浏览器不支持WebSocket");
} else {
console.log("您的浏览器支持WebSocket");
//实现化WebSocket对象,指定要连接的服务器地址与端口 建立连接
//等同于socket = new WebSocket("ws://localhost:8083/checkcentersys/websocket/20");
// socket = new WebSocket("${basePath}webSocket/${username}".replace("https","ws"));
socket = new WebSocket("ws://didi-gz4.jiaoyou365.com:8188/webSocket/du1"); //小度
// socket = new WebSocket("ws://didi-gz4.jiaoyou365.com:8188/webSocket/aigz3"); //小度
// // socket = new WebSocket("ws://didi-gz4.jiaoyou365.com:8188/webSocket/aigz4"); //小度
//打开事件
socket.onopen = function () {
console.log("Socket 已打开");
//socket.send("这是来自客户端的消息" + location.href + new Date());
};
//获得消息事件
socket.onmessage = function (msg) {
let obj = {
ai: "",
self: ""
}
let arr = msg.data.split("/");
obj.ai = arr[0];
obj.self = arr[1];
that.datalist.push(obj);
var div = document.getElementById('mainbox');
div.scrollTop = div.scrollHeight;
console.log(msg.data);
console.log(this.alldata);
//发现消息进入 开始处理前端触发逻辑
};
//关闭事件
socket.onclose = function () {
console.log("Socket已关闭");
};
//发生了错误事件
socket.onerror = function () {
alert("Socket发生了错误");
//此时可以尝试刷新页面
}
//离开页面时,关闭socket
//jquery1.8中已经被废弃,3.0中已经移除
// $(window).unload(function(){
// socket.close();
//});
}
}
})
</script>
<style>
.mainbox {
width: 500px;
height: auto;
border: 1px solid black;
display: flex;
flex-direction: column;
margin: 100px auto;
padding: 20px;
}
.ai {
color: green;
}
.one_tack {
margin-top: 10;
}
</style>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>音箱日志(小爱1号gz3)</title>
<!--<link rel="stylesheet" href="../static/layui.css">-->
<!--<script src="./static/vue.js"></script>-->
<link rel="stylesheet" type="text/css" th:href="@{/layui.css}">
<script th:src="@{/vue.js}"></script>
</head>
<body>
<div id="app">
<div class="mainbox" id="mainbox">
<div v-for="item in datalist">
<p class=" one_tack ai">{{item.ai}}</p>
<p class="one_tack self">{{item.self}}</p>
</div>
</div>
</div>
</body>
<script>
var app = new Vue({
el: '#app',
data: {
seen: "131",
datalist: [
{
ai: "",
self: ""
}
]
},
methods: {
},
mounted: function () {
let that = this;
var socket;
if (typeof (WebSocket) == "undefined") {
console.log("您的浏览器不支持WebSocket");
} else {
console.log("您的浏览器支持WebSocket");
//实现化WebSocket对象,指定要连接的服务器地址与端口 建立连接
//等同于socket = new WebSocket("ws://localhost:8083/checkcentersys/websocket/20");
// socket = new WebSocket("${basePath}webSocket/${username}".replace("https","ws"));
// socket = new WebSocket("ws://didi-gz4.jiaoyou365.com:8188/webSocket/du"); //小度
socket = new WebSocket("ws://didi-gz4.jiaoyou365.com:8188/webSocket/ai1"); //小度
// socket = new WebSocket("ws://didi-gz4.jiaoyou365.com:8188/webSocket/aigz4"); //小度
//打开事件
socket.onopen = function () {
console.log("Socket 已打开");
//socket.send("这是来自客户端的消息" + location.href + new Date());
};
//获得消息事件
socket.onmessage = function (msg) {
let obj = {
ai: "",
self: ""
}
let arr = msg.data.split("/");
obj.ai = arr[0];
obj.self = arr[1];
that.datalist.push(obj);
var div = document.getElementById('mainbox');
div.scrollTop = div.scrollHeight;
console.log(msg.data);
console.log(this.alldata);
//发现消息进入 开始处理前端触发逻辑
};
//关闭事件
socket.onclose = function () {
console.log("Socket已关闭");
};
//发生了错误事件
socket.onerror = function () {
alert("Socket发生了错误");
//此时可以尝试刷新页面
}
//离开页面时,关闭socket
//jquery1.8中已经被废弃,3.0中已经移除
// $(window).unload(function(){
// socket.close();
//});
}
}
})
</script>
<style>
.mainbox {
width: 500px;
height: auto;
border: 1px solid black;
display: flex;
flex-direction: column;
margin: 100px auto;
padding: 20px;
}
.ai {
color: green;
}
.one_tack {
margin-top: 10px;
}
</style>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>音箱日志(小爱2号gz3)</title>
<!--<link rel="stylesheet" href="../static/layui.css">-->
<!--<script src="./static/vue.js"></script>-->
<link rel="stylesheet" type="text/css" th:href="@{/layui.css}">
<script th:src="@{/vue.js}"></script>
</head>
<body>
<div id="app">
<div class="mainbox" id="mainbox" >
<div v-for="item in datalist">
<p class=" one_tack ai">{{item.ai}}</p>
<p class="one_tack self">{{item.self}}</p>
</div>
</div>
</div>
</body>
<script>
var app = new Vue({
el: '#app',
data: {
seen: "131",
datalist: [
{
ai: "",
self: ""
}
]
},
methods: {
},
mounted: function () {
let that = this;
var socket;
if (typeof (WebSocket) == "undefined") {
console.log("您的浏览器不支持WebSocket");
} else {
console.log("您的浏览器支持WebSocket");
//实现化WebSocket对象,指定要连接的服务器地址与端口 建立连接
//等同于socket = new WebSocket("ws://localhost:8083/checkcentersys/websocket/20");
// socket = new WebSocket("${basePath}webSocket/${username}".replace("https","ws"));
// socket = new WebSocket("ws://didi-gz4.jiaoyou365.com:8188/webSocket/du"); //小度
// socket = new WebSocket("ws://didi-gz4.jiaoyou365.com:8188/webSocket/aigz3"); //小度
socket = new WebSocket("ws://didi-gz4.jiaoyou365.com:8188/webSocket/ai2"); //小度
//打开事件
socket.onopen = function () {
console.log("Socket 已打开");
//socket.send("这是来自客户端的消息" + location.href + new Date());
};
//获得消息事件
socket.onmessage = function (msg) {
let obj = {
ai: "",
self: ""
}
let arr = msg.data.split("/");
obj.ai = arr[0];
obj.self = arr[1];
that.datalist.push(obj);
var div = document.getElementById('mainbox');
div.scrollTop = div.scrollHeight;
console.log(msg.data);
console.log(this.alldata);
//发现消息进入 开始处理前端触发逻辑
};
//关闭事件
socket.onclose = function () {
console.log("Socket已关闭");
};
//发生了错误事件
socket.onerror = function () {
alert("Socket发生了错误");
//此时可以尝试刷新页面
}
//离开页面时,关闭socket
//jquery1.8中已经被废弃,3.0中已经移除
// $(window).unload(function(){
// socket.close();
//});
}
}
})
</script>
<style>
.mainbox {
width: 500px;
height: auto;
border: 1px solid black;
display: flex;
flex-direction: column;
margin: 100px auto;
padding: 20px;
}
.ai {
color: green;
}
.one_tack {
margin-top: 10;
}
</style>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>音箱日志(小度2号gz4)</title>
<!--<link rel="stylesheet" href="../static/layui.css">-->
<!--<script src="./static/vue.js"></script>-->
<link rel="stylesheet" type="text/css" th:href="@{/layui.css}">
<script th:src="@{/vue.js}"></script>
</head>
<body>
<div id="app">
<div class="mainbox" id="mainbox" >
<div v-for="item in datalist">
<p class=" one_tack ai">{{item.ai}}</p>
<p class="one_tack self">{{item.self}}</p>
</div>
</div>
</div>
</body>
<script>
var app = new Vue({
el: '#app',
data: {
seen: "131",
datalist: [
{
ai: "",
self: ""
}
]
},
methods: {
},
mounted: function () {
let that = this;
var socket;
if (typeof (WebSocket) == "undefined") {
console.log("您的浏览器不支持WebSocket");
} else {
console.log("您的浏览器支持WebSocket");
//实现化WebSocket对象,指定要连接的服务器地址与端口 建立连接
//等同于socket = new WebSocket("ws://localhost:8083/checkcentersys/websocket/20");
// socket = new WebSocket("${basePath}webSocket/${username}".replace("https","ws"));
// socket = new WebSocket("ws://didi-gz4.jiaoyou365.com:8188/webSocket/du"); //小度
// socket = new WebSocket("ws://didi-gz4.jiaoyou365.com:8188/webSocket/aigz3"); //小度
socket = new WebSocket("ws://didi-gz4.jiaoyou365.com:8188/webSocket/du2"); //小度
//打开事件
socket.onopen = function () {
console.log("Socket 已打开");
//socket.send("这是来自客户端的消息" + location.href + new Date());
};
//获得消息事件
socket.onmessage = function (msg) {
let obj = {
ai: "",
self: ""
}
let arr = msg.data.split("/");
obj.ai = arr[0];
obj.self = arr[1];
that.datalist.push(obj);
var div = document.getElementById('mainbox');
div.scrollTop = div.scrollHeight;
console.log(msg.data);
console.log(this.alldata);
//发现消息进入 开始处理前端触发逻辑
};
//关闭事件
socket.onclose = function () {
console.log("Socket已关闭");
};
//发生了错误事件
socket.onerror = function () {
alert("Socket发生了错误");
//此时可以尝试刷新页面
}
//离开页面时,关闭socket
//jquery1.8中已经被废弃,3.0中已经移除
// $(window).unload(function(){
// socket.close();
//});
}
}
})
</script>
<style>
.mainbox {
width: 500px;
height: auto;
border: 1px solid black;
display: flex;
flex-direction: column;
margin: 100px auto;
padding: 20px;
}
.ai {
color: green;
}
.one_tack {
margin-top: 10;
}
</style>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
var socket;
if(typeof(WebSocket) == "undefined") {
console.log("您的浏览器不支持WebSocket");
}else{
console.log("您的浏览器支持WebSocket");
//实现化WebSocket对象,指定要连接的服务器地址与端口 建立连接
//等同于socket = new WebSocket("ws://localhost:8083/checkcentersys/websocket/20");
// socket = new WebSocket("${basePath}webSocket/${username}".replace("https","ws"));
socket = new WebSocket("ws://didi-gz4.jiaoyou365.com:8188/webSocket/aigz3");
//打开事件
socket.onopen = function() {
console.log("Socket 已打开");
//socket.send("这是来自客户端的消息" + location.href + new Date());
};
//获得消息事件
socket.onmessage = function(msg) {
console.log(msg.data);
//发现消息进入 开始处理前端触发逻辑
};
//关闭事件
socket.onclose = function() {
console.log("Socket已关闭");
};
//发生了错误事件
socket.onerror = function() {
alert("Socket发生了错误");
//此时可以尝试刷新页面
}
//离开页面时,关闭socket
//jquery1.8中已经被废弃,3.0中已经移除
// $(window).unload(function(){
// socket.close();
//});
}
</script>
</head>
<body>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
var socket;
if(typeof(WebSocket) == "undefined") {
console.log("您的浏览器不支持WebSocket");
}else{
console.log("您的浏览器支持WebSocket");
//实现化WebSocket对象,指定要连接的服务器地址与端口 建立连接
//等同于socket = new WebSocket("ws://localhost:8083/checkcentersys/websocket/20");
// socket = new WebSocket("${basePath}webSocket/${username}".replace("https","ws"));
socket = new WebSocket("ws://didi-gz4.jiaoyou365.com:8188/webSocket/aigz4");
//打开事件
socket.onopen = function() {
console.log("Socket 已打开");
//socket.send("这是来自客户端的消息" + location.href + new Date());
};
//获得消息事件
socket.onmessage = function(msg) {
console.log(msg.data);
//发现消息进入 开始处理前端触发逻辑
};
//关闭事件
socket.onclose = function() {
console.log("Socket已关闭");
};
//发生了错误事件
socket.onerror = function() {
alert("Socket发生了错误");
//此时可以尝试刷新页面
}
//离开页面时,关闭socket
//jquery1.8中已经被废弃,3.0中已经移除
// $(window).unload(function(){
// socket.close();
//});
}
</script>
</head>
<body>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>音响测试</title>
<link rel="stylesheet" type="text/css" th:href="@{/layui.css}">
</head>
<body>
<div class="mainbox">
<button type="button" class="layui-btn button " id="one">小度1号 (gz4)</button>
<button type="button" class="layui-btn button " id="four">小度2号 (gz3)</button>
<button type="button" class="layui-btn button " id="tow">小爱1号(gz3)</button>
<button type="button" class="layui-btn button " id="therr">小爱2号(gz3)</button>
</div>
</body>
<style>
.mainbox{
width: 300px;
height: 200px;
margin: 100px auto;
display: flex;
flex-direction: row;
}
button{
flex: 1;
}
</style>
<script>
var one = document.getElementById("one");
var tow = document.getElementById("tow");
var therr = document.getElementById("therr");
var four = document.getElementById("four");
one.onclick = function(){
console.log("点击事件");
window.open("./Log1.html","_blank");
};
tow.onclick = function(){
console.log("点击事件");
window.open("./Log2.html","_blank");
};
therr.onclick = function(){
console.log("点击事件");
window.open("./Log3.html","_blank");
};
four.onclick = function(){
console.log("点击事件");
window.open("./Log4.html","_blank");
}
</script>
</html>
\ No newline at end of file
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