|
@@ -1,5 +1,6 @@
|
|
package com.zhili.stationcontrol.tts.component;
|
|
package com.zhili.stationcontrol.tts.component;
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
import com.zhili.stationcontrol.tts.util.WavPlayUtil;
|
|
import com.zhili.stationcontrol.tts.util.WavPlayUtil;
|
|
import com.sun.jna.Library;
|
|
import com.sun.jna.Library;
|
|
import com.sun.jna.Native;
|
|
import com.sun.jna.Native;
|
|
@@ -15,6 +16,7 @@ import org.springframework.stereotype.Component;
|
|
import javax.annotation.PostConstruct;
|
|
import javax.annotation.PostConstruct;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.io.RandomAccessFile;
|
|
import java.io.RandomAccessFile;
|
|
|
|
+import java.util.Map;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -90,12 +92,14 @@ public class XunFeiTextToSpeech implements DisposableBean, Runnable {
|
|
RandomAccessFile raf = null;
|
|
RandomAccessFile raf = null;
|
|
String sessionId = null;
|
|
String sessionId = null;
|
|
try {
|
|
try {
|
|
- Object txtObj = redisTemplate.opsForList().leftPop("ttsList", 500l, TimeUnit.MILLISECONDS);
|
|
|
|
- if (txtObj == null) {
|
|
|
|
|
|
+ Object voiceObj = redisTemplate.opsForList().leftPop("ttsList", 500l, TimeUnit.MILLISECONDS);
|
|
|
|
+ if (voiceObj == null) {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
- String text = txtObj.toString();
|
|
|
|
- log.info("speak:{}", text);
|
|
|
|
|
|
+ Map<String, Object> voice = JSON.parseObject(voiceObj.toString(), Map.class);
|
|
|
|
+ String text = voice.get("txt").toString();
|
|
|
|
+ Integer vol = Integer.valueOf(voice.get("vol").toString());
|
|
|
|
+ log.info("speak:{},vol:{}", text, vol);
|
|
IntByReference errCode = new IntByReference();
|
|
IntByReference errCode = new IntByReference();
|
|
sessionId = MscLibrary.INSTANCE.QTTSSessionBegin(sessionBeginParams, errCode);
|
|
sessionId = MscLibrary.INSTANCE.QTTSSessionBegin(sessionBeginParams, errCode);
|
|
if (errCode.getValue() != 0) {
|
|
if (errCode.getValue() != 0) {
|
|
@@ -136,10 +140,10 @@ public class XunFeiTextToSpeech implements DisposableBean, Runnable {
|
|
raf.seek(0);
|
|
raf.seek(0);
|
|
//写入真实头格式
|
|
//写入真实头格式
|
|
raf.write(getWavHeader(dataSize, 16000, 32000, 1, 16));
|
|
raf.write(getWavHeader(dataSize, 16000, 32000, 1, 16));
|
|
- if(playWay.equals("java")){
|
|
|
|
|
|
+ if (playWay.equals("java")) {
|
|
WavPlayUtil.play(filename);
|
|
WavPlayUtil.play(filename);
|
|
- }else if(playWay.equals("sox")){
|
|
|
|
- WavPlayUtil.play1(filename);
|
|
|
|
|
|
+ } else if (playWay.equals("sox")) {
|
|
|
|
+ WavPlayUtil.play2(filename, vol);
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|