Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
DeepSpeech
提交
6c57c2bf
D
DeepSpeech
项目概览
PaddlePaddle
/
DeepSpeech
大约 1 年 前同步成功
通知
206
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,发现更多精彩内容 >>
提交
6c57c2bf
编写于
5月 25, 2022
作者:
K
KP
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Dynamic cli commands registration.
上级
1a8b478b
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
36 addition
and
27 deletion
+36
-27
paddlespeech/cli/__init__.py
paddlespeech/cli/__init__.py
+0
-7
paddlespeech/cli/asr/infer.py
paddlespeech/cli/asr/infer.py
+0
-3
paddlespeech/cli/base_commands.py
paddlespeech/cli/base_commands.py
+18
-0
paddlespeech/cli/cls/infer.py
paddlespeech/cli/cls/infer.py
+1
-4
paddlespeech/cli/entry.py
paddlespeech/cli/entry.py
+5
-0
paddlespeech/cli/st/infer.py
paddlespeech/cli/st/infer.py
+0
-3
paddlespeech/cli/text/infer.py
paddlespeech/cli/text/infer.py
+0
-2
paddlespeech/cli/tts/infer.py
paddlespeech/cli/tts/infer.py
+0
-3
paddlespeech/cli/utils.py
paddlespeech/cli/utils.py
+11
-0
paddlespeech/cli/vector/infer.py
paddlespeech/cli/vector/infer.py
+1
-5
未找到文件。
paddlespeech/cli/__init__.py
浏览文件 @
6c57c2bf
...
...
@@ -13,14 +13,7 @@
# limitations under the License.
import
_locale
from
.asr
import
ASRExecutor
from
.base_commands
import
BaseCommand
from
.base_commands
import
HelpCommand
from
.cls
import
CLSExecutor
from
.st
import
STExecutor
from
.stats
import
StatsExecutor
from
.text
import
TextExecutor
from
.tts
import
TTSExecutor
from
.vector
import
VectorExecutor
_locale
.
_getdefaultlocale
=
(
lambda
*
args
:
[
'en_US'
,
'utf8'
])
paddlespeech/cli/asr/infer.py
浏览文件 @
6c57c2bf
...
...
@@ -29,7 +29,6 @@ from yacs.config import CfgNode
from
..download
import
get_path_from_url
from
..executor
import
BaseExecutor
from
..log
import
logger
from
..utils
import
cli_register
from
..utils
import
CLI_TIMER
from
..utils
import
MODEL_HOME
from
..utils
import
stats_wrapper
...
...
@@ -45,8 +44,6 @@ __all__ = ['ASRExecutor']
@
timer_register
@
cli_register
(
name
=
'paddlespeech.asr'
,
description
=
'Speech to text infer command.'
)
class
ASRExecutor
(
BaseExecutor
):
def
__init__
(
self
):
super
().
__init__
()
...
...
paddlespeech/cli/base_commands.py
浏览文件 @
6c57c2bf
...
...
@@ -15,6 +15,7 @@ from typing import List
from
.entry
import
commands
from
.utils
import
cli_register
from
.utils
import
explicit_command_register
from
.utils
import
get_command
__all__
=
[
...
...
@@ -73,3 +74,20 @@ class VersionCommand:
print
(
msg
)
return
True
# Dynamic import when running specific command
_commands
=
{
'asr'
:
[
'Speech to text infer command.'
,
'ASRExecutor'
],
'cls'
:
[
'Audio classification infer command.'
,
'CLSExecutor'
],
'st'
:
[
'Speech translation infer command.'
,
'STExecutor'
],
'text'
:
[
'Text command.'
,
'TextExecutor'
],
'tts'
:
[
'Text to Speech infer command.'
,
'TTSExecutor'
],
'vector'
:
[
'Speech to vector embedding infer command.'
,
'VectorExecutor'
],
}
for
com
,
info
in
_commands
.
items
():
explicit_command_register
(
name
=
'paddlespeech.{}'
.
format
(
com
),
description
=
info
[
0
],
cls
=
'paddlespeech.cli.{}.{}'
.
format
(
com
,
info
[
1
]))
paddlespeech/cli/cls/infer.py
浏览文件 @
6c57c2bf
...
...
@@ -27,7 +27,6 @@ from paddlespeech.utils.dynamic_import import dynamic_import
from
..executor
import
BaseExecutor
from
..log
import
logger
from
..utils
import
cli_register
from
..utils
import
stats_wrapper
from
.pretrained_models
import
model_alias
from
.pretrained_models
import
pretrained_models
...
...
@@ -36,8 +35,6 @@ from .pretrained_models import pretrained_models
__all__
=
[
'CLSExecutor'
]
@
cli_register
(
name
=
'paddlespeech.cls'
,
description
=
'Audio classification infer command.'
)
class
CLSExecutor
(
BaseExecutor
):
def
__init__
(
self
):
super
().
__init__
()
...
...
@@ -246,4 +243,4 @@ class CLSExecutor(BaseExecutor):
self
.
infer
()
res
=
self
.
postprocess
(
topk
)
# Retrieve result of cls.
return
res
\ No newline at end of file
return
res
paddlespeech/cli/entry.py
浏览文件 @
6c57c2bf
...
...
@@ -34,6 +34,11 @@ def _execute():
# 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.
if
not
callable
(
com
[
'_entry'
]):
i
=
com
[
'_entry'
].
rindex
(
'.'
)
module
,
cls
=
com
[
'_entry'
][:
i
],
com
[
'_entry'
][
i
+
1
:]
exec
(
"from {} import {}"
.
format
(
module
,
cls
))
com
[
'_entry'
]
=
locals
()[
cls
]
status
=
0
if
com
[
'_entry'
]().
execute
(
sys
.
argv
[
idx
:])
else
1
return
status
...
...
paddlespeech/cli/st/infer.py
浏览文件 @
6c57c2bf
...
...
@@ -28,7 +28,6 @@ from yacs.config import CfgNode
from
..executor
import
BaseExecutor
from
..log
import
logger
from
..utils
import
cli_register
from
..utils
import
download_and_decompress
from
..utils
import
MODEL_HOME
from
..utils
import
stats_wrapper
...
...
@@ -42,8 +41,6 @@ from paddlespeech.utils.dynamic_import import dynamic_import
__all__
=
[
"STExecutor"
]
@
cli_register
(
name
=
"paddlespeech.st"
,
description
=
"Speech translation infer command."
)
class
STExecutor
(
BaseExecutor
):
def
__init__
(
self
):
super
().
__init__
()
...
...
paddlespeech/cli/text/infer.py
浏览文件 @
6c57c2bf
...
...
@@ -23,7 +23,6 @@ import paddle
from
..executor
import
BaseExecutor
from
..log
import
logger
from
..utils
import
cli_register
from
..utils
import
stats_wrapper
from
.pretrained_models
import
model_alias
from
.pretrained_models
import
pretrained_models
...
...
@@ -33,7 +32,6 @@ from paddlespeech.utils.dynamic_import import dynamic_import
__all__
=
[
'TextExecutor'
]
@
cli_register
(
name
=
'paddlespeech.text'
,
description
=
'Text infer command.'
)
class
TextExecutor
(
BaseExecutor
):
def
__init__
(
self
):
super
().
__init__
()
...
...
paddlespeech/cli/tts/infer.py
浏览文件 @
6c57c2bf
...
...
@@ -28,7 +28,6 @@ from yacs.config import CfgNode
from
..executor
import
BaseExecutor
from
..log
import
logger
from
..utils
import
cli_register
from
..utils
import
stats_wrapper
from
.pretrained_models
import
model_alias
from
.pretrained_models
import
pretrained_models
...
...
@@ -40,8 +39,6 @@ from paddlespeech.utils.dynamic_import import dynamic_import
__all__
=
[
'TTSExecutor'
]
@
cli_register
(
name
=
'paddlespeech.tts'
,
description
=
'Text to Speech infer command.'
)
class
TTSExecutor
(
BaseExecutor
):
def
__init__
(
self
):
super
().
__init__
()
...
...
paddlespeech/cli/utils.py
浏览文件 @
6c57c2bf
...
...
@@ -41,6 +41,7 @@ requests.adapters.DEFAULT_RETRIES = 3
__all__
=
[
'timer_register'
,
'cli_register'
,
'explicit_command_register'
,
'get_command'
,
'download_and_decompress'
,
'load_state_dict_from_url'
,
...
...
@@ -70,6 +71,16 @@ def cli_register(name: str, description: str='') -> Any:
return
_warpper
def
explicit_command_register
(
name
:
str
,
description
:
str
=
''
,
cls
:
str
=
''
):
items
=
name
.
split
(
'.'
)
com
=
commands
for
item
in
items
:
com
=
com
[
item
]
com
[
'_entry'
]
=
cls
if
description
:
com
[
'_description'
]
=
description
def
get_command
(
name
:
str
)
->
Any
:
items
=
name
.
split
(
'.'
)
com
=
commands
...
...
paddlespeech/cli/vector/infer.py
浏览文件 @
6c57c2bf
...
...
@@ -28,7 +28,6 @@ from yacs.config import CfgNode
from
..executor
import
BaseExecutor
from
..log
import
logger
from
..utils
import
cli_register
from
..utils
import
stats_wrapper
from
.pretrained_models
import
model_alias
from
.pretrained_models
import
pretrained_models
...
...
@@ -37,9 +36,6 @@ from paddlespeech.vector.io.batch import feature_normalize
from
paddlespeech.vector.modules.sid_model
import
SpeakerIdetification
@
cli_register
(
name
=
"paddlespeech.vector"
,
description
=
"Speech to vector embedding infer command."
)
class
VectorExecutor
(
BaseExecutor
):
def
__init__
(
self
):
super
().
__init__
()
...
...
@@ -476,4 +472,4 @@ class VectorExecutor(BaseExecutor):
else
:
logger
.
info
(
"The audio file format is right"
)
return
True
\ No newline at end of file
return
True
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录