Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
robot-trans-platform
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
赵啸非
robot-trans-platform
Commits
06c2aa48
Commit
06c2aa48
authored
Jun 17, 2025
by
赵啸非
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改音频识别结果
parent
16a414d7
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
41 deletions
+49
-41
robot-trans-manager/pom.xml
robot-trans-manager/pom.xml
+0
-3
robot-trans-manager/src/main/java/com/mortals/xhx/busiz/web/ApiSendMsgController.java
.../java/com/mortals/xhx/busiz/web/ApiSendMsgController.java
+19
-28
robot-trans-manager/src/main/java/com/mortals/xhx/common/utils/IatModelMulUtil.java
...in/java/com/mortals/xhx/common/utils/IatModelMulUtil.java
+29
-9
robot-trans-manager/src/test/java/httpclient/http-client.env.json
...ans-manager/src/test/java/httpclient/http-client.env.json
+1
-1
No files found.
robot-trans-manager/pom.xml
View file @
06c2aa48
...
...
@@ -83,9 +83,6 @@
</profiles>
<dependencies>
<dependency>
<groupId>
com.mortals.xhx
</groupId>
<artifactId>
common-lib
</artifactId>
...
...
robot-trans-manager/src/main/java/com/mortals/xhx/busiz/web/ApiSendMsgController.java
View file @
06c2aa48
...
...
@@ -32,6 +32,8 @@ import java.util.concurrent.Executors;
import
java.util.concurrent.ScheduledExecutorService
;
import
java.util.concurrent.TimeUnit
;
import
static
com
.
mortals
.
xhx
.
base
.
framework
.
exception
.
ExceptionHandle
.*;
@RestController
@Slf4j
@RequestMapping
(
"audio"
)
...
...
@@ -88,33 +90,21 @@ public class ApiSendMsgController {
return
emitter
;
}
@RequestMapping
(
value
=
"upload"
,
produces
=
MediaType
.
TEXT_EVENT_STREAM_VALUE
)
@RequestMapping
(
value
=
"upload"
)
@UnAuth
public
S
seEmitter
doFileUpload
(
MultipartFile
file
,
@RequestParam
(
value
=
"prePath"
,
defaultValue
=
""
)
String
prePath
)
{
public
S
tring
doFileUpload
(
MultipartFile
file
,
@RequestParam
(
value
=
"prePath"
,
defaultValue
=
""
)
String
prePath
)
{
Map
<
String
,
Object
>
model
=
new
HashMap
<>();
String
jsonStr
=
""
;
SseEmitter
emitter
=
new
SseEmitter
(
10
*
60
*
1000L
);
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
);
//IatModelMulUtil iatModelMulUtil = new IatModelMulUtil(filePath, appid, emitter);
IatModelMulUtil
.
file
=
filePath
;
IatModelMulUtil
.
emitter
=
emitter
;
IatModelMulUtil
.
appid
=
appid
;
IatModelMulUtil
iatModelMulUtil
=
new
IatModelMulUtil
(
filePath
,
appid
);
String
authUrl
=
IatModelMulUtil
.
getAuthUrl
(
hostUrl
,
apiKey
,
apiSecret
);
//log.info("authUrl==>" + authUrl);
...
...
@@ -123,27 +113,28 @@ public class ApiSendMsgController {
String
url
=
authUrl
.
toString
().
replace
(
"http://"
,
"ws://"
).
replace
(
"https://"
,
"wss://"
);
Request
request
=
new
Request
.
Builder
().
url
(
url
).
build
();
WebSocket
webSocket
=
client
.
newWebSocket
(
request
,
new
IatModelMulUtil
()
);
WebSocket
webSocket
=
client
.
newWebSocket
(
request
,
iatModelMulUtil
);
// 等待返回结果(阻塞直到收到完整数据或超时)
String
result
=
iatModelMulUtil
.
getResultFuture
().
get
(
60
,
TimeUnit
.
SECONDS
);
log
.
info
(
"识别结果:"
+
result
);
model
.
put
(
"result"
,
result
);
// model.put("url", filePath);
model
.
put
(
"fileName"
,
file
.
getOriginalFilename
());
//
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);
return
null
;
model
.
put
(
KEY_RESULT_MSG
,
e
.
getMessage
());
}
catch
(
Exception
e
)
{
emitter
.
complete
();
return
null
;
/* model.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
model.put(KEY_RESULT_MSG, "文件上传失败");*/
// jsonStr = JSONObject.toJSONString(model);
model
.
put
(
KEY_RESULT_CODE
,
VALUE_RESULT_FAILURE
);
model
.
put
(
KEY_RESULT_MSG
,
"文件上传失败"
);
jsonStr
=
JSONObject
.
toJSONString
(
model
);
}
return
emitte
r
;
return
jsonSt
r
;
}
}
robot-trans-manager/src/main/java/com/mortals/xhx/common/utils/IatModelMulUtil.java
View file @
06c2aa48
...
...
@@ -18,12 +18,14 @@ import java.nio.charset.Charset;
import
java.nio.charset.StandardCharsets
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
import
java.util.concurrent.CompletableFuture
;
/**
* 大模型语音识别---方言识别
*/
@Slf4j
public
class
IatModelMulUtil
extends
WebSocketListener
{
private
final
CompletableFuture
<
String
>
future
=
new
CompletableFuture
<>();
/* private static final String hostUrl = "https://iat.cn-huabei-1.xf-yun.com/v1"; // 注意多语种识别,也支持中文音频
private static final String appid = "3cc52607"; //在控制台-我的应用获取
private static final String apiSecret = "ZTdmMjFjMGYxYmJhN2VmYjFlMTg3N2Rk"; // 在控制台-我的应用获取
...
...
@@ -39,14 +41,21 @@ public class IatModelMulUtil extends WebSocketListener {
private
static
Date
dateEnd
=
new
Date
();
private
static
final
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyy-MM-dd HH:mm:ss.SSS"
);
private
final
StringBuilder
responseBuilder
=
new
StringBuilder
();
public
static
String
file
;
// 识别音频位置*/
public
String
file
;
// 识别音频位置*/
public
static
String
appid
;
public
String
appid
;
public
static
SseEmitter
emitter
;
// public
SseEmitter emitter;
/*
public
IatModelMulUtil
(
String
file
,
String
appid
)
{
this
.
file
=
file
;
this
.
appid
=
appid
;
// this.emitter = emitter;
}
/*
public IatModelMulUtil(String file, String appid, SseEmitter emitter) {
this.file = file;
this.appid = appid;
...
...
@@ -178,12 +187,15 @@ public class IatModelMulUtil extends WebSocketListener {
for
(
Ws
ws
:
wsList
)
{
List
<
Cw
>
cwList
=
ws
.
cw
;
for
(
Cw
cw
:
cwList
)
{
log
.
info
(
"识别结果==》{}"
,
cw
.
w
);
try
{
emitter
.
send
(
cw
.
w
);
// log.info("识别结果==》{}", cw.w);
responseBuilder
.
append
(
cw
.
w
);
/* try {
// emitter.send(cw.w);
} catch (IOException e) {
log.error("发送异常==》{}", e.getMessage());
}
}
*/
}
}
}
...
...
@@ -196,7 +208,9 @@ public class IatModelMulUtil extends WebSocketListener {
log
.
info
(
"耗时:"
+
(
dateEnd
.
getTime
()
-
dateBegin
.
getTime
())
+
"ms"
);
// System.out.println("最终识别结果 ==》" + decodeRes); // 按照规则替换与追加出最终识别结果
log
.
info
(
"本次识别sid ==》"
+
jsonParse
.
header
.
sid
);
emitter
.
complete
();
// emitter.complete();
future
.
complete
(
responseBuilder
.
toString
());
log
.
info
(
"emitter 关闭"
);
webSocket
.
close
(
1000
,
""
);
...
...
@@ -222,6 +236,8 @@ public class IatModelMulUtil extends WebSocketListener {
// TODO Auto-generated catch block
log
.
error
(
"onFailure error:"
+
e
.
getMessage
());
}
future
.
completeExceptionally
(
t
);
}
...
...
@@ -252,6 +268,10 @@ public class IatModelMulUtil extends WebSocketListener {
return
httpUrl
.
toString
();
}
public
CompletableFuture
<
String
>
getResultFuture
()
{
return
future
;
}
// 返回结果拆分与展示,仅供参考
// 返回结果拆分与展示,仅供参考
class
JsonParse
{
...
...
robot-trans-manager/src/test/java/httpclient/http-client.env.json
View file @
06c2aa48
...
...
@@ -6,7 +6,7 @@
"baseUrl"
:
"http://127.0.0.1:18001/m"
},
"test"
:
{
"baseUrl"
:
"http://192.168.0.
98
:18006"
"baseUrl"
:
"http://192.168.0.
250
:18006"
},
"prod"
:
{
"baseUrl"
:
"http://robot.scsmile.cn"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment