Commit 8eea4ec4 by 苗权威

11.03

parent cc5cc11e
<component name="libraryTable">
<library name="Maven: com.alibaba.nls:nls-sdk-common:2.1.9">
<CLASSES>
<root url="jar://$PROJECT_DIR$/../../../../maven/myRepository/com/alibaba/nls/nls-sdk-common/2.1.9/nls-sdk-common-2.1.9.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$PROJECT_DIR$/../../../../maven/myRepository/com/alibaba/nls/nls-sdk-common/2.1.9/nls-sdk-common-2.1.9-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$PROJECT_DIR$/../../../../maven/myRepository/com/alibaba/nls/nls-sdk-common/2.1.9/nls-sdk-common-2.1.9-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="Maven: com.alibaba.nls:nls-sdk-tts:2.1.9">
<CLASSES>
<root url="jar://$PROJECT_DIR$/../../../../maven/myRepository/com/alibaba/nls/nls-sdk-tts/2.1.9/nls-sdk-tts-2.1.9.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$PROJECT_DIR$/../../../../maven/myRepository/com/alibaba/nls/nls-sdk-tts/2.1.9/nls-sdk-tts-2.1.9-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$PROJECT_DIR$/../../../../maven/myRepository/com/alibaba/nls/nls-sdk-tts/2.1.9/nls-sdk-tts-2.1.9-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="Maven: io.netty:netty-codec-http:4.1.49.Final">
<CLASSES>
<root url="jar://$PROJECT_DIR$/../../../../maven/myRepository/io/netty/netty-codec-http/4.1.49.Final/netty-codec-http-4.1.49.Final.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$PROJECT_DIR$/../../../../maven/myRepository/io/netty/netty-codec-http/4.1.49.Final/netty-codec-http-4.1.49.Final-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$PROJECT_DIR$/../../../../maven/myRepository/io/netty/netty-codec-http/4.1.49.Final/netty-codec-http-4.1.49.Final-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
......@@ -134,6 +134,12 @@
<artifactId>commons-csv</artifactId>
<version>1.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba.nls/nls-sdk-tts -->
<dependency>
<groupId>com.alibaba.nls</groupId>
<artifactId>nls-sdk-tts</artifactId>
<version>2.1.9</version>
</dependency>
<!--&lt;!&ndash; https://mvnrepository.com/artifact/com.baidubce/bce-java-sdk &ndash;&gt;-->
<!--<dependency>-->
<!--<groupId>com.baidubce</groupId>-->
......
......@@ -47,9 +47,9 @@ public interface TTSConstants {
}
interface TENCENT_PROFESSION_TTS_ID {
String APP_ID = "1304075838";
String SECRET_ID = "AKIDjfMnytjxiFXa9UEs61hcIn4Zs0tc5ui0";
String SECRET_KEY = "DqQkqcBWbU8oEPay96OSTEi1OVOegU0p";
// String APP_ID = "1259060820";
String SECRET_ID = "AKID60nOmwBqTr3JmzweR2MS9TaS6zh9pEyV";
String SECRET_KEY = "ReptlPxIRHuPkrmZ9VvondRNTnxtpX6R";
}
interface XUN_FEI_TTS {
......@@ -59,6 +59,11 @@ public interface TTSConstants {
String API_KEY = "67596108f05733619d9866badb030234";
}
interface ALI_TTS {
String ACCESS_KEY_ID = "";
String ACCESS_KEY_SECRET = "";
}
interface Audio {
String XIAOAI = "XIAOAI";
String XIAODU = "XIAODU";
......
......@@ -694,6 +694,68 @@ public class TTSUtils {
});
}
public static void thirdSoxCutAndCombineWav(Collection<String> filePathList, String targetFilepath) {
int i = 0, ln = filePathList.size()-1;
String tempPath;
List<Future> resultList = new ArrayList<>(ln+1);
List<String> cutedPaths = new ArrayList<>(resultList.size());
for (String sourcePath: filePathList) {
StringBuilder soxCutCommand = new StringBuilder("sox ");
if (i == 0) {
tempPath = sourcePath.substring(0, sourcePath.lastIndexOf("."))+"_l.wav";
soxCutCommand.append(sourcePath).append(" ").append(tempPath).append(" reverse silence 1 0.1 1% reverse");
}else if (i == ln) {
tempPath = sourcePath.substring(0, sourcePath.lastIndexOf("."))+"_f.wav";
soxCutCommand.append(sourcePath).append(" ").append(tempPath).append(" silence 1 0.1 1%");
} else {
tempPath = sourcePath.substring(0, sourcePath.lastIndexOf("."))+"_a.wav";
soxCutCommand.append(sourcePath).append(" ").append(tempPath).append(" silence 1 0.1 1% reverse silence 1 0.1 1% reverse");
}
i++;
if (!cutedPaths.contains(tempPath)) {
if (!doesFileExist(tempPath)) {
resultList.add(POOL.submit(() -> {
CallPython.soxCut(soxCutCommand.toString());
}));
}
}
cutedPaths.add(tempPath);
}
for (Future future: resultList) {
try {
future.get(10, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException e) {
log.error("soxCutAndCombineWav ,分段任务执行出错:"+e);
} catch (TimeoutException e2) {
log.error("soxCutAndCombineWav ,等待10s分段任务仍未执行结束");
}
}
// long temp;
// log.warn("sox 切除静音耗时:"+((temp=System.currentTimeMillis())-startMark));
List<String> str = cutedPaths.stream().map(s -> {
if (Files.exists(Paths.get(s))) {
return "-i " + s;
} else {
return "-i " + s.substring(0, s.lastIndexOf("_"))+".wav";
}
}).collect(Collectors.toList());
StringBuilder builder = new StringBuilder("ffmpeg ").append(StringUtils.join(str, " ")).append(" -filter_complex ");
for (int k = 0; k < filePathList.size(); k++) {
builder.append("[").append(k).append(":a:0]");
}
builder.append("concat=n=").append(filePathList.size()).append(":v=0:a=1[a] -map [a] -b:a 64k -y ").append(targetFilepath);
CallPython.ffmpegExecute(builder.toString());
// log.warn("ffmpeg 拼接耗时:"+(System.currentTimeMillis()-temp));
POOL.submit(() -> {
cutedPaths.addAll(filePathList);
for (String delPath: cutedPaths) {
try {
Files.deleteIfExists(Paths.get(delPath));
} catch (Exception e) {}
}
});
}
/**
* 节点
* @param <T>
......
......@@ -8,6 +8,10 @@ import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import java.io.*;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Date;
/**
* pcm转换为wav
......@@ -40,5 +44,13 @@ public class Pcm2Wav {
}
public static void main(String[] args) {
// ThirdPartyService.lieHuTTS("绿洲有美丽的风景,好吃的食物,湛蓝的天空,蔚蓝的海洋", "1", "/home/yf01/testPcm.wav");
// System.out.println("<speak><phoneme alphabet=\"py\" ph=\"zhao2\">着</phoneme>手办理此事</speak>".length());
// String text;
// System.out.println((text="<speak>绿洲有美丽的风景,好吃的食物,湛蓝的天空,蔚蓝的海洋,<phoneme alphabet=\"py\" ph=\"zhao2\">着</phoneme>手办理此事,这是人<phoneme alphabet=\"py\" ph=\"xing2\">行</phoneme>横道</speak>").length());
// text = text.substring(7, text.length()-8);
// System.out.println(ThirdPartyService.proTencentTextSlice(text, 6));
String expireDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")) * 1000L));
System.out.println("Token有效期的北京时间:" + expireDate);
}
}
......@@ -67,8 +67,8 @@ public class TTSController {
// private final CdnService cdnService;
@Autowired
private StringRedisTemplate stringRedisTemplate;
// @Autowired
// private StringRedisTemplate stringRedisTemplate;
@Autowired
public TTSController(TTService ttService, TTServiceEdition2 ttServiceEdition2, LieHuSchedule lieHuSchedule) {
......
......@@ -4,11 +4,18 @@ import ai.qiwu.com.tts_service.common.OkHttp3Utils;
import ai.qiwu.com.tts_service.common.TTSConstants;
import ai.qiwu.com.tts_service.pojo.third.LieHuTokenResponse;
import com.alibaba.fastjson.JSON;
import com.alibaba.nls.client.AccessToken;
import com.alibaba.nls.client.protocol.NlsClient;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.HashMap;
/**
......@@ -24,6 +31,9 @@ public class LieHuSchedule {
// private static final HashMap<String, String> LIE_HU_TOKEN_HEADER;
private static String LIE_HU_TOKEN;
public static NlsClient nlsClient;
private static volatile AccessToken accessToken;
static {
LIE_HU_TOKEN_PARAMS = new HashMap<>();
// LIE_HU_TOKEN_HEADER = new HashMap<>();
......@@ -35,6 +45,41 @@ public class LieHuSchedule {
// LIE_HU_TOKEN_HEADER.put("Content-Type", "application/json");
}
@Scheduled(fixedDelay = 1800000)
public void scheduleALiTTSToken() {
if (accessToken == null) {
accessToken = new AccessToken(TTSConstants.ALI_TTS.ACCESS_KEY_ID, TTSConstants.ALI_TTS.ACCESS_KEY_SECRET);
try {
accessToken.apply();
log.warn("阿里TTS token 超时时间:"+accessToken.getExpireTime());
nlsClient = new NlsClient(accessToken.getToken());
} catch (IOException e) {
log.error(ExceptionUtils.getStackTrace(e));
}
} else {
if (accessToken.getExpireTime() - LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")) <= 300) {
boolean refreshTokenSuccess = false;
int refreshCount = 0;
do {
refreshCount++;
try {
accessToken.apply();
nlsClient.setToken(accessToken.getToken());
refreshTokenSuccess = true;
log.warn("刷新阿里TTS token, 超时时间:"+accessToken.getExpireTime());
} catch (IOException e) {
log.error("第:{}次刷新阿里TTS TOKEN 失败:{}", refreshCount, e);
try {
Thread.sleep(refreshCount*5000);
} catch (InterruptedException e1) {
// do nothing
}
}
} while (!refreshTokenSuccess && refreshCount <= 5);
}
}
}
@Scheduled(fixedDelay = 6600000)
public void scheduleLieHuToken() {
new Thread(() -> {
......
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