Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
DeepSpeech
提交
395e8d1b
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,发现更多精彩内容 >>
提交
395e8d1b
编写于
3月 10, 2022
作者:
K
KP
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add fbank and mfcc unittest.
上级
e7575ff4
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
135 addition
and
0 deletion
+135
-0
paddleaudio/tests/features/test_kaldi.py
paddleaudio/tests/features/test_kaldi.py
+81
-0
paddleaudio/tests/features/test_librosa.py
paddleaudio/tests/features/test_librosa.py
+54
-0
未找到文件。
paddleaudio/tests/features/test_kaldi.py
0 → 100644
浏览文件 @
395e8d1b
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# 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 specific language governing permissions and
# limitations under the License.
import
unittest
import
numpy
as
np
import
paddle
import
torch
import
torchaudio
import
paddleaudio
from
.base
import
FeatTest
class
TestKaldi
(
FeatTest
):
def
initParmas
(
self
):
self
.
window_size
=
1024
self
.
dtype
=
'float32'
def
test_window
(
self
):
t_hann_window
=
torch
.
hann_window
(
self
.
window_size
,
periodic
=
False
,
dtype
=
eval
(
f
'torch.
{
self
.
dtype
}
'
))
t_hamm_window
=
torch
.
hamming_window
(
self
.
window_size
,
periodic
=
False
,
alpha
=
0.54
,
beta
=
0.46
,
dtype
=
eval
(
f
'torch.
{
self
.
dtype
}
'
))
t_povey_window
=
torch
.
hann_window
(
self
.
window_size
,
periodic
=
False
,
dtype
=
eval
(
f
'torch.
{
self
.
dtype
}
'
)).
pow
(
0.85
)
p_hann_window
=
paddleaudio
.
functional
.
window
.
get_window
(
'hann'
,
self
.
window_size
,
fftbins
=
False
,
dtype
=
eval
(
f
'paddle.
{
self
.
dtype
}
'
))
p_hamm_window
=
paddleaudio
.
functional
.
window
.
get_window
(
'hamming'
,
self
.
window_size
,
fftbins
=
False
,
dtype
=
eval
(
f
'paddle.
{
self
.
dtype
}
'
))
p_povey_window
=
paddleaudio
.
functional
.
window
.
get_window
(
'hann'
,
self
.
window_size
,
fftbins
=
False
,
dtype
=
eval
(
f
'paddle.
{
self
.
dtype
}
'
)).
pow
(
0.85
)
np
.
testing
.
assert_array_almost_equal
(
t_hann_window
,
p_hann_window
)
np
.
testing
.
assert_array_almost_equal
(
t_hamm_window
,
p_hamm_window
)
np
.
testing
.
assert_array_almost_equal
(
t_povey_window
,
p_povey_window
)
def
test_fbank
(
self
):
ta_features
=
torchaudio
.
compliance
.
kaldi
.
fbank
(
torch
.
from_numpy
(
self
.
waveform
.
astype
(
self
.
dtype
)))
pa_features
=
paddleaudio
.
compliance
.
kaldi
.
fbank
(
paddle
.
to_tensor
(
self
.
waveform
.
astype
(
self
.
dtype
)))
np
.
testing
.
assert_array_almost_equal
(
ta_features
,
pa_features
,
decimal
=
4
)
def
test_mfcc
(
self
):
ta_features
=
torchaudio
.
compliance
.
kaldi
.
mfcc
(
torch
.
from_numpy
(
self
.
waveform
.
astype
(
self
.
dtype
)))
pa_features
=
paddleaudio
.
compliance
.
kaldi
.
mfcc
(
paddle
.
to_tensor
(
self
.
waveform
.
astype
(
self
.
dtype
)))
np
.
testing
.
assert_array_almost_equal
(
ta_features
,
pa_features
,
decimal
=
4
)
if
__name__
==
'__main__'
:
unittest
.
main
()
paddleaudio/tests/features/test_librosa.py
浏览文件 @
395e8d1b
...
...
@@ -27,9 +27,11 @@ class TestLibrosa(FeatTest):
self
.
n_fft
=
512
self
.
hop_length
=
128
self
.
n_mels
=
40
self
.
n_mfcc
=
20
self
.
fmin
=
0.0
self
.
window_str
=
'hann'
self
.
pad_mode
=
'reflect'
self
.
top_db
=
80.0
def
test_stft
(
self
):
if
len
(
self
.
waveform
.
shape
)
==
2
:
# (C, T)
...
...
@@ -222,6 +224,58 @@ class TestLibrosa(FeatTest):
np
.
testing
.
assert_array_almost_equal
(
feature_librosa
,
feature_layer
,
decimal
=
4
)
def
test_mfcc
(
self
):
if
len
(
self
.
waveform
.
shape
)
==
2
:
# (C, T)
self
.
waveform
=
self
.
waveform
.
squeeze
(
0
)
# 1D input for librosa.feature.melspectrogram
# librosa:
feature_librosa
=
librosa
.
feature
.
mfcc
(
y
=
self
.
waveform
,
sr
=
self
.
sr
,
S
=
None
,
n_mfcc
=
self
.
n_mfcc
,
dct_type
=
2
,
norm
=
'ortho'
,
lifter
=
0
,
n_fft
=
self
.
n_fft
,
hop_length
=
self
.
hop_length
,
n_mels
=
self
.
n_mels
,
fmin
=
self
.
fmin
)
# paddleaudio.compliance.librosa:
feature_compliance
=
paddleaudio
.
compliance
.
librosa
.
mfcc
(
x
=
self
.
waveform
,
sr
=
self
.
sr
,
n_mfcc
=
self
.
n_mfcc
,
dct_type
=
2
,
norm
=
'ortho'
,
lifter
=
0
,
window_size
=
self
.
n_fft
,
hop_length
=
self
.
hop_length
,
n_mels
=
self
.
n_mels
,
fmin
=
self
.
fmin
,
top_db
=
self
.
top_db
)
# paddleaudio.features.layer
x
=
paddle
.
to_tensor
(
self
.
waveform
,
dtype
=
paddle
.
float64
).
unsqueeze
(
0
)
# Add batch dim.
feature_extractor
=
paddleaudio
.
features
.
MFCC
(
sr
=
self
.
sr
,
n_mfcc
=
self
.
n_mfcc
,
n_fft
=
self
.
n_fft
,
hop_length
=
self
.
hop_length
,
n_mels
=
self
.
n_mels
,
f_min
=
self
.
fmin
,
top_db
=
self
.
top_db
,
dtype
=
x
.
dtype
)
feature_layer
=
feature_extractor
(
x
).
squeeze
(
0
).
numpy
()
np
.
testing
.
assert_array_almost_equal
(
feature_librosa
,
feature_compliance
,
decimal
=
4
)
np
.
testing
.
assert_array_almost_equal
(
feature_librosa
,
feature_layer
,
decimal
=
4
)
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录