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
0bfe5351
Commit
0bfe5351
authored
Aug 03, 2019
by
苗权威
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
8.3
parent
7df5f4da
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
348 additions
and
24 deletions
+348
-24
workspace.xml
.idea/workspace.xml
+0
-0
CallPython.java
.../main/java/ai/qiwu/com/tts_service/common/CallPython.java
+0
-15
OfflineConfig.java
...in/java/ai/qiwu/com/tts_service/common/OfflineConfig.java
+27
-0
OfflineServiceUtil.java
...va/ai/qiwu/com/tts_service/common/OfflineServiceUtil.java
+46
-0
TTSUtils.java
...rc/main/java/ai/qiwu/com/tts_service/common/TTSUtils.java
+6
-0
OfflineController.java
...ai/qiwu/com/tts_service/controller/OfflineController.java
+57
-0
TTSController.java
...ava/ai/qiwu/com/tts_service/controller/TTSController.java
+0
-1
OfflineOnlineCacheRequest.java
...m/tts_service/pojo/offline/OfflineOnlineCacheRequest.java
+17
-0
OfflineOnlineCacheResponse.java
.../tts_service/pojo/offline/OfflineOnlineCacheResponse.java
+28
-0
SpeakersApi.java
...ava/ai/qiwu/com/tts_service/pojo/offline/SpeakersApi.java
+42
-0
TTService.java
.../main/java/ai/qiwu/com/tts_service/service/TTService.java
+4
-4
OfflineService.java
.../qiwu/com/tts_service/service/offline/OfflineService.java
+104
-0
application.yml
tts_service/src/main/resources/application.yml
+12
-0
ResponseEncapsulation.java
...a/ai/qiwu/baidu/xiaodu/service/ResponseEncapsulation.java
+5
-4
No files found.
.idea/workspace.xml
View file @
0bfe5351
This diff is collapsed.
Click to expand it.
tts_service/src/main/java/ai/qiwu/com/tts_service/common/CallPython.java
View file @
0bfe5351
...
...
@@ -5,8 +5,6 @@ import lombok.extern.slf4j.Slf4j;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.nio.Buffer
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
...
...
@@ -51,19 +49,6 @@ public class CallPython {
reader
.
close
();
}
public
static
void
changeSound
()
throws
IOException
{
String
[]
args
=
{
INTERPRETER
,
"/home/yf01/pythonWork/hello.py"
,
"1"
,
"2"
};
Process
process
=
Runtime
.
getRuntime
().
exec
(
args
);
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
process
.
getInputStream
()));
String
line
;
StringBuilder
result
=
new
StringBuilder
();
while
((
line
=
reader
.
readLine
())
!=
null
)
{
result
.
append
(
line
);
}
log
.
info
(
"result:{}"
,
result
.
toString
());
reader
.
close
();
}
public
static
void
main
(
String
[]
args
)
throws
IOException
{
String
wav
=
"/usr/GameEditor/mqw/tts/audio/A04/正常/f403f73cff700be9c3fed05b67fc9ace.wav"
;
String
mp3
=
"/usr/GameEditor/mqw/tts/audio/A04/正常/f403f73cff700be9c3fed05b67fc9ace.mp3"
;
...
...
tts_service/src/main/java/ai/qiwu/com/tts_service/common/OfflineConfig.java
0 → 100644
View file @
0bfe5351
package
ai
.
qiwu
.
com
.
tts_service
.
common
;
import
lombok.Getter
;
import
lombok.Setter
;
import
lombok.ToString
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.stereotype.Component
;
/**
* @author 苗权威
* @dateTime 19-8-3 下午4:06
*/
@Component
@ConfigurationProperties
(
prefix
=
"offline"
)
@Getter
@Setter
@ToString
public
class
OfflineConfig
{
private
String
output_dir
;
private
String
short_audio_dir
;
private
String
letter_audio_dir
;
private
String
test_text
;
private
String
mysql_host
;
private
String
mysql_user
;
private
String
mysql_password
;
private
String
models_threads
;
}
tts_service/src/main/java/ai/qiwu/com/tts_service/common/OfflineServiceUtil.java
0 → 100644
View file @
0bfe5351
package
ai
.
qiwu
.
com
.
tts_service
.
common
;
import
ai.qiwu.com.tts_service.pojo.MP3Response
;
import
ai.qiwu.com.tts_service.pojo.offline.OfflineOnlineCacheResponse
;
import
com.alibaba.fastjson.JSON
;
import
lombok.extern.slf4j.Slf4j
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.*
;
/**
* @author 苗权威
* @dateTime 19-8-3 下午4:42
*/
@Slf4j
public
class
OfflineServiceUtil
{
public
static
void
speakersApiFile
(
HttpServletResponse
response
,
String
fileName
,
String
type
)
{
try
(
BufferedInputStream
inputStream
=
new
BufferedInputStream
(
new
FileInputStream
(
fileName
));
OutputStream
out
=
new
BufferedOutputStream
(
response
.
getOutputStream
())){
response
.
reset
();
response
.
setContentType
(
type
);
byte
[]
buffer
=
new
byte
[
1024
];
int
ln
;
while
((
ln
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
out
.
write
(
buffer
,
0
,
ln
);
}
out
.
flush
();
}
catch
(
Exception
e
)
{
log
.
error
(
"speakersApiFile():写入音频流到HttpServletResponse失败:{}"
,
e
.
toString
());
}
}
public
static
void
onlineCacheResponse
(
HttpServletResponse
response
,
OfflineOnlineCacheResponse
cacheResponse
,
int
status
)
{
String
responseJsonStr
=
JSON
.
toJSONString
(
cacheResponse
);
response
.
setStatus
(
status
);
response
.
setCharacterEncoding
(
"UTF-8"
);
response
.
setContentType
(
"application/json;charset=utf-8"
);
try
(
PrintWriter
out
=
response
.
getWriter
()){
out
.
append
(
responseJsonStr
);
out
.
flush
();
}
catch
(
Exception
e
)
{
log
.
error
(
"OfflineServiceUtil#onlineCacheResponse返回写入json数据失败:{}"
,
e
.
toString
());
}
}
}
tts_service/src/main/java/ai/qiwu/com/tts_service/common/TTSUtils.java
View file @
0bfe5351
...
...
@@ -86,6 +86,12 @@ public class TTSUtils {
return
file
;
}
public
static
String
buildWavFilename
(
String
filename
)
{
String
file
=
DigestUtils
.
md5DigestAsHex
(
filename
.
getBytes
(
StandardCharsets
.
UTF_8
));
file
=
StringUtils
.
join
(
new
String
[]{
file
,
"wav"
},
"."
);
return
file
;
}
public
static
String
pythonlistToStr
(
List
<
String
>
file_ls
)
{
StringBuilder
builder
=
new
StringBuilder
(
"['"
);
for
(
String
str
:
file_ls
)
{
...
...
tts_service/src/main/java/ai/qiwu/com/tts_service/controller/OfflineController.java
0 → 100644
View file @
0bfe5351
package
ai
.
qiwu
.
com
.
tts_service
.
controller
;
import
ai.qiwu.com.tts_service.pojo.offline.OfflineOnlineCacheRequest
;
import
ai.qiwu.com.tts_service.pojo.offline.SpeakersApi
;
import
ai.qiwu.com.tts_service.service.offline.OfflineService
;
import
org.aspectj.lang.annotation.Before
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletResponse
;
/**
* @author 苗权威
* @dateTime 19-8-3 下午3:45
*/
@RestController
public
class
OfflineController
{
private
final
OfflineService
offlineService
;
@Autowired
public
OfflineController
(
OfflineService
offlineService
)
{
this
.
offlineService
=
offlineService
;
}
@Before
(
value
=
"speakers_api() || online_cache()"
)
public
void
before
()
{
}
@GetMapping
(
"/synthesize"
)
public
void
speakers_api
(
@RequestParam
(
required
=
false
)
String
person
,
@RequestParam
(
required
=
false
)
String
tone
,
@RequestParam
(
required
=
false
)
String
server
,
@RequestParam
(
required
=
false
)
String
text
,
@RequestParam
(
required
=
false
)
String
botname
,
@RequestParam
(
required
=
false
)
String
volume
,
@RequestParam
(
required
=
false
)
String
pitch
,
@RequestParam
(
required
=
false
)
String
speed
,
@RequestParam
(
required
=
false
)
String
format
,
@RequestParam
(
required
=
false
)
String
change
,
HttpServletResponse
response
)
{
SpeakersApi
speakersApi
=
new
SpeakersApi
(
person
,
tone
,
server
,
text
,
botname
,
volume
,
pitch
,
speed
,
format
,
change
);
offlineService
.
speakers_api
(
speakersApi
,
response
,
"GET"
);
}
@PostMapping
(
"/synthesize"
)
public
void
speakers_api
(
@RequestBody
SpeakersApi
api
,
HttpServletResponse
response
)
{
offlineService
.
speakers_api
(
api
,
response
,
"POST"
);
}
@PutMapping
(
"/synthesize"
)
public
void
speakers_api
(
HttpServletResponse
response
,
@RequestBody
SpeakersApi
api
)
{
offlineService
.
speakers_api
(
api
,
response
,
"PUT"
);
}
@DeleteMapping
(
"/online_cache"
)
public
void
online_cache
(
@RequestBody
OfflineOnlineCacheRequest
request
,
HttpServletResponse
response
)
{
offlineService
.
online_cache
(
request
,
response
);
}
}
tts_service/src/main/java/ai/qiwu/com/tts_service/controller/TTSController.java
View file @
0bfe5351
...
...
@@ -19,7 +19,6 @@ import javax.servlet.http.HttpServletResponse;
@RequestMapping
(
"/mqw"
)
public
class
TTSController
{
// @Autowired
private
final
TTService
ttService
;
@Autowired
...
...
tts_service/src/main/java/ai/qiwu/com/tts_service/pojo/offline/OfflineOnlineCacheRequest.java
0 → 100644
View file @
0bfe5351
package
ai
.
qiwu
.
com
.
tts_service
.
pojo
.
offline
;
import
lombok.Getter
;
import
lombok.Setter
;
import
lombok.ToString
;
/**
* @author 苗权威
* @dateTime 19-8-3 下午5:06
*/
@Getter
@Setter
@ToString
public
class
OfflineOnlineCacheRequest
{
private
String
server
;
private
String
botname
;
}
tts_service/src/main/java/ai/qiwu/com/tts_service/pojo/offline/OfflineOnlineCacheResponse.java
0 → 100644
View file @
0bfe5351
package
ai
.
qiwu
.
com
.
tts_service
.
pojo
.
offline
;
import
com.fasterxml.jackson.databind.annotation.JsonSerialize
;
import
lombok.Getter
;
import
lombok.Setter
;
import
lombok.ToString
;
/**
* @author 苗权威
* @dateTime 19-8-3 下午5:11
*/
@Getter
@Setter
@ToString
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
public
class
OfflineOnlineCacheResponse
{
private
int
status
;
private
String
message
;
public
OfflineOnlineCacheResponse
(
int
status
,
String
message
)
{
this
.
status
=
status
;
this
.
message
=
message
;
}
public
OfflineOnlineCacheResponse
(
int
status
)
{
this
.
status
=
status
;
}
}
tts_service/src/main/java/ai/qiwu/com/tts_service/pojo/offline/SpeakersApi.java
0 → 100644
View file @
0bfe5351
package
ai
.
qiwu
.
com
.
tts_service
.
pojo
.
offline
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
lombok.Getter
;
import
lombok.Setter
;
import
lombok.ToString
;
/**
* @author 苗权威
* @dateTime 19-8-3 下午3:49
*/
@Getter
@Setter
@ToString
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
SpeakersApi
{
private
String
person
;
private
String
tone
;
private
String
server
;
private
String
text
;
private
String
botname
;
private
String
volume
;
private
String
pitch
;
private
String
speed
;
private
String
format
;
private
String
change
;
public
SpeakersApi
(
String
person
,
String
tone
,
String
server
,
String
text
,
String
botname
,
String
volume
,
String
pitch
,
String
speed
,
String
format
,
String
change
)
{
this
.
person
=
person
;
this
.
tone
=
tone
;
this
.
server
=
server
;
this
.
text
=
text
;
this
.
botname
=
botname
;
this
.
volume
=
volume
;
this
.
pitch
=
pitch
;
this
.
speed
=
speed
;
this
.
format
=
format
;
this
.
change
=
change
;
}
}
tts_service/src/main/java/ai/qiwu/com/tts_service/service/TTService.java
View file @
0bfe5351
...
...
@@ -70,7 +70,7 @@ public class TTService {
Config
.
getProperty
(
"offline_server"
)),
new
HashMap
<>(),
offlineStr
);
}
catch
(
IOException
e
)
{
log
.
error
(
"删除offline地址的bot请求出错:{}"
,
e
.
toString
());
deleteOfflineResCode
=
5
00
;
deleteOfflineResCode
=
5
55
;
}
TTServiceUtil
.
buildOnlineCacheResponse
(
response
,
new
TTSResponse
(
deleteOfflineResCode
,
"no botName"
),
deleteOfflineResCode
);
}
...
...
@@ -320,7 +320,7 @@ public class TTService {
response
=
new
TTSResponse
(
200
,
audio
);
}
catch
(
UnsupportedEncodingException
e
)
{
log
.
error
(
"URLEncoding编码出错:{}"
,
e
.
toString
());
response
=
new
TTSResponse
(
5
00
,
"编码URL中的中文出错"
);
response
=
new
TTSResponse
(
5
55
,
"编码URL中的中文出错"
);
}
}
// filepath文件不存在或是put请求,调用generalMP3生成该filepath所指的mp3文件
...
...
@@ -373,7 +373,7 @@ public class TTService {
String
.
valueOf
(
data
.
getPitch
()),
filePath
);
}
catch
(
Exception
e
)
{
log
.
error
(
"调用python的changeSound出错:{}"
,
e
.
toString
());
res
=
new
ResponseCodeWithData
(
5
00
);
res
=
new
ResponseCodeWithData
(
5
55
);
}
}
// 如果url是线下地址:http://aliyun-hz1.chewrobot.com:9001/synthesize 且xx.mp3文件不存在,则直接下载
...
...
@@ -466,7 +466,7 @@ public class TTService {
log
.
error
(
"第{}次失败,原因{}"
,
i
+
1
,
e
.
toString
());
continue
;
}
int
resCode
=
res
==
null
?
5
00
:
res
.
getCode
();
int
resCode
=
res
==
null
?
5
55
:
res
.
getCode
();
if
(
resCode
==
200
)
{
break
;
}
...
...
tts_service/src/main/java/ai/qiwu/com/tts_service/service/offline/OfflineService.java
0 → 100644
View file @
0bfe5351
package
ai
.
qiwu
.
com
.
tts_service
.
service
.
offline
;
import
ai.qiwu.com.tts_service.common.CallPython
;
import
ai.qiwu.com.tts_service.common.OfflineConfig
;
import
ai.qiwu.com.tts_service.common.OfflineServiceUtil
;
import
ai.qiwu.com.tts_service.common.TTSUtils
;
import
ai.qiwu.com.tts_service.pojo.offline.OfflineOnlineCacheRequest
;
import
ai.qiwu.com.tts_service.pojo.offline.OfflineOnlineCacheResponse
;
import
ai.qiwu.com.tts_service.pojo.offline.SpeakersApi
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.File
;
import
java.io.IOException
;
/**
* @author 苗权威
* @dateTime 19-8-3 下午3:56
*/
@Service
@Slf4j
public
class
OfflineService
{
private
final
OfflineConfig
offlineConfig
;
@Autowired
public
OfflineService
(
OfflineConfig
offlineConfig
)
{
this
.
offlineConfig
=
offlineConfig
;
}
public
void
speakers_api
(
SpeakersApi
request
,
HttpServletResponse
response
,
String
requestMethod
)
{
String
person
=
request
.
getPerson
();
String
mood
=
null
;
if
(
StringUtils
.
isNotBlank
(
person
))
{
mood
=
request
.
getTone
();
}
String
server_name
=
request
.
getServer
();
String
text
=
request
.
getText
();
if
(
StringUtils
.
isBlank
(
text
))
{
log
.
info
(
"text is empty"
);
response
.
setStatus
(
404
);
return
;
}
if
(
offlineConfig
.
getTest_text
().
equals
(
text
))
{
server_name
=
null
;
}
String
botname
=
StringUtils
.
isBlank
(
server_name
)
?
null
:
request
.
getBotname
();
String
volume
=
StringUtils
.
isBlank
(
request
.
getVolume
())
?
"0"
:
request
.
getVolume
();
String
pitch
=
StringUtils
.
isBlank
(
request
.
getPitch
())
?
"0"
:
request
.
getPitch
();
String
speed
=
StringUtils
.
isBlank
(
request
.
getSpeed
())
?
"1"
:
request
.
getSpeed
();
String
filename
=
TTSUtils
.
buildWavFilename
(
text
);
StringBuilder
builder
=
new
StringBuilder
(
offlineConfig
.
getOutput_dir
()).
append
(
File
.
separator
);
for
(
String
str
:
new
String
[]{
server_name
,
botname
,
person
,
mood
})
{
if
(
str
!=
null
)
builder
.
append
(
str
).
append
(
File
.
separator
);
}
String
wavfilepath
=
builder
.
append
(
filename
).
toString
();
log
.
info
(
"OfflineService,51 row: filepath:{}"
,
wavfilepath
);
if
(!
TTSUtils
.
doesFileExist
(
wavfilepath
))
{
if
(
"wav"
.
equals
(
request
.
getFormat
()))
{
OfflineServiceUtil
.
speakersApiFile
(
response
,
wavfilepath
,
"audio/wav"
);
return
;
}
String
mp3Filepath
=
wavfilepath
.
replace
(
".wav"
,
".mp3"
);
if
(!
TTSUtils
.
doesFileExist
(
mp3Filepath
)
||
StringUtils
.
isNotBlank
(
request
.
getChange
())
||
requestMethod
.
equals
(
"PUT"
))
{
try
{
CallPython
.
changeSound
(
wavfilepath
,
volume
,
speed
,
pitch
,
mp3Filepath
);
}
catch
(
Exception
e
)
{
log
.
info
(
"OfflineService#speakers_api:调用changeSound方法生成mp3文件出错:{}"
,
e
.
toString
());
response
.
setStatus
(
555
);
return
;
}
OfflineServiceUtil
.
speakersApiFile
(
response
,
mp3Filepath
,
"audio/mp3"
);
return
;
}
}
else
{
response
.
setStatus
(
404
);
}
}
public
void
online_cache
(
OfflineOnlineCacheRequest
request
,
HttpServletResponse
response
)
{
String
serverName
=
request
.
getServer
();
String
botname
=
null
;
if
(
StringUtils
.
isNotBlank
(
serverName
))
{
botname
=
request
.
getBotname
();
}
if
(
StringUtils
.
isBlank
(
botname
))
{
OfflineServiceUtil
.
onlineCacheResponse
(
response
,
new
OfflineOnlineCacheResponse
(
401
,
"no botname"
),
401
);
return
;
}
StringBuilder
builder
=
new
StringBuilder
(
"offline"
).
append
(
File
.
separator
);
if
(
StringUtils
.
isNotBlank
(
serverName
))
builder
.
append
(
serverName
).
append
(
File
.
separator
);
if
(
StringUtils
.
isNotBlank
(
botname
))
builder
.
append
(
botname
);
String
botDir
=
builder
.
toString
();
if
(
TTSUtils
.
doesFileExist
(
botDir
))
{
TTSUtils
.
deleteFile
(
new
File
(
botDir
));
log
.
info
(
"删除目录{}成功"
,
botDir
);
}
OfflineServiceUtil
.
onlineCacheResponse
(
response
,
new
OfflineOnlineCacheResponse
(
200
),
200
);
}
}
tts_service/src/main/resources/application.yml
View file @
0bfe5351
...
...
@@ -19,3 +19,14 @@ spring:
# path: /usr/mqw/logs/tts
server
:
port
:
8088
offline
:
output_dir
:
'
offline'
short_audio_dir
:
'
short_audio'
letter_audio_dir
:
'
letter_audio'
test_text
:
'
这是一段测试文本,请听下音效,选择你认为合适的一套声音'
# hz1
mysql_host
:
'
47.98.37.248'
mysql_user
:
'
tts'
mysql_password
:
'
qiwu@123234aA~'
models_threads
:
3
\ No newline at end of file
xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/service/ResponseEncapsulation.java
View file @
0bfe5351
...
...
@@ -227,11 +227,12 @@ public class ResponseEncapsulation extends AudioPlayer {
String
audioUrl
=
data
.
getAudio
();
logger
.
info
(
getSupportedInterfaces
().
getAudioPlayer
()
==
null
?
"audio is null"
:
"audio not null"
);
logger
.
info
(
getSupportedInterfaces
().
getScreen
()
==
null
?
"screen is null"
:
"screen not null"
);
if
(
getSupportedInterfaces
().
getScreen
()
==
null
)
{
addDirective
(
buildNoScreenPlayDirec
(
audioUrl
,
AudioPlayerDirective
.
PlayBehaviorType
.
REPLACE_ALL
));
}
else
{
// if (getSupportedInterfaces().getScreen() == null) {
// addDirective(buildNoScreenPlayDirec(audioUrl, AudioPlayerDirective.PlayBehaviorType.REPLACE_ALL));
// }else {
// addDirective(buildPlayDirective(audioUrl, data.getText(), AudioPlayerDirective.PlayBehaviorType.REPLACE_ALL));
// }
addDirective
(
buildPlayDirective
(
audioUrl
,
data
.
getText
(),
AudioPlayerDirective
.
PlayBehaviorType
.
REPLACE_ALL
));
}
// String uri = "https://aliyun-hz1.chewrobot.com/xiaodu/image/5b2d0a11/lvzhou/1564033095964d39f.jpg";
// ImageStructure imageStructure = new ImageStructure(uri, 512, 512);
...
...
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