Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
aee3e11f
M
models
项目概览
PaddlePaddle
/
models
1 年多 前同步成功
通知
222
Star
6828
Fork
2962
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
602
列表
看板
标记
里程碑
合并请求
255
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
602
Issue
602
列表
看板
标记
里程碑
合并请求
255
合并请求
255
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
aee3e11f
编写于
8月 03, 2017
作者:
X
Xinghai Sun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add warming-up to demo_server.py for DS2 and clean codes.
上级
ae84c6f6
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
35 addition
and
7 deletion
+35
-7
deep_speech_2/data_utils/audio.py
deep_speech_2/data_utils/audio.py
+0
-2
deep_speech_2/demo_server.py
deep_speech_2/demo_server.py
+35
-5
未找到文件。
deep_speech_2/data_utils/audio.py
浏览文件 @
aee3e11f
...
...
@@ -64,8 +64,6 @@ class AudioSegment(object):
:rtype: AudioSegment
"""
samples
,
sample_rate
=
soundfile
.
read
(
file
,
dtype
=
'float32'
)
print
(
samples
)
print
(
sample_rate
)
return
cls
(
samples
,
sample_rate
)
@
classmethod
...
...
deep_speech_2/demo_server.py
浏览文件 @
aee3e11f
import
os
import
time
import
random
import
argparse
import
distutils.util
from
time
import
gmtime
,
strftime
...
...
@@ -8,9 +9,10 @@ import struct
import
wave
import
pyaudio
import
paddle.v2
as
paddle
from
utils
import
print_arguments
from
data_utils.data
import
DataGenerator
from
model
import
DeepSpeech2Model
import
utils
from
data_utils.utils
import
read_manifest
parser
=
argparse
.
ArgumentParser
(
description
=
__doc__
)
parser
.
add_argument
(
...
...
@@ -38,6 +40,11 @@ parser.add_argument(
default
=
'mean_std.npz'
,
type
=
str
,
help
=
"Manifest path for normalizer. (default: %(default)s)"
)
parser
.
add_argument
(
"--warmup_manifest_path"
,
default
=
'datasets/manifest.test'
,
type
=
str
,
help
=
"Manifest path for warmup test. (default: %(default)s)"
)
parser
.
add_argument
(
"--specgram_type"
,
default
=
'linear'
,
...
...
@@ -77,7 +84,7 @@ parser.add_argument(
"(default: %(default)s)"
)
parser
.
add_argument
(
"--beam_size"
,
default
=
5
00
,
default
=
1
00
,
type
=
int
,
help
=
"Width for beam search decoding. (default: %(default)d)"
)
parser
.
add_argument
(
...
...
@@ -134,7 +141,6 @@ class AsrRequestHandler(SocketServer.BaseRequestHandler):
print
(
"Received utterance[length=%d] from %s, saved to %s."
%
(
len
(
data
),
self
.
client_address
[
0
],
filename
))
#filename = "/home/work/.cache/paddle/dataset/speech/Libri/train-other-500/LibriSpeech/train-other-500/811/130143/811-130143-0025.flac"
start_time
=
time
.
time
()
transcript
=
self
.
server
.
audio_process_handler
(
filename
)
finish_time
=
time
.
time
()
...
...
@@ -149,7 +155,7 @@ class AsrRequestHandler(SocketServer.BaseRequestHandler):
timestamp
=
strftime
(
"%Y%m%d%H%M%S"
,
gmtime
())
out_filename
=
os
.
path
.
join
(
self
.
server
.
speech_save_dir
,
timestamp
+
"_"
+
self
.
client_address
[
0
]
+
"
_"
+
"
.wav"
)
timestamp
+
"_"
+
self
.
client_address
[
0
]
+
".wav"
)
# write to wav file
file
=
wave
.
open
(
out_filename
,
'wb'
)
file
.
setnchannels
(
1
)
...
...
@@ -160,6 +166,22 @@ class AsrRequestHandler(SocketServer.BaseRequestHandler):
return
out_filename
def
warm_up_test
(
audio_process_handler
,
manifest_path
,
num_test_cases
,
random_seed
=
0
):
manifest
=
read_manifest
(
manifest_path
)
rng
=
random
.
Random
(
random_seed
)
samples
=
rng
.
sample
(
manifest
,
num_test_cases
)
for
idx
,
sample
in
enumerate
(
samples
):
print
(
"Warm-up Test Case %d: %s"
,
idx
,
sample
[
'audio_filepath'
])
start_time
=
time
.
time
()
transcript
=
audio_process_handler
(
sample
[
'audio_filepath'
])
finish_time
=
time
.
time
()
print
(
"Response Time: %f, Transcript: %s"
%
(
finish_time
-
start_time
,
transcript
))
def
start_server
():
data_generator
=
DataGenerator
(
vocab_filepath
=
args
.
vocab_filepath
,
...
...
@@ -188,6 +210,14 @@ def start_server():
num_processes
=
1
)
return
result_transcript
[
0
]
print
(
'-----------------------------------------------------------'
)
print
(
'Warming up ...'
)
warm_up_test
(
audio_process_handler
=
file_to_transcript
,
manifest_path
=
args
.
warmup_manifest_path
,
num_test_cases
=
3
)
print
(
'-----------------------------------------------------------'
)
server
=
AsrTCPServer
(
server_address
=
(
args
.
host_ip
,
args
.
host_port
),
RequestHandlerClass
=
AsrRequestHandler
,
...
...
@@ -199,7 +229,7 @@ def start_server():
def
main
():
utils
.
print_arguments
(
args
)
print_arguments
(
args
)
paddle
.
init
(
use_gpu
=
args
.
use_gpu
,
trainer_count
=
1
)
start_server
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录