Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
DeepSpeech
提交
162361d8
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,发现更多精彩内容 >>
提交
162361d8
编写于
2月 25, 2022
作者:
L
lym0302
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
format code, test=doc
上级
434708cf
变更
15
显示空白变更内容
内联
并排
Showing
15 changed file
with
65 addition
and
63 deletion
+65
-63
paddlespeech/server/bin/main.py
paddlespeech/server/bin/main.py
+1
-1
paddlespeech/server/bin/paddlespeech_client.py
paddlespeech/server/bin/paddlespeech_client.py
+4
-4
paddlespeech/server/engine/asr/paddleinference/asr_engine.py
paddlespeech/server/engine/asr/paddleinference/asr_engine.py
+15
-23
paddlespeech/server/engine/base_engine.py
paddlespeech/server/engine/base_engine.py
+0
-2
paddlespeech/server/engine/engine_factory.py
paddlespeech/server/engine/engine_factory.py
+0
-1
paddlespeech/server/engine/engine_pool.py
paddlespeech/server/engine/engine_pool.py
+4
-2
paddlespeech/server/engine/tts/paddleinference/tts_engine.py
paddlespeech/server/engine/tts/paddleinference/tts_engine.py
+11
-5
paddlespeech/server/engine/tts/python/tts_engine.py
paddlespeech/server/engine/tts/python/tts_engine.py
+13
-6
paddlespeech/server/restful/asr_api.py
paddlespeech/server/restful/asr_api.py
+2
-1
paddlespeech/server/restful/request.py
paddlespeech/server/restful/request.py
+0
-1
paddlespeech/server/restful/response.py
paddlespeech/server/restful/response.py
+0
-3
paddlespeech/server/restful/tts_api.py
paddlespeech/server/restful/tts_api.py
+1
-1
paddlespeech/server/tests/asr/http_client.py
paddlespeech/server/tests/asr/http_client.py
+11
-11
paddlespeech/server/tests/tts/test_client.py
paddlespeech/server/tests/tts/test_client.py
+2
-1
paddlespeech/server/util.py
paddlespeech/server/util.py
+1
-1
未找到文件。
paddlespeech/server/bin/main.py
浏览文件 @
162361d8
...
...
@@ -12,8 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import
argparse
import
uvicorn
import
yaml
from
fastapi
import
FastAPI
from
paddlespeech.server.engine.engine_pool
import
init_engine_pool
...
...
paddlespeech/server/bin/paddlespeech_client.py
浏览文件 @
162361d8
...
...
@@ -124,7 +124,7 @@ class TTSClientExecutor(BaseExecutor):
logger
.
info
(
"RTF: %f "
%
(
time_consume
/
duration
))
return
True
except
:
except
BaseException
:
logger
.
error
(
"Failed to synthesized audio."
)
return
False
...
...
@@ -164,7 +164,7 @@ class TTSClientExecutor(BaseExecutor):
print
(
"Audio duration: %f s."
%
(
duration
))
print
(
"Response time: %f s."
%
(
time_consume
))
print
(
"RTF: %f "
%
(
time_consume
/
duration
))
except
:
except
BaseException
:
print
(
"Failed to synthesized audio."
)
...
...
@@ -211,7 +211,7 @@ class ASRClientExecutor(BaseExecutor):
logger
.
info
(
r
.
json
())
logger
.
info
(
"time cost %f s."
%
(
time_end
-
time_start
))
return
True
except
:
except
BaseException
:
logger
.
error
(
"Failed to speech recognition."
)
return
False
...
...
@@ -242,5 +242,5 @@ class ASRClientExecutor(BaseExecutor):
time_end
=
time
.
time
()
print
(
r
.
json
())
print
(
"time cost %f s."
%
(
time_end
-
time_start
))
except
:
except
BaseException
:
print
(
"Failed to speech recognition."
)
paddlespeech/server/engine/asr/paddleinference/asr_engine.py
浏览文件 @
162361d8
...
...
@@ -13,31 +13,24 @@
# limitations under the License.
import
io
import
os
from
typing
import
List
from
typing
import
Optional
from
typing
import
Union
import
librosa
import
paddle
import
soundfile
from
yacs.config
import
CfgNode
from
paddlespeech.cli.utils
import
MODEL_HOME
from
paddlespeech.s2t.modules.ctc
import
CTCDecoder
from
paddlespeech.cli.asr.infer
import
ASRExecutor
from
paddlespeech.cli.log
import
logger
from
paddlespeech.cli.utils
import
MODEL_HOME
from
paddlespeech.s2t.frontend.featurizer.text_featurizer
import
TextFeaturizer
from
paddlespeech.s2t.transform.transformation
import
Transformation
from
paddlespeech.s2t.utils.dynamic_import
import
dynamic_import
from
paddlespeech.s2t.modules.ctc
import
CTCDecoder
from
paddlespeech.s2t.utils.utility
import
UpdateConfig
from
paddlespeech.server.engine.base_engine
import
BaseEngine
from
paddlespeech.server.utils.config
import
get_config
from
paddlespeech.server.utils.paddle_predictor
import
init_predictor
from
paddlespeech.server.utils.paddle_predictor
import
run_model
from
paddlespeech.server.engine.base_engine
import
BaseEngine
__all__
=
[
'ASREngine'
]
pretrained_models
=
{
"deepspeech2offline_aishell-zh-16k"
:
{
'url'
:
...
...
@@ -143,7 +136,6 @@ class ASRServerExecutor(ASRExecutor):
batch_average
=
True
,
# sum / batch_size
grad_norm_type
=
self
.
config
.
get
(
'ctc_grad_norm_type'
,
None
))
@
paddle
.
no_grad
()
def
infer
(
self
,
model_type
:
str
):
"""
...
...
@@ -161,8 +153,7 @@ class ASRServerExecutor(ASRExecutor):
cfg
.
beam_size
,
cfg
.
cutoff_prob
,
cfg
.
cutoff_top_n
,
cfg
.
num_proc_bsearch
)
output_data
=
run_model
(
self
.
am_predictor
,
output_data
=
run_model
(
self
.
am_predictor
,
[
audio
.
numpy
(),
audio_len
.
numpy
()])
probs
=
output_data
[
0
]
...
...
@@ -230,7 +221,8 @@ class ASREngine(BaseEngine):
io
.
BytesIO
(
audio_data
),
self
.
config
.
sample_rate
,
self
.
config
.
force_yes
):
logger
.
info
(
"start running asr engine"
)
self
.
executor
.
preprocess
(
self
.
config
.
model_type
,
io
.
BytesIO
(
audio_data
))
self
.
executor
.
preprocess
(
self
.
config
.
model_type
,
io
.
BytesIO
(
audio_data
))
self
.
executor
.
infer
(
self
.
config
.
model_type
)
self
.
output
=
self
.
executor
.
postprocess
()
# Retrieve result of asr.
logger
.
info
(
"end inferring asr engine"
)
...
...
paddlespeech/server/engine/base_engine.py
浏览文件 @
162361d8
...
...
@@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import
os
from
typing
import
Any
from
typing
import
List
from
typing
import
Union
from
pattern_singleton
import
Singleton
...
...
paddlespeech/server/engine/engine_factory.py
浏览文件 @
162361d8
...
...
@@ -13,7 +13,6 @@
# limitations under the License.
from
typing
import
Text
__all__
=
[
'EngineFactory'
]
...
...
paddlespeech/server/engine/engine_pool.py
浏览文件 @
162361d8
...
...
@@ -29,8 +29,10 @@ def init_engine_pool(config) -> bool:
"""
global
ENGINE_POOL
for
engine
in
config
.
engine_backend
:
ENGINE_POOL
[
engine
]
=
EngineFactory
.
get_engine
(
engine_name
=
engine
,
engine_type
=
config
.
engine_type
[
engine
])
if
not
ENGINE_POOL
[
engine
].
init
(
config_file
=
config
.
engine_backend
[
engine
]):
ENGINE_POOL
[
engine
]
=
EngineFactory
.
get_engine
(
engine_name
=
engine
,
engine_type
=
config
.
engine_type
[
engine
])
if
not
ENGINE_POOL
[
engine
].
init
(
config_file
=
config
.
engine_backend
[
engine
]):
return
False
return
True
paddlespeech/server/engine/tts/paddleinference/tts_engine.py
浏览文件 @
162361d8
...
...
@@ -360,8 +360,8 @@ class TTSEngine(BaseEngine):
am_predictor_conf
=
self
.
config
.
am_predictor_conf
,
voc_predictor_conf
=
self
.
config
.
voc_predictor_conf
,
)
except
:
logger
.
info
(
"Initialize TTS server engine Failed."
)
except
BaseException
:
logger
.
error
(
"Initialize TTS server engine Failed."
)
return
False
logger
.
info
(
"Initialize TTS server engine successfully."
)
...
...
@@ -405,11 +405,13 @@ class TTSEngine(BaseEngine):
# transform speed
try
:
# windows not support soxbindings
wav_speed
=
change_speed
(
wav_vol
,
speed
,
target_fs
)
except
:
except
ServerBaseException
:
raise
ServerBaseException
(
ErrorCode
.
SERVER_INTERNAL_ERR
,
"Transform speed failed. Can not install soxbindings on your system.
\
You need to set speed value 1.0."
)
except
BaseException
:
logger
.
error
(
"Transform speed failed."
)
# wav to base64
buf
=
io
.
BytesIO
()
...
...
@@ -462,9 +464,11 @@ class TTSEngine(BaseEngine):
try
:
self
.
executor
.
infer
(
text
=
sentence
,
lang
=
lang
,
am
=
self
.
config
.
am
,
spk_id
=
spk_id
)
except
:
except
ServerBaseException
:
raise
ServerBaseException
(
ErrorCode
.
SERVER_INTERNAL_ERR
,
"tts infer failed."
)
except
BaseException
:
logger
.
error
(
"tts infer failed."
)
try
:
target_sample_rate
,
wav_base64
=
self
.
postprocess
(
...
...
@@ -474,8 +478,10 @@ class TTSEngine(BaseEngine):
volume
=
volume
,
speed
=
speed
,
audio_path
=
save_path
)
except
:
except
ServerBaseException
:
raise
ServerBaseException
(
ErrorCode
.
SERVER_INTERNAL_ERR
,
"tts postprocess failed."
)
except
BaseException
:
logger
.
error
(
"tts postprocess failed."
)
return
lang
,
target_sample_rate
,
wav_base64
paddlespeech/server/engine/tts/python/tts_engine.py
浏览文件 @
162361d8
...
...
@@ -72,8 +72,8 @@ class TTSEngine(BaseEngine):
voc_ckpt
=
self
.
config
.
voc_ckpt
,
voc_stat
=
self
.
config
.
voc_stat
,
lang
=
self
.
config
.
lang
)
except
:
logger
.
info
(
"Initialize TTS server engine Failed."
)
except
BaseException
:
logger
.
error
(
"Initialize TTS server engine Failed."
)
return
False
logger
.
info
(
"Initialize TTS server engine successfully."
)
...
...
@@ -117,10 +117,13 @@ class TTSEngine(BaseEngine):
# transform speed
try
:
# windows not support soxbindings
wav_speed
=
change_speed
(
wav_vol
,
speed
,
target_fs
)
except
:
except
ServerBaseException
:
raise
ServerBaseException
(
ErrorCode
.
SERVER_INTERNAL_ERR
,
"Can not install soxbindings on your system."
)
"Transform speed failed. Can not install soxbindings on your system.
\
You need to set speed value 1.0."
)
except
BaseException
:
logger
.
error
(
"Transform speed failed."
)
# wav to base64
buf
=
io
.
BytesIO
()
...
...
@@ -173,9 +176,11 @@ class TTSEngine(BaseEngine):
try
:
self
.
executor
.
infer
(
text
=
sentence
,
lang
=
lang
,
am
=
self
.
config
.
am
,
spk_id
=
spk_id
)
except
:
except
ServerBaseException
:
raise
ServerBaseException
(
ErrorCode
.
SERVER_INTERNAL_ERR
,
"tts infer failed."
)
except
BaseException
:
logger
.
error
(
"tts infer failed."
)
try
:
target_sample_rate
,
wav_base64
=
self
.
postprocess
(
...
...
@@ -185,8 +190,10 @@ class TTSEngine(BaseEngine):
volume
=
volume
,
speed
=
speed
,
audio_path
=
save_path
)
except
:
except
ServerBaseException
:
raise
ServerBaseException
(
ErrorCode
.
SERVER_INTERNAL_ERR
,
"tts postprocess failed."
)
except
BaseException
:
logger
.
error
(
"tts postprocess failed."
)
return
lang
,
target_sample_rate
,
wav_base64
paddlespeech/server/restful/asr_api.py
浏览文件 @
162361d8
...
...
@@ -14,6 +14,7 @@
import
base64
import
traceback
from
typing
import
Union
from
fastapi
import
APIRouter
from
paddlespeech.server.engine.engine_pool
import
get_engine_pool
...
...
@@ -83,7 +84,7 @@ def asr(request_body: ASRRequest):
except
ServerBaseException
as
e
:
response
=
failed_response
(
e
.
error_code
,
e
.
msg
)
except
:
except
BaseException
:
response
=
failed_response
(
ErrorCode
.
SERVER_UNKOWN_ERR
)
traceback
.
print_exc
()
...
...
paddlespeech/server/restful/request.py
浏览文件 @
162361d8
...
...
@@ -11,7 +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
typing
import
List
from
typing
import
Optional
from
pydantic
import
BaseModel
...
...
paddlespeech/server/restful/response.py
浏览文件 @
162361d8
...
...
@@ -11,9 +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
typing
import
List
from
typing
import
Optional
from
pydantic
import
BaseModel
__all__
=
[
'ASRResponse'
,
'TTSResponse'
]
...
...
paddlespeech/server/restful/tts_api.py
浏览文件 @
162361d8
...
...
@@ -114,7 +114,7 @@ def tts(request_body: TTSRequest):
}
except
ServerBaseException
as
e
:
response
=
failed_response
(
e
.
error_code
,
e
.
msg
)
except
:
except
BaseException
:
response
=
failed_response
(
ErrorCode
.
SERVER_UNKOWN_ERR
)
traceback
.
print_exc
()
...
...
paddlespeech/server/tests/asr/http_client.py
浏览文件 @
162361d8
...
...
@@ -10,11 +10,11 @@
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the
import
requests
import
base64
import
json
import
time
import
base64
import
io
import
requests
def
readwav2base64
(
wav_file
):
...
...
@@ -34,7 +34,7 @@ def main():
url
=
"http://127.0.0.1:8090/paddlespeech/asr"
# start Timestamp
time_start
=
time
.
time
()
time_start
=
time
.
time
()
test_audio_dir
=
"./16_audio.wav"
audio
=
readwav2base64
(
test_audio_dir
)
...
...
@@ -49,8 +49,8 @@ def main():
r
=
requests
.
post
(
url
=
url
,
data
=
json
.
dumps
(
data
))
# ending Timestamp
time_end
=
time
.
time
()
print
(
'time cost'
,
time_end
-
time_start
,
's'
)
time_end
=
time
.
time
()
print
(
'time cost'
,
time_end
-
time_start
,
's'
)
print
(
r
.
json
())
...
...
paddlespeech/server/tests/tts/test_client.py
浏览文件 @
162361d8
...
...
@@ -25,6 +25,7 @@ import soundfile
from
paddlespeech.server.utils.audio_process
import
wav2pcm
# Request and response
def
tts_client
(
args
):
""" Request and response
...
...
@@ -99,5 +100,5 @@ if __name__ == "__main__":
print
(
"Inference time: %f"
%
(
time_consume
))
print
(
"The duration of synthesized audio: %f"
%
(
duration
))
print
(
"The RTF is: %f"
%
(
rtf
))
except
:
except
BaseException
:
print
(
"Failed to synthesized audio."
)
paddlespeech/server/util.py
浏览文件 @
162361d8
...
...
@@ -219,7 +219,7 @@ class ConfigCache:
try
:
cfg
=
yaml
.
load
(
file
,
Loader
=
yaml
.
FullLoader
)
self
.
_data
.
update
(
cfg
)
except
:
except
BaseException
:
self
.
flush
()
@
property
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录