Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
SmartBox
Project
Overview
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
苗权威
SmartBox
Commits
ab298873
Commit
ab298873
authored
Sep 09, 2019
by
苗权威
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
9.9
parent
76df569d
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
213 additions
and
34 deletions
+213
-34
workspace.xml
.idea/workspace.xml
+0
-0
Config.java
.../src/main/java/ai/qiwu/com/tts_service/common/Config.java
+2
-1
OkHttp3Utils.java
...ain/java/ai/qiwu/com/tts_service/common/OkHttp3Utils.java
+2
-3
TTSUtils.java
...rc/main/java/ai/qiwu/com/tts_service/common/TTSUtils.java
+25
-5
TTSController.java
...ava/ai/qiwu/com/tts_service/controller/TTSController.java
+12
-1
UploadCallbackResponse.java
...u/com/tts_service/pojo/upload/UploadCallbackResponse.java
+17
-0
UploadOneSenData.java
...ai/qiwu/com/tts_service/pojo/upload/UploadOneSenData.java
+6
-0
Initialize.java
...main/java/ai/qiwu/com/tts_service/service/Initialize.java
+6
-0
TTService.java
.../main/java/ai/qiwu/com/tts_service/service/TTService.java
+0
-0
application.yml
tts_service/src/main/resources/application.yml
+7
-7
tts.properties
tts_service/src/main/resources/tts.properties
+2
-4
ttsTest.properties
tts_service/src/main/resources/ttsTest.properties
+15
-0
RequestTerminal.java
.../main/java/ai/qiwu/mi/xiaoai/commons/RequestTerminal.java
+7
-1
XiaoAiConstants.java
.../main/java/ai/qiwu/mi/xiaoai/commons/XiaoAiConstants.java
+3
-3
XiaoAiService.java
...rc/main/java/ai/qiwu/mi/xiaoai/service/XiaoAiService.java
+15
-9
logback-spring.xml
xiaoduhome/src/main/resources/logback-spring.xml
+94
-0
No files found.
.idea/workspace.xml
View file @
ab298873
This diff is collapsed.
Click to expand it.
tts_service/src/main/java/ai/qiwu/com/tts_service/common/Config.java
View file @
ab298873
...
@@ -20,7 +20,8 @@ public class Config {
...
@@ -20,7 +20,8 @@ public class Config {
private
static
Properties
properties
;
private
static
Properties
properties
;
static
{
static
{
String
filename
=
"tts.properties"
;
//String filename = "tts.properties";
String
filename
=
"ttsTest.properties"
;
properties
=
new
Properties
();
properties
=
new
Properties
();
try
{
try
{
properties
.
load
(
new
InputStreamReader
(
Config
.
class
.
getClassLoader
().
getResourceAsStream
(
filename
),
StandardCharsets
.
UTF_8
));
properties
.
load
(
new
InputStreamReader
(
Config
.
class
.
getClassLoader
().
getResourceAsStream
(
filename
),
StandardCharsets
.
UTF_8
));
...
...
tts_service/src/main/java/ai/qiwu/com/tts_service/common/OkHttp3Utils.java
View file @
ab298873
...
@@ -99,14 +99,13 @@ public class OkHttp3Utils {
...
@@ -99,14 +99,13 @@ public class OkHttp3Utils {
return
doPost
(
url
,
new
HashMap
<>(),
new
HashMap
<>(),
file
);
return
doPost
(
url
,
new
HashMap
<>(),
new
HashMap
<>(),
file
);
}
}
public
static
String
doPostJsonStr
(
String
url
,
Map
<
String
,
String
>
headers
,
String
requestJsonStr
)
throws
IOException
{
public
static
String
doPostJsonStr
(
String
url
,
String
requestJsonStr
)
throws
IOException
{
Request
.
Builder
builder
=
new
Request
.
Builder
();
Request
.
Builder
builder
=
new
Request
.
Builder
();
Request
request
=
builder
.
url
(
url
).
build
();
Request
request
=
builder
.
url
(
url
).
build
();
Headers
.
Builder
headBuilder
=
request
.
headers
().
newBuilder
();
Headers
.
Builder
headBuilder
=
request
.
headers
().
newBuilder
();
Iterator
<
Map
.
Entry
<
String
,
String
>>
headIterator
=
headers
.
entrySet
().
iterator
();
headBuilder
.
add
(
"Content-Type"
,
"application/json; charset=utf-8"
);
headIterator
.
forEachRemaining
(
e
->
headBuilder
.
add
(
e
.
getKey
(),
e
.
getValue
()));
builder
.
headers
(
headBuilder
.
build
()).
post
(
RequestBody
.
create
(
MediaType
.
parse
(
"application/json; charset=utf-8"
),
requestJsonStr
));
builder
.
headers
(
headBuilder
.
build
()).
post
(
RequestBody
.
create
(
MediaType
.
parse
(
"application/json; charset=utf-8"
),
requestJsonStr
));
try
(
Response
response
=
client
.
newCall
(
builder
.
build
()).
execute
()){
try
(
Response
response
=
client
.
newCall
(
builder
.
build
()).
execute
()){
...
...
tts_service/src/main/java/ai/qiwu/com/tts_service/common/TTSUtils.java
View file @
ab298873
package
ai
.
qiwu
.
com
.
tts_service
.
common
;
package
ai
.
qiwu
.
com
.
tts_service
.
common
;
import
ai.qiwu.com.tts_service.service.Initialize
;
import
ai.qiwu.com.tts_service.service.Initialize
;
import
com.alibaba.fastjson.JSON
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.exception.ExceptionUtils
;
import
org.apache.commons.lang3.exception.ExceptionUtils
;
...
@@ -25,6 +26,7 @@ import java.util.zip.ZipFile;
...
@@ -25,6 +26,7 @@ import java.util.zip.ZipFile;
@Slf4j
@Slf4j
public
class
TTSUtils
{
public
class
TTSUtils
{
private
static
final
String
STRIP
=
" /'\""
;
private
static
final
String
STRIP
=
" /'\""
;
private
static
final
List
<
Character
>
TRIP_ENTER
=
Arrays
.
asList
(
'\r'
,
'\n'
);
public
static
String
charset
(
File
file
)
{
public
static
String
charset
(
File
file
)
{
String
charset
=
"GB18030"
;
String
charset
=
"GB18030"
;
...
@@ -80,6 +82,13 @@ public class TTSUtils {
...
@@ -80,6 +82,13 @@ public class TTSUtils {
return
charset
;
return
charset
;
}
}
public
static
String
tripEnter
(
String
str
)
{
str
=
str
.
trim
();
int
i
=
str
.
length
()-
1
;
while
(
TRIP_ENTER
.
contains
(
str
.
charAt
(
i
)))
--
i
;
return
str
.
substring
(
0
,
i
+
1
);
}
public
static
boolean
checkZipFile
(
String
zipFilePath
)
{
public
static
boolean
checkZipFile
(
String
zipFilePath
)
{
try
(
ZipFile
zipFile
=
new
ZipFile
(
zipFilePath
,
Charset
.
forName
(
"GBK"
))){
try
(
ZipFile
zipFile
=
new
ZipFile
(
zipFilePath
,
Charset
.
forName
(
"GBK"
))){
Enumeration
<?>
entries
=
zipFile
.
entries
();
Enumeration
<?>
entries
=
zipFile
.
entries
();
...
@@ -162,11 +171,20 @@ public class TTSUtils {
...
@@ -162,11 +171,20 @@ public class TTSUtils {
public
static
File
createFileReturnIts
(
String
path
)
throws
IOException
{
public
static
File
createFileReturnIts
(
String
path
)
throws
IOException
{
File
file
=
new
File
(
path
);
File
file
=
new
File
(
path
);
if
(
file
.
exists
())
{
if
(
file
.
exists
())
{
log
.
info
(
"createFileReturnIts:文件:{}已存在"
,
path
);
if
(
file
.
delete
())
{
if
(
file
.
delete
())
{
if
(
file
.
createNewFile
())
return
new
File
(
path
);
log
.
info
(
"createFileReturnIts:文件:{}已存在,删除成功"
,
path
);
if
(
file
.
createNewFile
())
{
log
.
info
(
"createFileReturnIts:文件:{}已存在,删除成功,创建成功"
,
path
);
return
new
File
(
path
);
}
}
}
}
else
{
}
else
{
if
(
file
.
createNewFile
())
return
new
File
(
path
);
log
.
info
(
"createFileReturnIts:文件:{}不存在"
,
path
);
if
(
file
.
createNewFile
())
{
log
.
info
(
"createFileReturnIts:文件:{}不存在,创建成功"
,
path
);
return
new
File
(
path
);
}
}
}
return
null
;
return
null
;
}
}
...
@@ -220,7 +238,6 @@ public class TTSUtils {
...
@@ -220,7 +238,6 @@ public class TTSUtils {
}
}
public
static
boolean
doesFileExist
(
String
filePath
)
{
public
static
boolean
doesFileExist
(
String
filePath
)
{
if
(
filePath
==
null
)
return
false
;
File
file
=
new
File
(
filePath
);
File
file
=
new
File
(
filePath
);
if
(
file
.
exists
())
{
if
(
file
.
exists
())
{
//log.info("文件:{},大小为:{}", filePath, file.length());
//log.info("文件:{},大小为:{}", filePath, file.length());
...
@@ -394,7 +411,10 @@ public class TTSUtils {
...
@@ -394,7 +411,10 @@ public class TTSUtils {
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
File
deleteBotDir
=
new
File
(
"/home/yf01/springbootdemo"
);
File
deleteBotDir
=
new
File
(
"/home/yf01/springbootdemo"
);
File
[]
needDelete
=
deleteBotDir
.
listFiles
((
dir
,
name
)
->
!
name
.
equals
(
"record"
));
File
[]
needDelete
=
deleteBotDir
.
listFiles
((
dir
,
name
)
->
!
name
.
equals
(
"record"
));
System
.
out
.
println
(
needDelete
.
length
);
//System.out.println(needDelete.length);
System
.
out
.
println
(
Arrays
.
toString
(
needDelete
));
//System.out.println(Arrays.toString(needDelete));
File
file
=
new
File
(
"/home/yf01/en.mp3"
);
file
.
renameTo
(
new
File
(
"/home/yf01/springbootdemo/nihao.mp3"
));
}
}
}
}
tts_service/src/main/java/ai/qiwu/com/tts_service/controller/TTSController.java
View file @
ab298873
...
@@ -89,12 +89,23 @@ public class TTSController {
...
@@ -89,12 +89,23 @@ public class TTSController {
response
.
setStatus
(
200
);
response
.
setStatus
(
200
);
}
}
@PostMapping
(
"/api/upload/one_sen"
)
@PostMapping
(
"/api/upload/
record/
one_sen"
)
public
void
uploadOneSen
(
MultipartFile
file
,
Integer
tid
,
String
botName
,
String
npcName
,
public
void
uploadOneSen
(
MultipartFile
file
,
Integer
tid
,
String
botName
,
String
npcName
,
String
text
,
HttpServletResponse
response
)
{
String
text
,
HttpServletResponse
response
)
{
UploadOneSenData
data
=
new
UploadOneSenData
(
tid
,
botName
,
npcName
,
text
,
file
);
UploadOneSenData
data
=
new
UploadOneSenData
(
tid
,
botName
,
npcName
,
text
,
file
);
ttService
.
uploadOneSen
(
data
,
response
);
ttService
.
uploadOneSen
(
data
,
response
);
}
}
@PostMapping
(
"/api/upload/record/one_npc"
)
public
void
uploadOneNpc
(
MultipartFile
file
,
String
botName
,
String
npcName
,
HttpServletResponse
response
)
{
UploadOneSenData
data
=
new
UploadOneSenData
(
botName
,
npcName
,
file
);
ttService
.
uploadOneNpc
(
data
,
response
);
}
@DeleteMapping
(
"/api/delete/record/one_sen"
)
public
void
deleteOneSen
(
@RequestBody
UploadOneSenData
data
,
HttpServletResponse
response
)
{
ttService
.
delOneSen
(
data
,
response
);
}
}
}
tts_service/src/main/java/ai/qiwu/com/tts_service/pojo/upload/UploadCallbackResponse.java
0 → 100644
View file @
ab298873
package
ai
.
qiwu
.
com
.
tts_service
.
pojo
.
upload
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
lombok.Getter
;
import
lombok.Setter
;
/**
* @author 苗权威
* @dateTime 19-9-9 下午8:17
*/
@Getter
@Setter
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
UploadCallbackResponse
{
private
Integer
code
;
private
String
msg
;
}
tts_service/src/main/java/ai/qiwu/com/tts_service/pojo/upload/UploadOneSenData.java
View file @
ab298873
...
@@ -35,4 +35,10 @@ public class UploadOneSenData {
...
@@ -35,4 +35,10 @@ public class UploadOneSenData {
this
.
npcName
=
npcName
;
this
.
npcName
=
npcName
;
this
.
file
=
file
;
this
.
file
=
file
;
}
}
public
UploadOneSenData
(
String
botName
,
String
npcName
,
String
text
)
{
this
.
botName
=
botName
;
this
.
npcName
=
npcName
;
this
.
text
=
text
;
}
}
}
tts_service/src/main/java/ai/qiwu/com/tts_service/service/Initialize.java
View file @
ab298873
...
@@ -44,6 +44,7 @@ public class Initialize implements InitializingBean {
...
@@ -44,6 +44,7 @@ public class Initialize implements InitializingBean {
private
static
final
String
CHANGE_SOUND
;
private
static
final
String
CHANGE_SOUND
;
private
static
final
String
UPLOADED_DIR
;
private
static
final
String
UPLOADED_DIR
;
private
static
final
String
delCacheCallbackUrl
;
private
static
final
String
delCacheCallbackUrl
;
private
static
final
String
delRecordCallbackUrl
;
private
static
final
String
record_callback_url
;
private
static
final
String
record_callback_url
;
private
final
SpeakerInfoRepository
speakerInfoRepository
;
private
final
SpeakerInfoRepository
speakerInfoRepository
;
...
@@ -63,6 +64,7 @@ public class Initialize implements InitializingBean {
...
@@ -63,6 +64,7 @@ public class Initialize implements InitializingBean {
AUDIO_DIR
=
Config
.
getProperty
(
"audio_dir"
);
AUDIO_DIR
=
Config
.
getProperty
(
"audio_dir"
);
UPLOADED_DIR
=
Config
.
getProperty
(
"record_dir"
);
UPLOADED_DIR
=
Config
.
getProperty
(
"record_dir"
);
delCacheCallbackUrl
=
Config
.
getProperty
(
"del_cache_callback_url"
);
delCacheCallbackUrl
=
Config
.
getProperty
(
"del_cache_callback_url"
);
delRecordCallbackUrl
=
Config
.
getProperty
(
"del_record_callback_url"
);
record_callback_url
=
Config
.
getProperty
(
"record_callback_url"
);
record_callback_url
=
Config
.
getProperty
(
"record_callback_url"
);
String
[]
online_sever_list
=
Config
.
getProperty
(
"online_sever"
).
split
(
","
);
String
[]
online_sever_list
=
Config
.
getProperty
(
"online_sever"
).
split
(
","
);
...
@@ -233,6 +235,10 @@ public class Initialize implements InitializingBean {
...
@@ -233,6 +235,10 @@ public class Initialize implements InitializingBean {
return
delCacheCallbackUrl
;
return
delCacheCallbackUrl
;
}
}
public
static
String
getDelRecordCallbackUrl
()
{
return
delRecordCallbackUrl
;
}
private
static
String
getOnlineServer
(
int
withOnline
)
{
private
static
String
getOnlineServer
(
int
withOnline
)
{
return
ONLINE_SERVER
.
get
(
withOnline
);
return
ONLINE_SERVER
.
get
(
withOnline
);
}
}
...
...
tts_service/src/main/java/ai/qiwu/com/tts_service/service/TTService.java
View file @
ab298873
This diff is collapsed.
Click to expand it.
tts_service/src/main/resources/application.yml
View file @
ab298873
...
@@ -19,16 +19,16 @@ spring:
...
@@ -19,16 +19,16 @@ spring:
ansi
:
ansi
:
enabled
:
detect
enabled
:
detect
logging
:
logging
:
path
:
/home/ubuntu/project/tts/logs
#
path: /home/ubuntu/project/tts/logs
#
path: /root/GameEditor/mqw/project/ttsTest/logs
path
:
/root/GameEditor/mqw/project/ttsTest/logs
level
:
level
:
root
:
info
root
:
info
server
:
server
:
port
:
9663
#
port: 9663
#
port: 8188
port
:
8188
tomcat
:
tomcat
:
accesslog
:
accesslog
:
enabled
:
true
enabled
:
true
pattern
:
'
%h
%l
%u
%t
"%r"
%s
%b
bytes
%D
ms'
pattern
:
'
%h
%l
%u
%t
"%r"
%s
%b
bytes
%D
ms'
directory
:
/home/ubuntu/project/tts/tomcat
#directory: /home/ubuntu/project/tts/tomcat
#directory: /root/GameEditor/mqw/project/ttsTest/tomcat
directory
:
/root/GameEditor/mqw/project/ttsTest/tomcat
\ No newline at end of file
\ No newline at end of file
tts_service/src/main/resources/tts.properties
View file @
ab298873
#server_name=hz1
server_name
=
aws-nx2
server_name
=
aws-nx2
server_url
=
http://aws-nx2.chewrobot.com:9663
server_url
=
http://aws-nx2.chewrobot.com:9663
#server_url=http://aliyun-hz1.chewrobot.com:9663
audio_dir
=
/root/TTS-service/audio
audio_dir
=
/root/TTS-service/audio
record_dir
=
record
record_dir
=
record
#audio_dir=/root/GameEditor/mqw/project/tts/audio
online_sever
=
1:http://dev01.centaurstech.com,2:http://dev01.centaurstech.com
online_sever
=
1:http://dev01.centaurstech.com,2:http://dev01.centaurstech.com
offline_server
=
http://dev01.centaurstech.com:9001
offline_server
=
http://dev01.centaurstech.com:9001
#offline_server=http://aliyun-hz1.chewrobot.com:9001
#第三方tts标记
#第三方tts标记
third_party_tts_text
=
third_party_tts
third_party_tts_text
=
third_party_tts
...
@@ -16,3 +12,4 @@ python_interpreter=/usr/bin/python3
...
@@ -16,3 +12,4 @@ python_interpreter=/usr/bin/python3
change_sound_path
=
/root/GameEditor/mqw/project/tts/pythonCode/audios.py
change_sound_path
=
/root/GameEditor/mqw/project/tts/pythonCode/audios.py
del_cache_callback_url
=
http://localhost:18082/text/offline/delCache/callback
del_cache_callback_url
=
http://localhost:18082/text/offline/delCache/callback
record_callback_url
=
http://localhost:18082/text/offline/upload/callback
record_callback_url
=
http://localhost:18082/text/offline/upload/callback
del_record_callback_url
=
http://localhost:18082/text/offline/delUpload/callback
\ No newline at end of file
tts_service/src/main/resources/ttsTest.properties
0 → 100644
View file @
ab298873
server_name
=
hz1
server_url
=
https://aliyun-hz1.chewrobot.com/mqw
record_dir
=
record
audio_dir
=
/root/GameEditor/mqw/project/tts/audio
online_sever
=
1:http://dev01.centaurstech.com,2:http://dev01.centaurstech.com
offline_server
=
http://dev01.centaurstech.com:9001
#第三方tts标记
third_party_tts_text
=
third_party_tts
del_cache_callback_url
=
http://localhost:18082/text/offline/delCache/callback
record_callback_url
=
http://localhost:18082/text/offline/upload/callback
del_record_callback_url
=
http://localhost:18082/text/offline/delUpload/callback
python_interpreter
=
/usr/bin/python3
#change_sound_path=/root/GameEditor/mqw/project/tts/pythonCode/audios.py
xiaoai/src/main/java/ai/qiwu/mi/xiaoai/commons/RequestTerminal.java
View file @
ab298873
...
@@ -2,6 +2,7 @@ package ai.qiwu.mi.xiaoai.commons;
...
@@ -2,6 +2,7 @@ package ai.qiwu.mi.xiaoai.commons;
import
ai.qiwu.mi.xiaoai.model.QiWuRequest
;
import
ai.qiwu.mi.xiaoai.model.QiWuRequest
;
import
ai.qiwu.mi.xiaoai.model.QiWuResponse
;
import
ai.qiwu.mi.xiaoai.model.QiWuResponse
;
import
ai.qiwu.mi.xiaoai.service.XiaoAiService
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
...
@@ -24,7 +25,12 @@ public class RequestTerminal {
...
@@ -24,7 +25,12 @@ public class RequestTerminal {
//log.info("向终端发出请求的参数信息:{}", requestJsonStr);
//log.info("向终端发出请求的参数信息:{}", requestJsonStr);
HashMap
<
String
,
String
>
headers
=
new
HashMap
<>();
HashMap
<
String
,
String
>
headers
=
new
HashMap
<>();
headers
.
put
(
"Content-Type"
,
"application/json;charset=utf-8"
);
headers
.
put
(
"Content-Type"
,
"application/json;charset=utf-8"
);
String
resStr
=
OkHttp3Utils
.
doPostJsonStr
(
XiaoAiConstants
.
QI_WU_TERMINATE
,
headers
,
requestJsonStr
);
String
resStr
;
if
(
userId
.
equals
(
XiaoAiService
.
deviceId
))
{
resStr
=
OkHttp3Utils
.
doPostJsonStr
(
XiaoAiConstants
.
QI_WU_TERMINATE_DIDI
,
headers
,
requestJsonStr
);
}
else
{
resStr
=
OkHttp3Utils
.
doPostJsonStr
(
XiaoAiConstants
.
QI_WU_TERMINATE_nx2
,
headers
,
requestJsonStr
);
}
if
(
resStr
==
null
)
{
if
(
resStr
==
null
)
{
return
null
;
return
null
;
}
}
...
...
xiaoai/src/main/java/ai/qiwu/mi/xiaoai/commons/XiaoAiConstants.java
View file @
ab298873
...
@@ -5,8 +5,8 @@ package ai.qiwu.mi.xiaoai.commons;
...
@@ -5,8 +5,8 @@ package ai.qiwu.mi.xiaoai.commons;
* @dateTime 19-7-5 下午8:56
* @dateTime 19-7-5 下午8:56
*/
*/
public
interface
XiaoAiConstants
{
public
interface
XiaoAiConstants
{
String
QI_WU_TERMINATE
=
"http://didi-gz2.jiaoyou365.com:8070/api/chat2"
;
String
QI_WU_TERMINATE
_DIDI
=
"http://didi-gz2.jiaoyou365.com:8070/api/chat2"
;
//String QI_WU_TERMINATE
= "http://aws-nx2.chewrobot.com:8070/api/chat2";
String
QI_WU_TERMINATE_nx2
=
"http://aws-nx2.chewrobot.com:8070/api/chat2"
;
String
DEVICE_NAME
=
"XIAOAI"
;
String
DEVICE_NAME
=
"XIAOAI"
;
String
CONTENT_TYPE
=
"application/json;charset=utf-8"
;
String
CONTENT_TYPE
=
"application/json;charset=utf-8"
;
String
PLAYBACK_NEARLY_FINISHED
=
"mediaplayer.playbacknearlyfinished"
;
String
PLAYBACK_NEARLY_FINISHED
=
"mediaplayer.playbacknearlyfinished"
;
...
@@ -23,7 +23,7 @@ public interface XiaoAiConstants {
...
@@ -23,7 +23,7 @@ public interface XiaoAiConstants {
String
WELCOME_WORD
=
"欢迎来到交游天下,海量的作品在这等您"
;
String
WELCOME_WORD
=
"欢迎来到交游天下,海量的作品在这等您"
;
String
END_BYE
=
"我们的作品库在不断扩充,欢迎再来玩"
;
String
END_BYE
=
"我们的作品库在不断扩充,欢迎再来玩"
;
String
END_WORD
=
"退出"
;
String
END_WORD
=
"退出"
;
String
USER_IDLE
=
"小悟在等你的回复
哦
"
;
String
USER_IDLE
=
"小悟在等你的回复"
;
String
ANOTHER_USER_IDLE
=
"再不回复我,那我可退出喽"
;
String
ANOTHER_USER_IDLE
=
"再不回复我,那我可退出喽"
;
}
}
}
}
xiaoai/src/main/java/ai/qiwu/mi/xiaoai/service/XiaoAiService.java
View file @
ab298873
...
@@ -36,11 +36,13 @@ public class XiaoAiService {
...
@@ -36,11 +36,13 @@ public class XiaoAiService {
2500
,
TimeUnit
.
MILLISECONDS
,
new
ArrayBlockingQueue
<>(
CORE
),
new
ThreadPoolExecutor
.
CallerRunsPolicy
());
2500
,
TimeUnit
.
MILLISECONDS
,
new
ArrayBlockingQueue
<>(
CORE
),
new
ThreadPoolExecutor
.
CallerRunsPolicy
());
private
static
final
ConcurrentHashMap
<
String
,
XiaoAiResponse
>
LAST_OUTTIME_RESULT
=
new
ConcurrentHashMap
<>();
private
static
final
ConcurrentHashMap
<
String
,
XiaoAiResponse
>
LAST_OUTTIME_RESULT
=
new
ConcurrentHashMap
<>();
public
static
volatile
String
deviceId
;
public
XiaoAiResponse
getResponse
(
XiaoAiRequest
request
)
{
public
XiaoAiResponse
getResponse
(
XiaoAiRequest
request
)
{
String
userId
=
getUserId
(
request
);
String
userId
=
getUserId
(
request
);
int
type
=
request
.
getRequest
().
getType
();
int
type
=
request
.
getRequest
().
getType
();
switch
(
type
)
{
switch
(
type
)
{
case
0
:
return
dealWithLaunchRequest
();
case
0
:
return
dealWithLaunchRequest
(
request
);
case
1
:
return
dealWithIntentRequest
(
request
,
userId
);
case
1
:
return
dealWithIntentRequest
(
request
,
userId
);
case
2
:
return
dealWithEndRequest
(
userId
);
case
2
:
return
dealWithEndRequest
(
userId
);
default
:
return
buildTextResponse
(
SORRY_REPEAT
);
default
:
return
buildTextResponse
(
SORRY_REPEAT
);
...
@@ -130,7 +132,8 @@ public class XiaoAiService {
...
@@ -130,7 +132,8 @@ public class XiaoAiService {
return
response
;
return
response
;
}
}
private
XiaoAiResponse
dealWithLaunchRequest
()
{
private
XiaoAiResponse
dealWithLaunchRequest
(
XiaoAiRequest
request
)
{
if
(
deviceId
==
null
)
deviceId
=
getUserId
(
request
);
return
buildTextResponse
(
TTS
.
WELCOME_WORD
);
return
buildTextResponse
(
TTS
.
WELCOME_WORD
);
}
}
...
@@ -141,7 +144,14 @@ public class XiaoAiService {
...
@@ -141,7 +144,14 @@ public class XiaoAiService {
if
(
response
!=
null
)
return
response
;
if
(
response
!=
null
)
return
response
;
//log.info("用户没说话");
//log.info("用户没说话");
//return buildTextResponse(".");
//return buildTextResponse(".");
return
buildTextResponse
((
new
Random
(
47
).
nextInt
(
666
)
&
1
)
==
1
?
TTS
.
USER_IDLE
:
TTS
.
ANOTHER_USER_IDLE
);
try
{
//log.info("开始等待");
Thread
.
sleep
(
1800
);
//log.info("等待OVER");
}
catch
(
InterruptedException
e
)
{
log
.
warn
(
"等待中断"
);
}
return
buildTextResponse
((
new
Random
(
47
).
nextInt
()
&
1
)
==
1
?
TTS
.
USER_IDLE
:
TTS
.
ANOTHER_USER_IDLE
);
}
}
XiaoAiResponse
response
=
getLastResult
(
userId
);
XiaoAiResponse
response
=
getLastResult
(
userId
);
if
(
response
!=
null
)
return
response
;
if
(
response
!=
null
)
return
response
;
...
@@ -184,12 +194,8 @@ public class XiaoAiService {
...
@@ -184,12 +194,8 @@ public class XiaoAiService {
return
Utils
.
modifyDeviceId
(
userId
);
return
Utils
.
modifyDeviceId
(
userId
);
}
}
public
XiaoAiResponse
getLastResult
(
String
userId
)
{
private
XiaoAiResponse
getLastResult
(
String
userId
)
{
XiaoAiResponse
response
;
return
LAST_OUTTIME_RESULT
.
remove
(
userId
);
if
((
response
=
LAST_OUTTIME_RESULT
.
get
(
userId
))
!=
null
)
{
LAST_OUTTIME_RESULT
.
remove
(
userId
);
}
return
response
;
}
}
class
Task
implements
Runnable
{
class
Task
implements
Runnable
{
...
...
xiaoduhome/src/main/resources/logback-spring.xml
0 → 100644
View file @
ab298873
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<property
resource=
"logback.properties"
/>
<appender
name=
"CONSOLE-LOG"
class=
"ch.qos.logback.core.ConsoleAppender"
>
<layout
class=
"ch.qos.logback.classic.PatternLayout"
>
<pattern>
[%d{yyyy-MM-dd' 'HH:mm:ss.sss}] [%C] [%t] [%L] [%-5p] %m%n
</pattern>
</layout>
</appender>
<!--获取比info级别高(包括info级别)但除error级别的日志-->
<appender
name=
"INFO-LOG"
class=
"ch.qos.logback.core.rolling.RollingFileAppender"
>
<filter
class=
"ch.qos.logback.classic.filter.LevelFilter"
>
<level>
ERROR
</level>
<onMatch>
DENY
</onMatch>
<onMismatch>
ACCEPT
</onMismatch>
</filter>
<encoder>
<pattern>
[%d{yyyy-MM-dd' 'HH:mm:ss.sss}] [%C] [%t] [%L] [%-5p] %m%n
</pattern>
</encoder>
<!--滚动策略-->
<rollingPolicy
class=
"ch.qos.logback.core.rolling.TimeBasedRollingPolicy"
>
<!--路径-->
<fileNamePattern>
${LOG_INFO_HOME}//%d.log
</fileNamePattern>
<maxHistory>
30
</maxHistory>
</rollingPolicy>
</appender>
<appender
name=
"ERROR-LOG"
class=
"ch.qos.logback.core.rolling.RollingFileAppender"
>
<filter
class=
"ch.qos.logback.classic.filter.ThresholdFilter"
>
<level>
ERROR
</level>
</filter>
<encoder>
<pattern>
[%d{yyyy-MM-dd' 'HH:mm:ss.sss}] [%C] [%t] [%L] [%-5p] %m%n
</pattern>
</encoder>
<!--滚动策略-->
<rollingPolicy
class=
"ch.qos.logback.core.rolling.TimeBasedRollingPolicy"
>
<!--路径-->
<fileNamePattern>
${LOG_ERROR_HOME}//%d.log
</fileNamePattern>
<maxHistory>
30
</maxHistory>
</rollingPolicy>
</appender>
<!-- 异步输出 -->
<appender
name=
"ASYNC-INFO"
class=
"ch.qos.logback.classic.AsyncAppender"
>
<!-- 不丢失日志.默认的,如果队列的80%已满,则会丢弃TRACT、DEBUG、INFO级别的日志 -->
<discardingThreshold>
0
</discardingThreshold>
<!-- 更改默认的队列的深度,该值会影响性能.默认值为256 -->
<queueSize>
256
</queueSize>
<!-- 添加附加的appender,最多只能添加一个 -->
<appender-ref
ref=
"INFO-LOG"
/>
</appender>
<appender
name=
"ASYNC-ERROR"
class=
"ch.qos.logback.classic.AsyncAppender"
>
<!-- 不丢失日志.默认的,如果队列的80%已满,则会丢弃TRACT、DEBUG、INFO级别的日志 -->
<discardingThreshold>
0
</discardingThreshold>
<!-- 更改默认的队列的深度,该值会影响性能.默认值为256 -->
<queueSize>
256
</queueSize>
<!-- 添加附加的appender,最多只能添加一个 -->
<appender-ref
ref=
"ERROR-LOG"
/>
</appender>
<root
level=
"info"
>
<appender-ref
ref=
"CONSOLE-LOG"
/>
<appender-ref
ref=
"ASYNC-INFO"
/>
<appender-ref
ref=
"ASYNC-ERROR"
/>
</root>
</configuration>
\ No newline at end of file
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