Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-boot-biz
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
项目统一框架
amos-boot-biz
Commits
112a9750
Commit
112a9750
authored
Dec 13, 2021
by
helinlin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
对接语音数据
parent
40c750b9
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
11 deletions
+31
-11
AudioKeywordType.java
...mos/boot/module/jcs/biz/audioToText/AudioKeywordType.java
+4
-4
RealTimeSpeechTranscriberListener.java
...cs/biz/audioToText/RealTimeSpeechTranscriberListener.java
+15
-4
application-dev.properties
...-system-jcs/src/main/resources/application-dev.properties
+0
-1
AppNslClient.java
...h/src/main/java/com/yeejoin/amos/speech/AppNslClient.java
+11
-2
AppSpeechTranscriber.java
...in/java/com/yeejoin/amos/speech/AppSpeechTranscriber.java
+1
-0
No files found.
amos-boot-module/amos-boot-module-biz/amos-boot-module-jcs-biz/src/main/java/com/yeejoin/amos/boot/module/jcs/biz/audioToText/AudioKeywordType.java
View file @
112a9750
...
...
@@ -4,11 +4,11 @@ package com.yeejoin.amos.boot.module.jcs.biz.audioToText;
* 语音转文字关键字查找表
*/
enum
AudioKeywordType
{
LOCATION
(
"location"
,
new
String
[]{
"地址"
,
"位置"
,
"地点"
,
}),
CONTACT
(
"contact"
,
new
String
[]{
"联系人"
,
"联系"
,
"在"
,
}),
CONTACT_NUMBER
(
"contactNumber"
,
new
String
[]{
"号码
是"
,
"号码"
,
"手机是"
,
"手机"
,
"手机号"
,
"手机号是
"
}),
LOCATION
(
"location"
,
new
String
[]{
"地址"
,
"位置"
,
"地点"
}),
CONTACT
(
"contact"
,
new
String
[]{
"联系人"
,
"联系"
,}),
CONTACT_NUMBER
(
"contactNumber"
,
new
String
[]{
"号码
"
,
"手机"
,
"手机号"
,
"手机号码
"
}),
UNIT
(
"unit"
,
new
String
[]{
"事发单位"
,
"单位"
,
"部门"
}),
PART
(
"part"
,
new
String
[]{
"重点部位"
,
"部位"
,
});
PART
(
"part"
,
new
String
[]{
"重点部位"
,
"部位"
});
private
String
type
;
private
String
[]
keyword
;
...
...
amos-boot-module/amos-boot-module-biz/amos-boot-module-jcs-biz/src/main/java/com/yeejoin/amos/boot/module/jcs/biz/audioToText/RealTimeSpeechTranscriberListener.java
View file @
112a9750
...
...
@@ -182,6 +182,7 @@ public class RealTimeSpeechTranscriberListener extends SpeechTranscriberListener
audioRecords
.
forEach
(
audioRecord
->
{
stringBuilder
.
append
(
","
).
append
(
audioRecord
.
getMessage
());
});
stringBuilder
.
append
(
","
);
String
result
=
stringBuilder
.
toString
();
//寻找电话号码
Pattern
pattern
=
Pattern
.
compile
(
"\\d{5,}"
);
...
...
@@ -194,13 +195,23 @@ public class RealTimeSpeechTranscriberListener extends SpeechTranscriberListener
if
(
messageKeyword
==
AudioKeywordType
.
CONTACT_NUMBER
)
continue
;
for
(
String
keyword
:
messageKeyword
.
getKeyword
())
{
int
keywordIndex
=
result
.
indexOf
(
keyword
);
//问答式:截取关键字,从关键字的下一个[,/。]号开始截取到下下一个[,/。]号结束
// 第一种(获取keyword紧跟的内容到下一个[,/。]号的内容作为关键字)
if
(
keywordIndex
!=
-
1
)
{
int
keyWordValueEndIndex
=
getKeyWordValueIndex
(
result
,
keywordIndex
);
if
(
keyWordValueEndIndex
==
-
1
)
continue
;
String
keywordValue
=
result
.
substring
(
keywordIndex
+
keyword
.
length
(),
keyWordValueEndIndex
);
if
(!
StringUtils
.
isEmpty
(
keywordValue
)
&&
keywordValue
.
length
()
>=
4
)
{
audioKeyWords
.
getValues
().
get
(
messageKeyword
.
getType
()).
add
(
keywordValue
);
continue
;
}
}
// 第二种(获取keyword的下一个[,/。]号和下下一个[,/。]号的内容作为关键字)
if
(
keywordIndex
!=
-
1
)
{
int
keyWordValueStartIndex
=
getKeyWordValueIndex
(
result
,
keywordIndex
);
if
(
keyWordValueStartIndex
==
-
1
)
continue
;
int
keyWordValueEndIndex
=
getKeyWordValueIndex
(
result
,
keyWordValueStartIndex
);
if
(
keyWordValueEndIndex
==
-
1
)
continue
;
String
keywordValue
=
result
.
substring
(
keyWordValueStartIndex
,
keyWordValueEndIndex
);
String
keywordValue
=
result
.
substring
(
keyWordValueStartIndex
+
1
<
result
.
length
()
?
keyWordValueStartIndex
+
1
:
keyWordValueStartIndex
,
keyWordValueEndIndex
);
if
(
StringUtils
.
isEmpty
(
keywordValue
))
continue
;
audioKeyWords
.
getValues
().
get
(
messageKeyword
.
getType
()).
add
(
keywordValue
);
}
...
...
@@ -217,8 +228,8 @@ public class RealTimeSpeechTranscriberListener extends SpeechTranscriberListener
private
int
getKeyWordValueIndex
(
String
text
,
int
keywordIndex
)
{
int
keywordIndexNextFlag
=
-
1
;
int
keywordIndexNextFlag1
=
text
.
indexOf
(
","
,
keywordIndex
);
int
keywordIndexNextFlag2
=
text
.
indexOf
(
"。"
,
keywordIndex
);
int
keywordIndexNextFlag1
=
text
.
indexOf
(
","
,
keywordIndex
+
1
);
int
keywordIndexNextFlag2
=
text
.
indexOf
(
"。"
,
keywordIndex
+
1
);
if
(
keywordIndexNextFlag1
!=
-
1
)
{
if
(
keywordIndexNextFlag2
!=
-
1
)
{
keywordIndexNextFlag
=
Math
.
min
(
keywordIndexNextFlag1
,
keywordIndexNextFlag2
);
...
...
amos-boot-system-jcs/src/main/resources/application-dev.properties
View file @
112a9750
...
...
@@ -40,7 +40,6 @@ file.url=http://39.98.45.134:9000/
video.url
=
https://11.11.16.4:443/
ifc.url
=
http://11.11.16.17/IFCInterface
ifc.call-back.localIp
=
11.11.16.1
amos-boot-utils/amos-boot-utils-speech/src/main/java/com/yeejoin/amos/speech/AppNslClient.java
View file @
112a9750
...
...
@@ -58,13 +58,23 @@ class AppNslClientToken {
}
}
//token过期自更新
if
(
getTokenTime
+
accessToken
.
getExpireTime
()
<=
System
.
currentTimeMillis
())
{
//显示18天过期,实测两天就失效了
/*if (getTokenTime + accessToken.getExpireTime() <= System.currentTimeMillis()) {
logger.warn("token已过期,开始重新获取...");
accessToken = getAccessToken();
getTokenTime = System.currentTimeMillis();
} else {
long time = getTokenTime + accessToken.getExpireTime() - System.currentTimeMillis();
logger.warn("token过期还剩:" + "(" + time / (1000 * 60 * 60 * 24) + "天)");
}*/
//一天更新一次
if
(
System
.
currentTimeMillis
()
-
getTokenTime
>
(
1000
*
60
*
60
))
{
logger
.
warn
(
"token已过期,开始重新获取..."
);
accessToken
=
getAccessToken
();
getTokenTime
=
System
.
currentTimeMillis
();
}
else
{
long
time
=
System
.
currentTimeMillis
()
-
getTokenTime
;
logger
.
warn
(
"token过期还剩:"
+
"("
+
time
/
(
1000
*
60
*
60
*
24
)
+
"天)"
);
}
return
accessToken
;
}
...
...
@@ -72,7 +82,6 @@ class AppNslClientToken {
/**
* 获取访问Token,包含token和过期时间(2021-11-30测试Token过期时间为18天)
* 避免多次获取可能导致已进行的任务token失效
*
* @return token 访问token
*/
private
static
AccessToken
getAccessToken
()
{
...
...
amos-boot-utils/amos-boot-utils-speech/src/main/java/com/yeejoin/amos/speech/AppSpeechTranscriber.java
View file @
112a9750
...
...
@@ -74,6 +74,7 @@ public class AppSpeechTranscriber {
idleTime
=
0
;
logger
.
warn
(
"收到数据包:"
+
b
.
length
);
//去掉前12个字节的rtp包头,后面的332字节为语音数据
//4秒未再次调用此方法,阿里云会抛出超时异常
transcriber
.
send
(
Arrays
.
copyOfRange
(
b
,
12
,
b
.
length
));
}
}
catch
(
Exception
e
)
{
...
...
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