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

修改音频识别结果

parent 9f18dc7a
......@@ -11,6 +11,7 @@ import com.mortals.xhx.base.system.upload.service.UploadService;
import com.mortals.xhx.common.utils.IatATWSUtil;
import com.mortals.xhx.common.utils.IatModelMulMain;
import com.mortals.xhx.common.utils.IatModelMulUtil;
import com.mortals.xhx.common.utils.WebIATWS;
import lombok.extern.slf4j.Slf4j;
import okhttp3.OkHttpClient;
import okhttp3.Request;
......@@ -99,31 +100,35 @@ public class ApiSendMsgController {
String jsonStr = "";
try {
if (file == null || file.getSize() == 0L) throw new AppException("文件为空!");
// if (!"pcm".equalsIgnoreCase(FileUtil.getSuffix(file.getOriginalFilename())))
// throw new AppException("只支持pcm!");
// //if (file.getOriginalFilename())
// String filePath = uploadService.saveFileUpload(file, prePath, null);
// filePath = uploadService.getFilePath(filePath);
//
// log.info("filePath==>" + filePath);
if (!"pcm".equalsIgnoreCase(FileUtil.getSuffix(file.getOriginalFilename())))
throw new AppException("只支持pcm!");
//if (file.getOriginalFilename())
String filePath = uploadService.saveFileUpload(file, prePath, null);
filePath = uploadService.getFilePath(filePath);
byte[] bytes = file.getBytes();
log.info("filePath==>" + filePath);
WebIATWS webIATWS = new WebIATWS(filePath);
String authUrl = WebIATWS.getAuthUrl(hostUrl, apiKey, apiSecret);
// byte[] bytes = file.getBytes();
// IatModelMulUtil iatModelMulUtil = new IatModelMulUtil(filePath, appid);
// IatModelMulUtil iatModelMulUtil = new IatModelMulUtil(bytes, appid);
IatATWSUtil iatModelMulUtil = new IatATWSUtil(bytes, appid);
// IatATWSUtil iatModelMulUtil = new IatATWSUtil(bytes, appid);
String authUrl = IatATWSUtil.getAuthUrl(hostUrl, apiKey, apiSecret);
//String authUrl = IatATWSUtil.getAuthUrl(hostUrl, apiKey, apiSecret);
//log.info("authUrl==>" + authUrl);
OkHttpClient client = new OkHttpClient.Builder().build();
String url = authUrl.toString().replace("http://", "ws://").replace("https://", "wss://");
Request request = new Request.Builder().url(url).build();
WebSocket webSocket = client.newWebSocket(request, iatModelMulUtil);
WebSocket webSocket = client.newWebSocket(request, webIATWS);
// 等待返回结果(阻塞直到收到完整数据或超时)
String result = iatModelMulUtil.getResultFuture().get(60, TimeUnit.SECONDS);
String result = webIATWS.getResultFuture().get(60, TimeUnit.SECONDS);
log.info("识别结果:" + result);
model.put("result", result);
// model.put("url", filePath);
......
......@@ -156,7 +156,7 @@ public class IatATWSUtil extends WebSocketListener {
@Override
public void onMessage(WebSocket webSocket, String text) {
super.onMessage(webSocket, text);
log.info("onMessage==>" + text);
// log.info("onMessage==>" + text);
ResponseData resp = gson.fromJson(text, ResponseData.class);
if (resp != null) {
if (resp.getCode() != 0) {
......@@ -167,7 +167,7 @@ public class IatATWSUtil extends WebSocketListener {
if (resp.getData() != null) {
if (resp.getData().getResult() != null) {
Text te = resp.getData().getResult().getText();
//System.out.println(te.toString());
System.out.println(te.toString());
try {
decoder.decode(te);
// System.out.println("中间识别结果 ==》" + decoder.toString());
......
......@@ -40,9 +40,9 @@ POST {{baseUrl}}/audio/upload
Content-Type: multipart/form-data; boundary=WebAppBoundary
--WebAppBoundary
Content-Disposition: form-data; name="file"; filename="test.pcm"
Content-Disposition: form-data; name="file"; filename="recording.pcm"
< ./test.pcm
< ./recording.pcm
--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