Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
DeepSpeech
提交
43f4d47b
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,发现更多精彩内容 >>
提交
43f4d47b
编写于
11月 30, 2021
作者:
H
huangyuxin
浏览文件
操作
浏览文件
下载
差异文件
add the call in infer.py
上级
cdc85209
c94ebdc5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
40 addition
and
39 deletion
+40
-39
paddlespeech/cli/executor.py
paddlespeech/cli/executor.py
+15
-0
paddlespeech/cli/s2t/infer.py
paddlespeech/cli/s2t/infer.py
+25
-39
未找到文件。
paddlespeech/cli/executor.py
浏览文件 @
43f4d47b
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
import
os
import
os
from
abc
import
ABC
from
abc
import
ABC
from
abc
import
abstractmethod
from
abc
import
abstractmethod
from
typing
import
List
from
typing
import
Union
from
typing
import
Union
import
paddle
import
paddle
...
@@ -64,3 +65,17 @@ class BaseExecutor(ABC):
...
@@ -64,3 +65,17 @@ class BaseExecutor(ABC):
Output postprocess and return human-readable results such as texts and audio files.
Output postprocess and return human-readable results such as texts and audio files.
"""
"""
pass
pass
@
abstractmethod
def
execute
(
self
,
argv
:
List
[
str
])
->
bool
:
"""
Command line entry.
"""
pass
@
abstractmethod
def
__call__
(
self
,
*
arg
,
**
kwargs
):
"""
Python API to call an executor.
"""
pass
paddlespeech/cli/s2t/infer.py
浏览文件 @
43f4d47b
...
@@ -18,13 +18,14 @@ from typing import List
...
@@ -18,13 +18,14 @@ from typing import List
from
typing
import
Optional
from
typing
import
Optional
from
typing
import
Union
from
typing
import
Union
import
soundfile
import
paddle
import
paddle
from
paddlespeech.cli.executor
import
BaseExecutor
import
soundfile
from
paddlespeech.cli.utils
import
cli_register
from
paddlespeech.cli.utils
import
download_and_decompress
from
..executor
import
BaseExecutor
from
paddlespeech.cli.utils
import
logger
from
..utils
import
cli_register
from
paddlespeech.cli.utils
import
MODEL_HOME
from
..utils
import
download_and_decompress
from
..utils
import
logger
from
..utils
import
MODEL_HOME
from
paddlespeech.s2t.exps.u2.config
import
get_cfg_defaults
from
paddlespeech.s2t.exps.u2.config
import
get_cfg_defaults
from
paddlespeech.s2t.frontend.featurizer.text_featurizer
import
TextFeaturizer
from
paddlespeech.s2t.frontend.featurizer.text_featurizer
import
TextFeaturizer
from
paddlespeech.s2t.io.collator
import
SpeechCollator
from
paddlespeech.s2t.io.collator
import
SpeechCollator
...
@@ -55,29 +56,6 @@ model_alias = {
...
@@ -55,29 +56,6 @@ model_alias = {
"wenetspeech"
:
"paddlespeech.s2t.models.u2:U2Model"
,
"wenetspeech"
:
"paddlespeech.s2t.models.u2:U2Model"
,
}
}
pretrain_model_alias
=
{
"ds2_online_zn"
:
[
"https://paddlespeech.bj.bcebos.com/s2t/aishell/asr0/aishell_ds2_online_cer8.00_release.tar.gz"
,
""
,
""
],
"ds2_offline_zn"
:
[
"https://paddlespeech.bj.bcebos.com/s2t/aishell/asr0/ds2.model.tar.gz"
,
""
,
""
],
"transformer_zn"
:
[
"https://paddlespeech.bj.bcebos.com/s2t/aishell/asr1/transformer.model.tar.gz"
,
""
,
""
],
"conformer_zn"
:
[
"https://paddlespeech.bj.bcebos.com/s2t/wenetspeech/conformer.model.tar.gz"
,
""
,
""
],
"wenetspeech_zn"
:
[
"https://paddlespeech.bj.bcebos.com/s2t/wenetspeech/conformer.model.tar.gz"
,
"conf/conformer.yaml"
,
"exp/conformer/checkpoints/wenetspeech"
],
}
@
cli_register
(
@
cli_register
(
name
=
'paddlespeech.s2t'
,
description
=
'Speech to text infer command.'
)
name
=
'paddlespeech.s2t'
,
description
=
'Speech to text infer command.'
)
...
@@ -107,7 +85,6 @@ class S2TExecutor(BaseExecutor):
...
@@ -107,7 +85,6 @@ class S2TExecutor(BaseExecutor):
self
.
parser
.
add_argument
(
self
.
parser
.
add_argument
(
'--input'
,
'--input'
,
type
=
str
,
type
=
str
,
default
=
"../Downloads/asr-demo-1.wav"
,
help
=
'Audio file to recognize.'
)
help
=
'Audio file to recognize.'
)
self
.
parser
.
add_argument
(
self
.
parser
.
add_argument
(
'--device'
,
'--device'
,
...
@@ -155,7 +132,9 @@ class S2TExecutor(BaseExecutor):
...
@@ -155,7 +132,9 @@ class S2TExecutor(BaseExecutor):
res_path
=
os
.
path
.
dirname
(
res_path
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
self
.
cfg_path
)))
os
.
path
.
dirname
(
os
.
path
.
abspath
(
self
.
cfg_path
)))
# Enter the path of model root
os
.
chdir
(
res_path
)
os
.
chdir
(
res_path
)
#Init body.
#Init body.
parser_args
=
self
.
parser_args
parser_args
=
self
.
parser_args
paddle
.
set_device
(
parser_args
.
device
)
paddle
.
set_device
(
parser_args
.
device
)
...
@@ -206,7 +185,7 @@ class S2TExecutor(BaseExecutor):
...
@@ -206,7 +185,7 @@ class S2TExecutor(BaseExecutor):
config
=
self
.
config
config
=
self
.
config
audio_file
=
input
audio_file
=
input
#print("audio_file", audio_file)
#print("audio_file", audio_file)
logger
.
info
(
"audio_file"
+
audio_file
)
logger
.
info
(
"audio_file"
+
audio_file
)
self
.
sr
=
config
.
collator
.
target_sample_rate
self
.
sr
=
config
.
collator
.
target_sample_rate
...
@@ -307,7 +286,11 @@ class S2TExecutor(BaseExecutor):
...
@@ -307,7 +286,11 @@ class S2TExecutor(BaseExecutor):
return
self
.
result_transcripts
return
self
.
result_transcripts
def
execute
(
self
,
argv
:
List
[
str
])
->
bool
:
def
execute
(
self
,
argv
:
List
[
str
])
->
bool
:
"""
Command line entry.
"""
self
.
parser_args
=
self
.
parser
.
parse_args
(
argv
)
self
.
parser_args
=
self
.
parser
.
parse_args
(
argv
)
print
(
self
.
parser_args
)
model
=
self
.
parser_args
.
model
model
=
self
.
parser_args
.
model
lang
=
self
.
parser_args
.
lang
lang
=
self
.
parser_args
.
lang
...
@@ -317,17 +300,20 @@ class S2TExecutor(BaseExecutor):
...
@@ -317,17 +300,20 @@ class S2TExecutor(BaseExecutor):
device
=
self
.
parser_args
.
device
device
=
self
.
parser_args
.
device
try
:
try
:
self
.
_init_from_path
(
model
,
lang
,
config
,
ckpt_path
)
res
=
self
(
model
,
lang
,
config
,
ckpt_path
,
audio_file
,
device
)
self
.
preprocess
(
audio_file
)
print
(
res
)
self
.
infer
()
res
=
self
.
postprocess
()
# Retrieve result of s2t.
logger
.
info
(
res
)
return
True
return
True
except
Exception
as
e
:
except
Exception
as
e
:
print
(
e
)
print
(
e
)
return
False
return
False
def
__call__
(
self
,
model
,
lang
,
config
,
ckpt_path
,
audio_file
,
device
):
"""
Python API to call an executor.
"""
self
.
_init_from_path
(
model
,
lang
,
config
,
ckpt_path
)
self
.
preprocess
(
audio_file
)
self
.
infer
()
res
=
self
.
postprocess
()
# Retrieve result of s2t.
if
__name__
==
"__main__"
:
return
res
exe
=
S2TExecutor
()
exe
.
execute
(
''
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录