Commit 16a414d7 authored by 赵啸非's avatar 赵啸非

添加音频识别

parent 4089b544
......@@ -96,9 +96,10 @@ public class ApiSendMsgController {
SseEmitter emitter = new SseEmitter(10 * 60 * 1000L);
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()))) throw new AppException("只支持pcm文件!");
if (!"pcm".equalsIgnoreCase(FileUtil.getSuffix(file.getOriginalFilename())))
throw new AppException("只支持pcm文件!");
//if (file.getOriginalFilename())
......@@ -108,31 +109,39 @@ public class ApiSendMsgController {
log.info("filePath==>" + filePath);
IatModelMulUtil iatModelMulUtil = new IatModelMulUtil(filePath, appid, emitter);
//IatModelMulUtil iatModelMulUtil = new IatModelMulUtil(filePath, appid, emitter);
String authUrl = iatModelMulUtil.getAuthUrl(hostUrl, apiKey, apiSecret);
IatModelMulUtil.file=filePath;
IatModelMulUtil.emitter=emitter;
IatModelMulUtil.appid=appid;
String authUrl = IatModelMulUtil.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, new IatModelMulUtil());
// model.put("url", filePath);
model.put("fileName", file.getOriginalFilename());
// model.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
jsonStr = JSONObject.toJSONString(model);
} catch (AppException e) {
emitter.complete();
/* log.debug(e);
model.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
model.put(KEY_RESULT_MSG, e.getMessage());*/
jsonStr = JSONObject.toJSONString(model);
// jsonStr = JSONObject.toJSONString(model);
return null;
} catch (Exception e) {
emitter.complete();
return null;
/* model.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
model.put(KEY_RESULT_MSG, "文件上传失败");*/
jsonStr = JSONObject.toJSONString(model);
// jsonStr = JSONObject.toJSONString(model);
}
return emitter;
}
......
......@@ -40,17 +40,19 @@ public class IatModelMulUtil extends WebSocketListener {
private static final SimpleDateFormat sdf = new SimpleDateFormat("yyy-MM-dd HH:mm:ss.SSS");
private String file; // 识别音频位置*/
public static String file; // 识别音频位置*/
private String appid;
public static String appid;
private SseEmitter emitter;
public static SseEmitter emitter;
/*
public IatModelMulUtil(String file, String appid, SseEmitter emitter) {
this.file = file;
this.appid = appid;
this.emitter = emitter;
}
*/
@Override
public void onOpen(WebSocket webSocket, Response response) {
......
......@@ -6,7 +6,7 @@
"baseUrl": "http://127.0.0.1:18001/m"
},
"test": {
"baseUrl": "http://192.168.0.250:8082/m"
"baseUrl": "http://192.168.0.98:18006"
},
"prod": {
"baseUrl": "http://robot.scsmile.cn"
......
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