Commit ecb902b7 authored by 赵啸非's avatar 赵啸非

修改音频识别结果

parent 1620e1e7
...@@ -97,15 +97,18 @@ public class ApiSendMsgController { ...@@ -97,15 +97,18 @@ public class ApiSendMsgController {
String jsonStr = ""; String jsonStr = "";
try { try {
if (file == null || file.getSize() == 0L) throw new AppException("文件为空!"); if (file == null || file.getSize() == 0L) throw new AppException("文件为空!");
if (!"pcm".equalsIgnoreCase(FileUtil.getSuffix(file.getOriginalFilename()))&& /* if (!"pcm".equalsIgnoreCase(FileUtil.getSuffix(file.getOriginalFilename()))&&
!"mp3".equalsIgnoreCase(FileUtil.getSuffix(file.getOriginalFilename()))) !"mp3".equalsIgnoreCase(FileUtil.getSuffix(file.getOriginalFilename())))
throw new AppException("只支持pcm或mp3文件!"); throw new AppException("只支持pcm或mp3文件!");*/
//if (file.getOriginalFilename()) //if (file.getOriginalFilename())
String filePath = uploadService.saveFileUpload(file, prePath, null); //String filePath = uploadService.saveFileUpload(file, prePath, null);
filePath = uploadService.getFilePath(filePath); //filePath = uploadService.getFilePath(filePath);
log.info("filePath==>" + filePath); //log.info("filePath==>" + filePath);
IatModelMulUtil iatModelMulUtil = new IatModelMulUtil(filePath, appid);
byte[] bytes = file.getBytes();
IatModelMulUtil iatModelMulUtil = new IatModelMulUtil(bytes, appid);
String authUrl = IatModelMulUtil.getAuthUrl(hostUrl, apiKey, apiSecret); String authUrl = IatModelMulUtil.getAuthUrl(hostUrl, apiKey, apiSecret);
//log.info("authUrl==>" + authUrl); //log.info("authUrl==>" + authUrl);
......
...@@ -53,9 +53,12 @@ public class IatModelMulUtil extends WebSocketListener { ...@@ -53,9 +53,12 @@ public class IatModelMulUtil extends WebSocketListener {
public String appid; public String appid;
private byte[] bytes;
public IatModelMulUtil(String file, String appid) {
this.file = file; public IatModelMulUtil(byte[] bytes, String appid) {
// this.file = file;
this.bytes = bytes;
this.appid = appid; this.appid = appid;
} }
...@@ -69,13 +72,15 @@ public class IatModelMulUtil extends WebSocketListener { ...@@ -69,13 +72,15 @@ public class IatModelMulUtil extends WebSocketListener {
int intervel = 40; int intervel = 40;
int status = 0; // 音频的状态 int status = 0; // 音频的状态
int seq = 0; //数据序号 int seq = 0; //数据序号
try (FileInputStream fs = new FileInputStream(file)) { // try (FileInputStream fs = new FileInputStream(file)) {
byte[] buffer = new byte[frameSize]; try{
// byte[] buffer = new byte[frameSize];
// 发送音频 // 发送音频
end: end:
while (true) { while (true) {
seq++; // 每次循环更新下seq seq++; // 每次循环更新下seq
int len = fs.read(buffer); // int len = fs.read(buffer);
int len = bytes.length;
if (len == -1) { if (len == -1) {
status = StatusLastFrame; //文件读完,改变status 为 2 status = StatusLastFrame; //文件读完,改变status 为 2
} }
...@@ -111,7 +116,7 @@ public class IatModelMulUtil extends WebSocketListener { ...@@ -111,7 +116,7 @@ public class IatModelMulUtil extends WebSocketListener {
audio.setBitDepth(16); audio.setBitDepth(16);
audio.setSeq(seq); audio.setSeq(seq);
audio.setStatus(status); audio.setStatus(status);
audio.setAudio(Base64.getEncoder().encodeToString(Arrays.copyOf(buffer, len))); audio.setAudio(Base64.getEncoder().encodeToString(Arrays.copyOf(bytes, len)));
payload.setAudio(audio); payload.setAudio(audio);
audioRoot.setPayload(payload); audioRoot.setPayload(payload);
...@@ -148,7 +153,7 @@ public class IatModelMulUtil extends WebSocketListener { ...@@ -148,7 +153,7 @@ public class IatModelMulUtil extends WebSocketListener {
" }\n" + " }\n" +
" }\n" + " }\n" +
"}";*/ "}";*/
// log.info("first json==>" + json); log.info("first json==>" + json);
webSocket.send(json); webSocket.send(json);
status = StatusContinueFrame; // 发送完第一帧改变status 为 1 status = StatusContinueFrame; // 发送完第一帧改变status 为 1
break; break;
...@@ -167,7 +172,7 @@ public class IatModelMulUtil extends WebSocketListener { ...@@ -167,7 +172,7 @@ public class IatModelMulUtil extends WebSocketListener {
audio.setBitDepth(16); audio.setBitDepth(16);
audio.setSeq(seq); audio.setSeq(seq);
audio.setStatus(status); audio.setStatus(status);
audio.setAudio(Base64.getEncoder().encodeToString(Arrays.copyOf(buffer, len))); audio.setAudio(Base64.getEncoder().encodeToString(Arrays.copyOf(bytes, len)));
payload.setAudio(audio); payload.setAudio(audio);
audioRoot.setPayload(payload); audioRoot.setPayload(payload);
......
...@@ -39,9 +39,9 @@ POST {{baseUrl}}/audio/upload ...@@ -39,9 +39,9 @@ POST {{baseUrl}}/audio/upload
Content-Type: multipart/form-data; boundary=WebAppBoundary Content-Type: multipart/form-data; boundary=WebAppBoundary
--WebAppBoundary --WebAppBoundary
Content-Disposition: form-data; name="file"; filename="test.mp3" Content-Disposition: form-data; name="file"; filename="new.opus"
< ./test.mp3 < ./new.opus
--WebAppBoundary-- --WebAppBoundary--
###上传音频文件1 ###上传音频文件1
...@@ -49,9 +49,9 @@ POST {{baseUrl}}/audio/upload ...@@ -49,9 +49,9 @@ POST {{baseUrl}}/audio/upload
Content-Type: multipart/form-data; boundary=WebAppBoundary Content-Type: multipart/form-data; boundary=WebAppBoundary
--WebAppBoundary --WebAppBoundary
Content-Disposition: form-data; name="file"; filename="test.pcm" Content-Disposition: form-data; name="file"; filename="test4.pcm"
< ./test1.pcm < ./test4.pcm
--WebAppBoundary-- --WebAppBoundary--
###测试链接数据库 ###测试链接数据库
......
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