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
a7e65528
Commit
a7e65528
authored
Sep 27, 2019
by
苗权威
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sh
parent
752b8190
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
144 additions
and
5 deletions
+144
-5
compiler.xml
.idea/compiler.xml
+1
-1
workspace.xml
.idea/workspace.xml
+0
-0
readme.md
readme.md
+2
-0
pom.xml
tts_service/pom.xml
+6
-0
TTSUtils.java
...rc/main/java/ai/qiwu/com/tts_service/common/TTSUtils.java
+5
-1
TTService.java
.../main/java/ai/qiwu/com/tts_service/service/TTService.java
+115
-0
readme.md
xiaoduhome/readme.md
+3
-0
TestBuild.java
.../src/main/java/ai/qiwu/com/xiaoduhome/pojo/TestBuild.java
+8
-3
start.sh
xiaoduhome/start.sh
+2
-0
upload.sh
xiaoduhome/upload.sh
+2
-0
No files found.
.idea/compiler.xml
View file @
a7e65528
...
...
@@ -33,7 +33,7 @@
<module
name=
"open"
options=
"-parameters"
/>
<module
name=
"rokid"
options=
"-parameters"
/>
<module
name=
"ruoqi"
options=
"-parameters"
/>
<module
name=
"spirit"
options=
"-parameters -extdirs
/usr/local/intellij/workplace/smartbox
/spirit/src/main/resources/lib"
/>
<module
name=
"spirit"
options=
"-parameters -extdirs
$PROJECT_DIR$
/spirit/src/main/resources/lib"
/>
<module
name=
"third_party_load"
options=
"-parameters"
/>
<module
name=
"tts_offline"
options=
"-parameters"
/>
<module
name=
"tts_service"
options=
"-parameters"
/>
...
...
.idea/workspace.xml
View file @
a7e65528
This diff is collapsed.
Click to expand it.
readme.md
View file @
a7e65528
tts_service项目,xiaoai项目,xiaoduhome项目下有上传与启动的脚本
\ No newline at end of file
tts_service/pom.xml
View file @
a7e65528
...
...
@@ -70,6 +70,12 @@
<artifactId>
commons-fileupload
</artifactId>
<version>
1.4
</version>
</dependency>
<!-- https://mvnrepository.com/artifact/net.sourceforge.javacsv/javacsv -->
<dependency>
<groupId>
net.sourceforge.javacsv
</groupId>
<artifactId>
javacsv
</artifactId>
<version>
2.0
</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.baidu.aip/java-sdk -->
<dependency>
<groupId>
com.baidu.aip
</groupId>
...
...
tts_service/src/main/java/ai/qiwu/com/tts_service/common/TTSUtils.java
View file @
a7e65528
...
...
@@ -138,7 +138,11 @@ public class TTSUtils {
return
true
;
}
public
static
void
deleteFile
(
String
path
)
{
File
file
=
new
File
(
path
);
if
(!
file
.
exists
())
return
;
file
.
delete
();
}
public
static
void
deleteFile
(
File
file
)
{
if
(!
file
.
exists
())
return
;
...
...
tts_service/src/main/java/ai/qiwu/com/tts_service/service/TTService.java
View file @
a7e65528
...
...
@@ -7,6 +7,7 @@ import ai.qiwu.com.tts_service.pojo.upload.UploadCallbackResponse;
import
ai.qiwu.com.tts_service.pojo.upload.UploadOneSenData
;
import
ai.qiwu.com.tts_service.service.baidu.ThirdPartyService
;
import
com.alibaba.fastjson.JSON
;
import
com.csvreader.CsvReader
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.RandomStringUtils
;
import
org.apache.commons.lang3.StringUtils
;
...
...
@@ -1248,6 +1249,120 @@ public class TTService {
TTServiceUtil
.
buildUploadResponse
(
response
,
new
TTSResponse
(
200
,
msg
),
200
);
}
public
void
uploadOneNpc2
(
UploadOneSenData
data
,
HttpServletResponse
response
)
{
// audio_dir/botname/record/npcname
final
String
folder
=
StringUtils
.
join
(
new
String
[]{
Initialize
.
getAudioDir
(),
data
.
getBotName
(),
Initialize
.
getUploadedDir
(),
data
.
getNpcName
()},
File
.
separator
);
TTSUtils
.
makedir
(
folder
);
long
currentTime
=
System
.
currentTimeMillis
();
// zipDir(专门存放压缩包及解压缩后的文件的)/botname+timestamp(确保文件名唯一,防止统一用户删除操作与上传操作的冲突)
final
String
zipFolder
=
new
StringBuilder
(
Initialize
.
getZipDir
()).
append
(
File
.
separator
)
.
append
(
data
.
getBotName
()).
append
(
currentTime
).
toString
();
TTSUtils
.
makedir
(
zipFolder
);
// 构建服务器上该压缩包的绝对路径
String
zipFilename
=
data
.
getFile
().
getName
();
if
(
zipFilename
==
null
)
zipFilename
=
new
StringBuilder
(
String
.
valueOf
(
currentTime
)).
append
(
".zip"
).
toString
();
else
if
(!
StringUtils
.
endsWith
(
zipFilename
,
".zip"
))
zipFilename
=
zipFilename
+
".zip"
;
String
filename
=
new
StringBuilder
(
zipFolder
).
append
(
File
.
separator
).
append
(
zipFilename
).
toString
();
// 写入文件
try
{
data
.
getFile
().
transferTo
(
new
File
(
filename
));
}
catch
(
IOException
e
)
{
log
.
error
(
"写入上传文件出错:{}"
,
ExceptionUtils
.
getStackTrace
(
e
));
TTServiceUtil
.
buildUploadResponse
(
response
,
new
TTSResponse
(
555
,
"写入上传文件出错:"
+
filename
),
555
);
return
;
}
// 检查压缩包格式是否正确,标准是不含有目录
if
(!
TTSUtils
.
checkZipFile
(
filename
)){
TTServiceUtil
.
buildUploadResponse
(
response
,
new
TTSResponse
(
400
,
"压缩包结构不正确"
),
400
);
return
;
}
// 解压
if
(!
TTSUtils
.
unZip
(
zipFolder
,
filename
))
{
TTServiceUtil
.
buildUploadResponse
(
response
,
new
TTSResponse
(
555
,
"压缩包解压失败"
),
555
);
return
;
}
// 压缩包中之应该只含有一个csv文件
File
[]
csvFiles
=
new
File
(
zipFolder
).
listFiles
((
dir
,
name
)
->
StringUtils
.
endsWith
(
name
,
".csv"
));
if
(
csvFiles
==
null
||
csvFiles
.
length
!=
1
)
{
int
count
=
csvFiles
==
null
?
0
:
csvFiles
.
length
;
TTServiceUtil
.
buildUploadResponse
(
response
,
new
TTSResponse
(
400
,
"csv文件数量为"
+
count
),
400
);
return
;
}
File
csvFile
=
csvFiles
[
0
];
// 判断该文件的编码
String
encoding
=
TTSUtils
.
charset
(
csvFile
);
// 意料之外的错误发生,无法判断程序进度,记录该种情况最后根据情况返回相应的信息
final
List
<
String
>
needDeleteB64File
=
new
ArrayList
<>();
List
<
String
>
successUpLoadFileIds
=
new
ArrayList
<>();
HashSet
<
String
>
textSet
=
new
HashSet
<>();
List
<
String
>
failList
=
new
ArrayList
<>();
try
{
CsvReader
reader
=
new
CsvReader
(
csvFile
.
getAbsolutePath
(),
','
,
Charset
.
forName
(
encoding
));
while
(
reader
.
readRecord
())
{
// id,text,isUpload,filename
if
(
StringUtils
.
isBlank
(
reader
.
get
(
3
)))
continue
;
if
(!
textSet
.
add
(
reader
.
get
(
1
)))
{
successUpLoadFileIds
.
add
(
reader
.
get
(
0
));
continue
;
}
String
audioFileName
=
reader
.
get
(
3
);
boolean
hasSuffix
=
StringUtils
.
endsWith
(
audioFileName
,
".mp3"
)
||
StringUtils
.
endsWith
(
audioFileName
,
".MP3"
);
if
(!
hasSuffix
)
audioFileName
=
audioFileName
+
".mp3"
;
String
fileInPackage
=
new
StringBuilder
(
zipFolder
).
append
(
File
.
separator
).
append
(
audioFileName
).
toString
();
String
md5Name
=
TTSUtils
.
buildMP3Filename
(
reader
.
get
(
1
));
//构造mp3文件名
final
String
usFilename
=
new
StringBuilder
(
folder
).
append
(
File
.
separator
).
append
(
md5Name
).
toString
();
boolean
doesFileExit
=
TTSUtils
.
doesFileExist
(
fileInPackage
);
if
(!
doesFileExit
&&
!
hasSuffix
)
{
fileInPackage
=
new
StringBuilder
(
zipFolder
).
append
(
File
.
separator
)
.
append
(
reader
.
get
(
3
)).
append
(
".MP3"
).
toString
();
doesFileExit
=
TTSUtils
.
doesFileExist
(
fileInPackage
);
}
if
(
doesFileExit
)
{
File
usFile
=
new
File
(
usFilename
);
boolean
result
=
true
;
// 删除之前的旧文件
if
(
TTSUtils
.
doesFileExist
(
usFilename
))
{
result
=
usFile
.
delete
();
}
// 删除成功后删除其b64文件,且将压缩包中的文件移到安置目录下,即
// /root/TTS-service/mqwZip/audioFilename -> audio_dir/botname/record/npcname/xxx.mp3
if
(
result
)
{
needDeleteB64File
.
add
(
new
StringBuilder
());
try
{
Files
.
copy
(
new
File
(
fileInPackage
).
toPath
(),
usFile
.
toPath
());
successUpLoadFileIds
.
add
(
reader
.
get
(
0
));
}
catch
(
Exception
e
)
{
textSet
.
remove
(
reader
.
get
(
1
));
}
}
else
{
textSet
.
remove
(
reader
.
get
(
1
));
log
.
error
(
"删除之前的就音频失败:{}"
,
fileInPackage
);
}
}
else
{
failList
.
add
(
reader
.
get
(
0
));
}
}
}
catch
(
Exception
e
)
{
log
.
error
(
"解析csv文件出错:{}"
,
ExceptionUtils
.
getStackTrace
(
e
));
TTServiceUtil
.
buildUploadResponse
(
response
,
new
TTSResponse
(
200
,
"程序出错"
),
200
);
return
;
}
POOL
.
submit
(()
->
{
TTSUtils
.
deleteFile
(
new
File
(
zipFolder
));
for
(
String
path:
needDeleteB64File
)
{
TTSUtils
.
deleteFile
(
path
);
}
});
//log.info("msg:{}",msg);
TTServiceUtil
.
buildUploadResponse
(
response
,
new
TTSResponse
(
200
,
failList
.
toString
()),
200
);
}
/**
* 删除单个上传音频文件,
* 参数说明:tid:句子id;botName:作品标识;npcName:npc名称;text:要删除的音频的内容
...
...
xiaoduhome/readme.md
0 → 100644
View file @
a7e65528
upload.sh:将jar包上传到服务器;
start.sh:服务器上执行该文件,启动项目
\ No newline at end of file
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/TestBuild.java
View file @
a7e65528
...
...
@@ -194,9 +194,14 @@ public class TestBuild {
srcReader
.
readHeaders
();
HashSet
<
String
>
set
=
new
HashSet
<>();
while
(
srcReader
.
readRecord
())
{
String
[]
arr
=
srcReader
.
getRawRecord
().
split
(
","
);
if
(
arr
.
length
!=
4
)
continue
;
set
.
add
(
arr
[
0
]);
//String[] arr = srcReader.getRawRecord().split(",");
if
(
StringUtils
.
isBlank
(
srcReader
.
get
(
3
)))
{
System
.
out
.
print
(
srcReader
.
get
(
0
)+
" "
);
continue
;
}
if
(
srcReader
.
get
(
3
).
lastIndexOf
(
"."
)
!=
-
1
&&
(!
StringUtils
.
endsWith
(
srcReader
.
get
(
3
),
".mp3"
)
&&
!
StringUtils
.
endsWith
(
srcReader
.
get
(
3
),
".MP3"
)))
continue
;
set
.
add
(
srcReader
.
get
(
0
));
}
System
.
out
.
println
(
set
.
size
());
}
...
...
xiaoduhome/start.sh
0 → 100644
View file @
a7e65528
nohup
java
-jar
/root/GameEditor/mqw/xiaoduhome/xiaoduhome.jar
>
nohup.log 2>&1 &
\ No newline at end of file
xiaoduhome/upload.sh
0 → 100644
View file @
a7e65528
scp /usr/local/intellij/workplace/smartbox/xiaoduhome/target/xiaoduhome.jar root@aliyun-hz1.chewrobot.com:/root/GameEditor/mqw/xiaoduhome/
\ 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