Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
DeepSpeech
提交
09171123
D
DeepSpeech
项目概览
PaddlePaddle
/
DeepSpeech
大约 1 年 前同步成功
通知
207
Star
8425
Fork
1598
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
245
列表
看板
标记
里程碑
合并请求
3
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
DeepSpeech
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
245
Issue
245
列表
看板
标记
里程碑
合并请求
3
合并请求
3
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
09171123
编写于
2月 22, 2022
作者:
H
Hui Zhang
提交者:
GitHub
2月 22, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1470 from lym0302/server-cli
[server] improve cli code
上级
6b94abd6
42cbe313
变更
8
显示空白变更内容
内联
并排
Showing
8 changed file
with
163 addition
and
34 deletion
+163
-34
paddlespeech/server/__init__.py
paddlespeech/server/__init__.py
+7
-4
paddlespeech/server/base_commands.py
paddlespeech/server/base_commands.py
+45
-12
paddlespeech/server/bin/__init__.py
paddlespeech/server/bin/__init__.py
+2
-0
paddlespeech/server/bin/paddlespeech_client.py
paddlespeech/server/bin/paddlespeech_client.py
+47
-3
paddlespeech/server/bin/paddlespeech_server.py
paddlespeech/server/bin/paddlespeech_server.py
+5
-2
paddlespeech/server/entry.py
paddlespeech/server/entry.py
+21
-5
paddlespeech/server/util.py
paddlespeech/server/util.py
+34
-7
setup.py
setup.py
+2
-1
未找到文件。
paddlespeech/server/__init__.py
浏览文件 @
09171123
...
...
@@ -13,9 +13,12 @@
# limitations under the License.
import
_locale
from
.base_commands
import
BaseCommand
from
.base_commands
import
HelpCommand
from
paddlespeech.server.bin.paddlespeech_client
import
TTSClientExecutor
from
paddlespeech.server.bin.paddlespeech_server
import
ServerExecutor
from
.base_commands
import
ClientBaseCommand
from
.base_commands
import
ClientHelpCommand
from
.base_commands
import
ServerBaseCommand
from
.base_commands
import
ServerHelpCommand
from
.bin.paddlespeech_client
import
ASRClientExecutor
from
.bin.paddlespeech_client
import
TTSClientExecutor
from
.bin.paddlespeech_server
import
ServerExecutor
_locale
.
_getdefaultlocale
=
(
lambda
*
args
:
[
'en_US'
,
'utf8'
])
paddlespeech/server/base_commands.py
浏览文件 @
09171123
...
...
@@ -13,30 +13,63 @@
# limitations under the License.
from
typing
import
List
from
.entry
import
commands
from
.util
import
cli_register
from
.util
import
get_command
from
.entry
import
client_commands
from
.entry
import
server_commands
from
.util
import
cli_client_register
from
.util
import
cli_server_register
from
.util
import
get_client_command
from
.util
import
get_server_command
__all__
=
[
'BaseCommand'
,
'HelpCommand'
,
'ServerBaseCommand'
,
'ServerHelpCommand'
,
'ClientBaseCommand'
,
'ClientHelpCommand'
,
]
@
cli_
register
(
name
=
'paddle
server'
)
class
BaseCommand
:
@
cli_
server_register
(
name
=
'paddlespeech_
server'
)
class
Server
BaseCommand
:
def
execute
(
self
,
argv
:
List
[
str
])
->
bool
:
help
=
get_
command
(
'paddle
server.help'
)
help
=
get_
server_command
(
'paddlespeech_
server.help'
)
return
help
().
execute
(
argv
)
@
cli_register
(
name
=
'paddleserver.help'
,
description
=
'Show help for commands.'
)
class
HelpCommand
:
@
cli_server_register
(
name
=
'paddlespeech_server.help'
,
description
=
'Show help for commands.'
)
class
ServerHelpCommand
:
def
execute
(
self
,
argv
:
List
[
str
])
->
bool
:
msg
=
'Usage:
\n
'
msg
+=
' paddleserver <command> <options>
\n\n
'
msg
+=
' paddles
peech_s
erver <command> <options>
\n\n
'
msg
+=
'Commands:
\n
'
for
command
,
detail
in
commands
[
'paddleserver'
].
items
():
for
command
,
detail
in
server_commands
[
'paddlespeech_server'
].
items
():
if
command
.
startswith
(
'_'
):
continue
if
'_description'
not
in
detail
:
continue
msg
+=
' {:<15} {}
\n
'
.
format
(
command
,
detail
[
'_description'
])
print
(
msg
)
return
True
@
cli_client_register
(
name
=
'paddlespeech_client'
)
class
ClientBaseCommand
:
def
execute
(
self
,
argv
:
List
[
str
])
->
bool
:
help
=
get_client_command
(
'paddlespeech_client.help'
)
return
help
().
execute
(
argv
)
@
cli_client_register
(
name
=
'paddlespeech_client.help'
,
description
=
'Show help for commands.'
)
class
ClientHelpCommand
:
def
execute
(
self
,
argv
:
List
[
str
])
->
bool
:
msg
=
'Usage:
\n
'
msg
+=
' paddlespeech_client <command> <options>
\n\n
'
msg
+=
'Commands:
\n
'
for
command
,
detail
in
client_commands
[
'paddlespeech_client'
].
items
():
if
command
.
startswith
(
'_'
):
continue
...
...
paddlespeech/server/bin/__init__.py
浏览文件 @
09171123
...
...
@@ -11,4 +11,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
.paddlespeech_client
import
ASRClientExecutor
from
.paddlespeech_client
import
TTSClientExecutor
from
.paddlespeech_server
import
ServerExecutor
paddlespeech/server/bin/paddlespeech_client.py
浏览文件 @
09171123
...
...
@@ -24,11 +24,15 @@ import numpy as np
import
requests
import
soundfile
from
paddlespeech.server.util
import
cli
_register
from
..util
import
cli_client
_register
from
paddlespeech.server.utils.audio_process
import
wav2pcm
from
paddlespeech.server.utils.util
import
wav2base64
__all__
=
[
'TTSClientExecutor'
,
'ASRClientExecutor'
]
@
cli_register
(
name
=
'paddleserver.ttsclient'
,
description
=
'visit tts service'
)
@
cli_client_register
(
name
=
'paddlespeech_client.tts'
,
description
=
'visit tts service'
)
class
TTSClientExecutor
():
def
__init__
(
self
):
super
().
__init__
()
...
...
@@ -79,6 +83,7 @@ class TTSClientExecutor():
response
=
requests
.
post
(
url
,
json
.
dumps
(
request
))
response_dict
=
response
.
json
()
print
(
response_dict
[
"message"
])
wav_base64
=
response_dict
[
"result"
][
"audio"
]
audio_data_byte
=
base64
.
b64decode
(
wav_base64
)
...
...
@@ -107,6 +112,45 @@ class TTSClientExecutor():
samples_length
,
sample_rate
=
self
.
tts_client
(
args
)
time_consume
=
time
.
time
()
-
st
print
(
"Save synthesized audio successfully on %s."
%
(
args
.
output
))
print
(
"Inference time: %f"
%
(
time_consume
))
print
(
"Inference time: %f
s.
"
%
(
time_consume
))
except
:
print
(
"Failed to synthesized audio."
)
@
cli_client_register
(
name
=
'paddlespeech_client.asr'
,
description
=
'visit asr service'
)
class
ASRClientExecutor
():
def
__init__
(
self
):
super
().
__init__
()
self
.
parser
=
argparse
.
ArgumentParser
()
self
.
parser
.
add_argument
(
'--server_ip'
,
type
=
str
,
default
=
'127.0.0.1'
,
help
=
'server ip'
)
self
.
parser
.
add_argument
(
'--port'
,
type
=
int
,
default
=
8090
,
help
=
'server port'
)
self
.
parser
.
add_argument
(
'--audio_file'
,
type
=
str
,
default
=
"./paddlespeech/server/tests/16_audio.wav"
,
help
=
'Audio file to be recognized'
)
self
.
parser
.
add_argument
(
'--sample_rate'
,
type
=
int
,
default
=
16000
,
help
=
'audio sample rate'
)
def
execute
(
self
,
argv
:
List
[
str
])
->
bool
:
args
=
self
.
parser
.
parse_args
(
argv
)
url
=
'http://'
+
args
.
server_ip
+
":"
+
str
(
args
.
port
)
+
'/paddlespeech/asr'
audio
=
wav2base64
(
args
.
audio_file
)
data
=
{
"audio"
:
audio
,
"audio_format"
:
"wav"
,
"sample_rate"
:
args
.
sample_rate
,
"lang"
:
"zh_cn"
,
}
time_start
=
time
.
time
()
try
:
r
=
requests
.
post
(
url
=
url
,
data
=
json
.
dumps
(
data
))
# ending Timestamp
time_end
=
time
.
time
()
print
(
'time cost'
,
time_end
-
time_start
,
's'
)
except
:
print
(
"Failed to speech recognition."
)
paddlespeech/server/bin/paddlespeech_server.py
浏览文件 @
09171123
...
...
@@ -17,16 +17,19 @@ from typing import List
import
uvicorn
from
fastapi
import
FastAPI
from
..util
import
cli_server_register
from
paddlespeech.server.engine.engine_factory
import
EngineFactory
from
paddlespeech.server.restful.api
import
setup_router
from
paddlespeech.server.util
import
cli_register
from
paddlespeech.server.utils.config
import
get_config
__all__
=
[
'ServerExecutor'
]
app
=
FastAPI
(
title
=
"PaddleSpeech Serving API"
,
description
=
"Api"
,
version
=
"0.0.1"
)
@
cli_register
(
name
=
'paddleserver.server'
,
description
=
'Start the service'
)
@
cli_server_register
(
name
=
'paddlespeech_server.server'
,
description
=
'Start the service'
)
class
ServerExecutor
():
def
__init__
(
self
):
super
().
__init__
()
...
...
paddlespeech/server/entry.py
浏览文件 @
09171123
...
...
@@ -14,18 +14,33 @@
import
sys
from
collections
import
defaultdict
__all__
=
[
'commands'
]
__all__
=
[
'
server_commands'
,
'client_
commands'
]
def
_CommandDict
():
return
defaultdict
(
_CommandDict
)
def
_execute
():
com
=
commands
def
server_execute
():
com
=
server_commands
idx
=
0
for
_argv
in
([
'paddlespeech_server'
]
+
sys
.
argv
[
1
:]):
if
_argv
not
in
com
:
break
idx
+=
1
com
=
com
[
_argv
]
# The method 'execute' of a command instance returns 'True' for a success
# while 'False' for a failure. Here converts this result into a exit status
# in bash: 0 for a success and 1 for a failure.
status
=
0
if
com
[
'_entry'
]().
execute
(
sys
.
argv
[
idx
:])
else
1
return
status
def
client_execute
():
com
=
client_commands
idx
=
0
for
_argv
in
([
'paddles
erver
'
]
+
sys
.
argv
[
1
:]):
for
_argv
in
([
'paddles
peech_client
'
]
+
sys
.
argv
[
1
:]):
if
_argv
not
in
com
:
break
idx
+=
1
...
...
@@ -38,4 +53,5 @@ def _execute():
return
status
commands
=
_CommandDict
()
server_commands
=
_CommandDict
()
client_commands
=
_CommandDict
()
paddlespeech/server/util.py
浏览文件 @
09171123
...
...
@@ -31,24 +31,27 @@ from paddle.framework import load
import
paddleaudio
from
.
import
download
from
..
import
__version__
from
.entry
import
commands
from
.entry
import
client_commands
from
.entry
import
server_commands
requests
.
adapters
.
DEFAULT_RETRIES
=
3
__all__
=
[
'cli_register'
,
'get_command'
,
'cli_server_register'
,
'get_server_command'
,
'cli_client_register'
,
'get_client_command'
,
'download_and_decompress'
,
'load_state_dict_from_url'
,
'stats_wrapper'
,
]
def
cli_register
(
name
:
str
,
description
:
str
=
''
)
->
Any
:
def
cli_
server_
register
(
name
:
str
,
description
:
str
=
''
)
->
Any
:
def
_warpper
(
command
):
items
=
name
.
split
(
'.'
)
com
=
commands
com
=
server_
commands
for
item
in
items
:
com
=
com
[
item
]
com
[
'_entry'
]
=
command
...
...
@@ -59,9 +62,33 @@ def cli_register(name: str, description: str='') -> Any:
return
_warpper
def
get_command
(
name
:
str
)
->
Any
:
def
get_
server_
command
(
name
:
str
)
->
Any
:
items
=
name
.
split
(
'.'
)
com
=
commands
com
=
server_commands
for
item
in
items
:
com
=
com
[
item
]
return
com
[
'_entry'
]
def
cli_client_register
(
name
:
str
,
description
:
str
=
''
)
->
Any
:
def
_warpper
(
command
):
items
=
name
.
split
(
'.'
)
com
=
client_commands
for
item
in
items
:
com
=
com
[
item
]
com
[
'_entry'
]
=
command
if
description
:
com
[
'_description'
]
=
description
return
command
return
_warpper
def
get_client_command
(
name
:
str
)
->
Any
:
items
=
name
.
split
(
'.'
)
com
=
client_commands
for
item
in
items
:
com
=
com
[
item
]
...
...
setup.py
浏览文件 @
09171123
...
...
@@ -236,7 +236,8 @@ setup_info = dict(
entry_points
=
{
'console_scripts'
:
[
'paddlespeech=paddlespeech.cli.entry:_execute'
,
'paddleserver=paddlespeech.server.entry:_execute'
'paddlespeech_server=paddlespeech.server.entry:server_execute'
,
'paddlespeech_client=paddlespeech.server.entry:client_execute'
]
})
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录