增加LAC、语音合成方案配置

This commit is contained in:
wulin 2023-10-20 14:29:00 +08:00
parent 8a84450b5d
commit cd8c4fc347
12 changed files with 63 additions and 27 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

View File

@ -10,8 +10,8 @@ public class ChineseDateTimeUtils {
* @param c 时间字符串
* @return
*/
public static LocalDateTime getDateWithCode(String c){
return getDateWithCodeAndLocalDateTime(c, LocalDateTime.now(), 0, 0);
public static LocalDateTime getDateWithString(String c){
return getDateTime(c.replace("", ""), LocalDateTime.now(), 0, 0);
}
private static int checkDayOfMonth(LocalDateTime localDateTime, int i){
@ -47,7 +47,7 @@ public class ChineseDateTimeUtils {
int i = checkDayOfMonth(localDateTime, ChineseToAlaboUtils.getLong(c.substring(0, index)).intValue());
return getDateWithCodeAndLocalDateTime(
return getDateTime(
c.substring(index + key.length()),
localDateTime.withDayOfMonth(i).withHour(0).withMinute(0).withSecond(0),
ampm,
@ -93,8 +93,8 @@ public class ChineseDateTimeUtils {
* @param localDateTime 时间基础
* @return
*/
public static LocalDateTime getDateWithCodeAndLocalDateTime(String c, LocalDateTime localDateTime){
return getDateWithCodeAndLocalDateTime(c, localDateTime, 0, 0);
public static LocalDateTime getDateWithStringAndLocalDateTime(String c, LocalDateTime localDateTime){
return getDateTime(c.replace("", ""), localDateTime, 0, 0);
}
/**
* 汉语时间字符串转时间
@ -104,14 +104,18 @@ public class ChineseDateTimeUtils {
* @param type 0无感 1 2 3
* @return
*/
public static LocalDateTime getDateWithCodeAndLocalDateTime(String c, LocalDateTime localDateTime, int ampm, int type){
public static LocalDateTime getDateWithStringAndLocalDateTime(String c, LocalDateTime localDateTime, int ampm, int type){
return getDateTime(c.replace("", ""), localDateTime, ampm, type);
}
private static LocalDateTime getDateTime(String c, LocalDateTime localDateTime, int ampm, int type){
DateEnum dateEnu = null;
for(DateEnum enum1 : DateEnum.values()){
if(c.startsWith(enum1.getCode())){
dateEnu = enum1;
localDateTime = dateEnu.getDateTime(localDateTime);
c = c.substring(enum1.getCode().length());
localDateTime = getDateWithCodeAndLocalDateTime(c, localDateTime, dateEnu.getAmPm(), 0);
localDateTime = getDateTime(c, localDateTime, dateEnu.getAmPm(), 0);
break;
}
}
@ -264,7 +268,7 @@ public class ChineseDateTimeUtils {
private static LocalDateTime setYear(String c, String key, LocalDateTime localDateTime, int ampm) {
int index = c.indexOf(key);
int i = ChineseToAlaboUtils.getLong(c.substring(0, index)).intValue();
return getDateWithCodeAndLocalDateTime(
return getDateTime(
c.substring(index + key.length()),
localDateTime.withYear(i),
ampm,
@ -305,7 +309,7 @@ public class ChineseDateTimeUtils {
private static LocalDateTime setMonth(String c, String key, LocalDateTime localDateTime, int ampm) {
int index = c.indexOf(key);
int i = checkMonth(ChineseToAlaboUtils.getLong(c.substring(0, index)).intValue());
return getDateWithCodeAndLocalDateTime(
return getDateTime(
c.substring(index + key.length()),
localDateTime.withMonth(i),
ampm,
@ -324,7 +328,7 @@ public class ChineseDateTimeUtils {
private static LocalDateTime setMinute(String c, String key, LocalDateTime localDateTime, int ampm) {
int index = c.indexOf(key);
int i = checkMinuteAndSecond(ChineseToAlaboUtils.getLong(c.substring(0, index)).intValue());
return getDateWithCodeAndLocalDateTime(
return getDateTime(
c.substring(index + key.length()),
localDateTime.withMinute(i),
ampm,
@ -352,7 +356,7 @@ public class ChineseDateTimeUtils {
localDateTime = localDateTime.plusDays(1);
}
}
return getDateWithCodeAndLocalDateTime(
return getDateTime(
c.substring(index + key.length()),
localDateTime.withHour(i).withMinute(0).withSecond(0),
ampm,

View File

@ -99,4 +99,8 @@ public class DeviceUserBindEntity extends GenericEntity<Long> {
@Column(name = "scence_id", length = 11)
private Long scenceId;
@Comment("语音合成音色标识")
@Column(name = "tts", length = 11)
private String tts;
}

View File

@ -79,5 +79,10 @@ public class DeviceUserBindRequest implements java.io.Serializable {
*/
private Integer onLine;
/**
* 语音合成音色标识
*/
private String tts;
}

View File

@ -35,6 +35,7 @@ public class DeviceUserBindResp {
categoryCode = entity.getCategoryCode();
u3dId = entity.getU3dId();
scenceId = entity.getScenceId();
tts = entity.getTts();
}
//
private Long id;
@ -92,4 +93,10 @@ public class DeviceUserBindResp {
* 最后离线时间
*/
private Date lastOffLineTime;
/**
* 语音合成音色标识
*/
private String tts;
}

View File

@ -109,6 +109,9 @@ public class DeviceUserBindService extends GenericReactiveCrudService<DeviceUser
if(request.getScenceId() != null){
reactiveQuery = reactiveQuery.and(DeviceUserBindRequest::getScenceId, request.getScenceId());
}
if(StringUtils.isNotEmpty(request.getTts())){
reactiveQuery = reactiveQuery.and(DeviceUserBindRequest::getTts, request.getTts());
}
SortOrder sortOrder = null;
if(StringUtils.isNotEmpty(request.getOrder())){
if(StringUtils.isNotEmpty(request.getSort()) && request.getSort().compareTo("0") == 0){
@ -200,6 +203,9 @@ public class DeviceUserBindService extends GenericReactiveCrudService<DeviceUser
if(request.getScenceId() != null){
reactiveQuery = reactiveQuery.and(DeviceUserBindRequest::getScenceId, request.getScenceId());
}
if(StringUtils.isNotEmpty(request.getTts())){
reactiveQuery = reactiveQuery.and(DeviceUserBindRequest::getTts, request.getTts());
}
QueryParamEntity param = QueryParamEntity.of(reactiveQuery.getParam());
if(StringUtils.isNotEmpty(request.getOrder())){
Sort sort = new Sort();
@ -295,6 +301,9 @@ public class DeviceUserBindService extends GenericReactiveCrudService<DeviceUser
if(entity.getScenceId() != null){
update = update.set(DeviceUserBindEntity::getScenceId, entity.getScenceId());
}
if(StringUtils.isNotEmpty(entity.getTts())){
update = update.set(DeviceUserBindEntity::getTts, entity.getTts());
}
return update.where(DeviceUserBindEntity::getId, entity.getId()).and("is_delete", 0).execute();
}
@ -321,6 +330,7 @@ public class DeviceUserBindService extends GenericReactiveCrudService<DeviceUser
update = update.set(DeviceUserBindEntity::getCategoryCode, entity.getCategoryCode());
update = update.set(DeviceUserBindEntity::getU3dId, entity.getU3dId());
update = update.set(DeviceUserBindEntity::getScenceId, entity.getScenceId());
update = update.set(DeviceUserBindEntity::getTts, entity.getTts());
return update.where(DeviceUserBindEntity::getId, entity.getId()).and("is_delete", 0).execute();
}

View File

@ -1,15 +1,11 @@
package com.qiuguo.iot.third.nlp.action;
import com.qiuguo.iot.base.date.DateEnum;
import com.qiuguo.iot.base.utils.ChineseDateTimeUtils;
import com.qiuguo.iot.base.utils.ChineseToAlaboUtils;
import com.qiuguo.iot.base.utils.StringUtils;
import lombok.Data;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;
@Data
public class ActionTime {
@ -52,7 +48,7 @@ public class ActionTime {
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
DateTimeFormatter df1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
localDateTime = ChineseDateTimeUtils.getDateWithCodeAndLocalDateTime(t, localDateTime);
localDateTime = ChineseDateTimeUtils.getDateWithStringAndLocalDateTime(t, localDateTime);
detailTime = localDateTime;
dateTime = localDateTime.format(df);
dateDetailTime = localDateTime.format(df1);

View File

@ -62,8 +62,10 @@ public class LacNlpService implements INlp {
@Override
public Mono<Nlp> geSingletNlp(String value) {
return getHubFaLac(value);
if(SpringUtil.getProperty("lac.type").equals("suanfa")){
return getHubFaLac(value);
}
return getSuanFaLac(value);
}
/**

View File

@ -1,6 +1,7 @@
package com.qiuguo.iot.user.api.controller.device;
import cn.hutool.crypto.digest.MD5;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.qiuguo.iot.base.constans.RedisConstans;
@ -164,8 +165,8 @@ public class DeviceController {
}
pagerResult.setData(list);
return pagerResult;
});
}

View File

@ -99,14 +99,15 @@ public class LogWebFilter implements WebFilter {
joinBuffer.read(returnContent);
DataBufferUtils.release(joinBuffer);
String returnStr = new String(returnContent, StandardCharsets.UTF_8);
log.info("response:{}", returnStr);
log.info("flux response:{}", returnStr);
return response.bufferFactory().wrap(returnContent);
}));
}else if(body instanceof Mono){
Mono<DataBuffer> monoBody = Mono.from(body);
return super.writeWith(monoBody.map(dataBuffer -> {
log.info("response:{}", dataBuffer.toString(StandardCharsets.UTF_8));
return response.bufferFactory().wrap(dataBuffer.toString(StandardCharsets.UTF_8).getBytes());
String returnStr = dataBuffer.toString(StandardCharsets.UTF_8);
log.info("mono response:{}", returnStr);
return response.bufferFactory().wrap(returnStr.getBytes());
}));
}
return super.writeWith(body);

View File

@ -44,6 +44,7 @@ import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.reactive.socket.WebSocketSession;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;
@ -89,6 +90,9 @@ public class BaseWebSocketProcess {
@Autowired
AudioService audioService;
@Value("${tts.suanfa")
Boolean ttsSuanfa;
@Autowired
protected SystemTalkBindU3dService systemTalkBindU3dService;
@ -672,20 +676,19 @@ public class BaseWebSocketProcess {
}
private void sendMsg(BaseSession baseSession, BaseMessageResp baseMessageResp) {
sendMsg(baseSession, JSONObject.toJSONString(baseMessageResp));
/* if(this instanceof BoxWebSocketHandler){
if(ttsSuanfa && this instanceof BoxWebSocketHandler){
audioService.getAudioUrl(baseMessageResp.getText()).map(s ->{
log.info("音频地址:{}", s);
BoxMessageResp boxMessageResp = new BoxMessageResp();
BeanUtils.copyProperties(baseMessageResp, boxMessageResp);
boxMessageResp.setAudio(s);
sendMsg(baseSession, JSONObject.toJSONString(boxMessageResp));======
sendMsg(baseSession, JSONObject.toJSONString(boxMessageResp));
return s;
}).subscribeOn(Schedulers.single()).subscribe();
}else{
sendMsg(baseSession, JSONObject.toJSONString(baseMessageResp));
}*/
}
}
private void sendMsg(BaseSession baseSession, String msg) {

View File

@ -40,7 +40,10 @@ tianqiapi:
qiuguo:
checktoken:
url: https://exper.qiuguojihua.com/data/api.auth.center/get
tts:
suanfa: true
lac:
type: suanfa
hub:
url: http://192.168.8.175:8866/predict/lac
suanfa: