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
3f632ed9
Commit
3f632ed9
authored
Jul 02, 2025
by
赵啸非
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改音频识别结果
parent
ecb902b7
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
30 additions
and
31 deletions
+30
-31
robot-trans-manager/src/main/java/com/mortals/xhx/busiz/web/ApiSendMsgController.java
.../java/com/mortals/xhx/busiz/web/ApiSendMsgController.java
+6
-7
robot-trans-manager/src/main/java/com/mortals/xhx/common/utils/IatModelMulMain.java
...in/java/com/mortals/xhx/common/utils/IatModelMulMain.java
+1
-1
robot-trans-manager/src/main/java/com/mortals/xhx/common/utils/IatModelMulUtil.java
...in/java/com/mortals/xhx/common/utils/IatModelMulUtil.java
+21
-12
robot-trans-manager/src/test/java/httpclient/recording.pcm
robot-trans-manager/src/test/java/httpclient/recording.pcm
+0
-0
robot-trans-manager/src/test/java/httpclient/system.http
robot-trans-manager/src/test/java/httpclient/system.http
+2
-11
robot-trans-manager/src/test/java/httpclient/test4.pcm
robot-trans-manager/src/test/java/httpclient/test4.pcm
+0
-0
No files found.
robot-trans-manager/src/main/java/com/mortals/xhx/busiz/web/ApiSendMsgController.java
View file @
3f632ed9
...
...
@@ -97,18 +97,17 @@ public class ApiSendMsgController {
String
jsonStr
=
""
;
try
{
if
(
file
==
null
||
file
.
getSize
()
==
0L
)
throw
new
AppException
(
"文件为空!"
);
/* if (!"pcm".equalsIgnoreCase(FileUtil.getSuffix(file.getOriginalFilename()))&&
!"mp3".equalsIgnoreCase(FileUtil.getSuffix(file.getOriginalFilename())))
throw new AppException("只支持pcm或mp3文件!");*/
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);
String
filePath
=
uploadService
.
saveFileUpload
(
file
,
prePath
,
null
);
filePath
=
uploadService
.
getFilePath
(
filePath
);
//log.info("filePath==>" + filePath);
byte
[]
bytes
=
file
.
getBytes
();
//
byte[] bytes = file.getBytes();
IatModelMulUtil
iatModelMulUtil
=
new
IatModelMulUtil
(
bytes
,
appid
);
IatModelMulUtil
iatModelMulUtil
=
new
IatModelMulUtil
(
filePath
,
appid
);
String
authUrl
=
IatModelMulUtil
.
getAuthUrl
(
hostUrl
,
apiKey
,
apiSecret
);
//log.info("authUrl==>" + authUrl);
...
...
robot-trans-manager/src/main/java/com/mortals/xhx/common/utils/IatModelMulMain.java
View file @
3f632ed9
...
...
@@ -24,7 +24,7 @@ public class IatModelMulMain extends WebSocketListener {
private
static
final
String
appid
=
"3cc52607"
;
//在控制台-我的应用获取
private
static
final
String
apiSecret
=
"ZTdmMjFjMGYxYmJhN2VmYjFlMTg3N2Rk"
;
// 在控制台-我的应用获取
private
static
final
String
apiKey
=
"d0f73d44e996c2da9924c4476c578a30"
;
// 在控制台-我的应用获取
private
static
final
String
file
=
"
E://test1.mp3
"
;
// 识别音频位置
private
static
final
String
file
=
"
F://recording.pcm
"
;
// 识别音频位置
public
static
final
int
StatusFirstFrame
=
0
;
public
static
final
int
StatusContinueFrame
=
1
;
public
static
final
int
StatusLastFrame
=
2
;
...
...
robot-trans-manager/src/main/java/com/mortals/xhx/common/utils/IatModelMulUtil.java
View file @
3f632ed9
...
...
@@ -12,6 +12,7 @@ import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import
javax.crypto.Mac
;
import
javax.crypto.spec.SecretKeySpec
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
...
...
@@ -57,11 +58,16 @@ public class IatModelMulUtil extends WebSocketListener {
public
IatModelMulUtil
(
byte
[]
bytes
,
String
appid
)
{
// this.file = file;
// this.file = file;
this
.
bytes
=
bytes
;
this
.
appid
=
appid
;
}
public
IatModelMulUtil
(
String
file
,
String
appid
)
{
this
.
file
=
file
;
this
.
appid
=
appid
;
}
@Override
public
void
onOpen
(
WebSocket
webSocket
,
Response
response
)
{
super
.
onOpen
(
webSocket
,
response
);
...
...
@@ -72,15 +78,18 @@ public class IatModelMulUtil extends WebSocketListener {
int
intervel
=
40
;
int
status
=
0
;
// 音频的状态
int
seq
=
0
;
//数据序号
//
try (FileInputStream fs = new FileInputStream(file)) {
try
{
//
byte[] buffer = new byte[frameSize];
try
(
FileInputStream
fs
=
new
FileInputStream
(
file
))
{
//
try{
byte
[]
buffer
=
new
byte
[
frameSize
];
// 发送音频
end:
while
(
true
)
{
seq
++;
// 每次循环更新下seq
// int len = fs.read(buffer);
int
len
=
bytes
.
length
;
//int len = bytes.length;
int
len
=
fs
.
read
(
buffer
);
//int len = bytes.length;
if
(
len
==
-
1
)
{
status
=
StatusLastFrame
;
//文件读完,改变status 为 2
}
...
...
@@ -116,7 +125,7 @@ public class IatModelMulUtil extends WebSocketListener {
audio
.
setBitDepth
(
16
);
audio
.
setSeq
(
seq
);
audio
.
setStatus
(
status
);
audio
.
setAudio
(
Base64
.
getEncoder
().
encodeToString
(
Arrays
.
copyOf
(
b
ytes
,
len
)));
audio
.
setAudio
(
Base64
.
getEncoder
().
encodeToString
(
Arrays
.
copyOf
(
b
uffer
,
len
)));
payload
.
setAudio
(
audio
);
audioRoot
.
setPayload
(
payload
);
...
...
@@ -172,7 +181,7 @@ public class IatModelMulUtil extends WebSocketListener {
audio
.
setBitDepth
(
16
);
audio
.
setSeq
(
seq
);
audio
.
setStatus
(
status
);
audio
.
setAudio
(
Base64
.
getEncoder
().
encodeToString
(
Arrays
.
copyOf
(
b
ytes
,
len
)));
audio
.
setAudio
(
Base64
.
getEncoder
().
encodeToString
(
Arrays
.
copyOf
(
b
uffer
,
len
)));
payload
.
setAudio
(
audio
);
audioRoot
.
setPayload
(
payload
);
...
...
@@ -195,7 +204,7 @@ public class IatModelMulUtil extends WebSocketListener {
" }\n" +
" }\n" +
"}";*/
// log.info("mid json==>" + json);
// log.info("mid json==>" + json);
webSocket
.
send
(
json
);
break
;
case
StatusLastFrame:
// 最后一帧音频status = 2 ,标志音频发送结束
...
...
@@ -236,7 +245,7 @@ public class IatModelMulUtil extends WebSocketListener {
" }\n" +
" }\n" +
"}";*/
// log.info("last json==>" + json);
// log.info("last json==>" + json);
webSocket
.
send
(
json
);
break
end
;
}
...
...
@@ -251,7 +260,7 @@ public class IatModelMulUtil extends WebSocketListener {
@Override
public
void
onMessage
(
WebSocket
webSocket
,
String
text
)
{
super
.
onMessage
(
webSocket
,
text
);
log
.
info
(
"onMessage==>"
+
text
);
//
log.info("onMessage==>" + text);
JsonParse
jsonParse
=
gson
.
fromJson
(
text
,
JsonParse
.
class
);
if
(
jsonParse
!=
null
)
{
if
(
jsonParse
.
header
.
code
!=
0
)
{
...
...
@@ -269,7 +278,7 @@ public class IatModelMulUtil extends WebSocketListener {
for
(
Ws
ws
:
wsList
)
{
List
<
Cw
>
cwList
=
ws
.
cw
;
for
(
Cw
cw
:
cwList
)
{
//
log.info("识别结果==》{}", cw.w);
log
.
info
(
"识别结果==》{}"
,
cw
.
w
);
responseBuilder
.
append
(
cw
.
w
);
/* try {
...
...
robot-trans-manager/src/test/java/httpclient/recording.pcm
0 → 100644
View file @
3f632ed9
File added
robot-trans-manager/src/test/java/httpclient/system.http
View file @
3f632ed9
...
...
@@ -34,24 +34,15 @@ Content-Disposition: form-data; name="file"; filename="file.zip"
--WebAppBoundary--
###上传音频文件
POST {{baseUrl}}/audio/upload
Content-Type: multipart/form-data; boundary=WebAppBoundary
--WebAppBoundary
Content-Disposition: form-data; name="file"; filename="new.opus"
< ./new.opus
--WebAppBoundary--
###上传音频文件1
POST {{baseUrl}}/audio/upload
Content-Type: multipart/form-data; boundary=WebAppBoundary
--WebAppBoundary
Content-Disposition: form-data; name="file"; filename="
test4
.pcm"
Content-Disposition: form-data; name="file"; filename="
recording
.pcm"
< ./
test4
.pcm
< ./
recording
.pcm
--WebAppBoundary--
###测试链接数据库
...
...
robot-trans-manager/src/test/java/httpclient/test4.pcm
0 → 100644
View file @
3f632ed9
File added
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