Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
DeepSpeech
提交
7ae36b21
D
DeepSpeech
项目概览
PaddlePaddle
/
DeepSpeech
大约 2 年 前同步成功
通知
210
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看板
提交
7ae36b21
编写于
7月 07, 2022
作者:
Y
Yang Zhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add kaldi feature pitch
上级
a16a044f
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
254 addition
and
10 deletion
+254
-10
CMakeLists.txt
CMakeLists.txt
+1
-1
paddlespeech/audio/kaldi/__init__.py
paddlespeech/audio/kaldi/__init__.py
+15
-0
paddlespeech/audio/kaldi/kaldi.py
paddlespeech/audio/kaldi/kaldi.py
+103
-0
paddlespeech/audio/src/pybind/kaldi/kaldi_feature.cc
paddlespeech/audio/src/pybind/kaldi/kaldi_feature.cc
+3
-3
paddlespeech/audio/src/pybind/pybind.cpp
paddlespeech/audio/src/pybind/pybind.cpp
+2
-2
paddlespeech/audio/third_party/kaldi/CMakeLists.txt
paddlespeech/audio/third_party/kaldi/CMakeLists.txt
+2
-1
speechx/speechx/kaldi/feat/feature-plp.h
speechx/speechx/kaldi/feat/feature-plp.h
+1
-1
speechx/speechx/kaldi/feat/online-feature-itf.h
speechx/speechx/kaldi/feat/online-feature-itf.h
+125
-0
speechx/speechx/kaldi/feat/online-feature.h
speechx/speechx/kaldi/feat/online-feature.h
+1
-1
speechx/speechx/kaldi/feat/pitch-functions.h
speechx/speechx/kaldi/feat/pitch-functions.h
+1
-1
未找到文件。
CMakeLists.txt
浏览文件 @
7ae36b21
...
@@ -65,4 +65,4 @@ add_subdirectory(paddlespeech/audio)
...
@@ -65,4 +65,4 @@ add_subdirectory(paddlespeech/audio)
# Summary
# Summary
include
(
cmake/summary.cmake
)
include
(
cmake/summary.cmake
)
onnx_print_configuration_summary
()
onnx_print_configuration_summary
()
\ No newline at end of file
paddlespeech/audio/kaldi/__init__.py
0 → 100644
浏览文件 @
7ae36b21
# 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.
from
.
import
fbank
from
.
import
pitch
paddlespeech/audio/kaldi/kaldi.py
0 → 100644
浏览文件 @
7ae36b21
# 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.
from
paddlespeech.audio._internal
import
module_utils
import
paddlespeech.audio.ops.paddleaudio.ComputeFbank
as
ComputeFbank
import
paddlespeech.audio.ops.paddleaudio.ComputeKaldiPitch
as
ComputeKaldiPitch
__all__
=
[
'fbank'
,
'pitch'
,
]
@
module_utils
.
requires_kaldi
()
def
fbank
(
wav
,
samp_freq
:
int
=
16000
,
frame_shift_ms
:
float
=
10.0
,
frame_length_ms
:
float
=
25.0
,
dither
:
float
=
0.0
,
preemph_coeff
:
float
=
0.97
,
remove_dc_offset
:
bool
=
True
,
window_type
:
str
=
'povey'
,
round_to_power_of_two
:
bool
=
True
,
blackman_coeff
:
float
=
0.42
,
snip_edges
:
bool
=
True
,
allow_downsample
:
bool
=
False
,
allow_upsample
:
bool
=
False
,
max_feature_vectors
:
int
=-
1
,
num_bins
:
int
=
23
,
low_freq
:
float
=
20
,
high_freq
:
float
=
0
,
vtln_low
:
float
=
100
,
vtln_high
:
float
=-
500
,
debug_mel
:
bool
=
False
,
htk_mode
:
bool
=
False
,
use_energy
:
bool
=
False
,
# fbank opts
energy_floor
:
float
=
0.0
,
raw_energy
:
bool
=
True
,
htk_compat
:
bool
=
False
,
use_log_fbank
:
bool
=
True
,
use_power
:
bool
=
True
):
feat
=
ComputeFbank
(
samp_freq
,
frame_shift_ms
,
frame_length_ms
,
dither
,
preemph_coeff
,
remove_dc_offset
,
window_type
,
round_to_power_of_two
,
blackman_coeff
,
snip_edges
,
allow_downsample
,
allow_upsample
,
max_feature_vectors
,
num_bins
,
low_freq
,
high_freq
,
vtln_low
,
vtln_high
,
debug_mel
,
htk_mode
,
use_energy
,
energy_floor
,
raw_energy
,
htk_compat
,
use_log_fbank
,
use_power
,
wav
)
return
feat
@
module_utils
.
requires_kaldi
()
def
pitch
(
wav
,
samp_freq
:
int
=
16000
,
frame_shift_ms
:
float
=
10.0
,
frame_length_ms
:
float
=
25.0
,
preemph_coeff
:
float
=
0.0
,
min_f0
:
int
=
50
,
max_f0
:
int
=
400
,
soft_min_f0
:
float
=
10.0
,
penalty_factor
:
float
=
0.1
,
lowpass_cutoff
:
int
=
1000
,
resample_freq
:
int
=
4000
,
delta_pitch
:
float
=
0.005
,
nccf_ballast
:
int
=
7000
,
lowpass_filter_width
:
int
=
1
,
upsample_filter_width
:
int
=
5
,
max_frames_latency
:
int
=
0
,
frames_per_chunk
:
int
=
0
,
simulate_first_pass_online
:
bool
=
False
,
recompute_frame
:
int
=
500
,
nccf_ballast_online
:
bool
=
False
,
snip_edges
:
bool
=
True
):
pitch
=
ComputeKaldiPitch
(
samp_freq
,
frame_shift_ms
,
frame_length_ms
,
preemph_coeff
,
min_f0
,
max_f0
,
soft_min_f0
,
penalty_factor
,
lowpass_cutoff
,
resample_freq
,
delta_pitch
,
nccf_ballast
,
lowpass_filter_width
,
upsample_filter_width
,
max_frames_latency
,
frames_per_chunk
,
simulate_first_pass_online
,
recompute_frame
,
nccf_ballast_online
,
snip_edges
,
wav
)
return
pitch
\ No newline at end of file
paddlespeech/audio/src/pybind/kaldi/kaldi_feature.cc
浏览文件 @
7ae36b21
...
@@ -191,15 +191,15 @@ opts.preemph_coeff = preemph_coeff;
...
@@ -191,15 +191,15 @@ opts.preemph_coeff = preemph_coeff;
opts
.
snip_edges
=
snip_edges
;
opts
.
snip_edges
=
snip_edges
;
py
::
buffer_info
info
=
wav
.
request
();
py
::
buffer_info
info
=
wav
.
request
();
kaldi
::
Vector
<::
kaldi
::
BaseFloat
>
input_wav
(
info
.
size
);
::
kaldi
::
Vector
<::
kaldi
::
BaseFloat
>
input_wav
(
info
.
size
);
double
*
wav_ptr
=
(
double
*
)
info
.
ptr
;
double
*
wav_ptr
=
(
double
*
)
info
.
ptr
;
for
(
int
idx
=
0
;
idx
<
info
.
size
;
++
idx
)
{
for
(
int
idx
=
0
;
idx
<
info
.
size
;
++
idx
)
{
input_wav
(
idx
)
=
*
wav_ptr
;
input_wav
(
idx
)
=
*
wav_ptr
;
wav_ptr
++
;
wav_ptr
++
;
}
}
kaldi
::
Matrix
<
kaldi
::
BaseFloat
>
features
;
::
kaldi
::
Matrix
<::
kaldi
::
BaseFloat
>
features
;
kaldi
::
ComputeKaldiPitch
(
opts
,
input_wav
,
&
features
);
::
kaldi
::
ComputeKaldiPitch
(
opts
,
input_wav
,
&
features
);
auto
result
=
py
::
array_t
<
double
>
({
features
.
NumRows
(),
features
.
NumCols
()});
auto
result
=
py
::
array_t
<
double
>
({
features
.
NumRows
(),
features
.
NumCols
()});
for
(
int
row_idx
=
0
;
row_idx
<
features
.
NumRows
();
++
row_idx
)
{
for
(
int
row_idx
=
0
;
row_idx
<
features
.
NumRows
();
++
row_idx
)
{
for
(
int
col_idx
=
0
;
col_idx
<
features
.
NumCols
();
++
col_idx
)
{
for
(
int
col_idx
=
0
;
col_idx
<
features
.
NumCols
();
++
col_idx
)
{
...
...
paddlespeech/audio/src/pybind/pybind.cpp
浏览文件 @
7ae36b21
...
@@ -4,15 +4,15 @@
...
@@ -4,15 +4,15 @@
#include "paddlespeech/audio/src/pybind/kaldi/kaldi_feature.h"
#include "paddlespeech/audio/src/pybind/kaldi/kaldi_feature.h"
#include "paddlespeech/audio/src/pybind/sox/io.h"
#include "paddlespeech/audio/src/pybind/sox/io.h"
// Sox
PYBIND11_MODULE
(
_paddleaudio
,
m
)
{
PYBIND11_MODULE
(
_paddleaudio
,
m
)
{
// Sox
m
.
def
(
"get_info_file"
,
m
.
def
(
"get_info_file"
,
&
paddleaudio
::
sox_io
::
get_info_file
,
&
paddleaudio
::
sox_io
::
get_info_file
,
"Get metadata of audio file."
);
"Get metadata of audio file."
);
m
.
def
(
"get_info_fileobj"
,
m
.
def
(
"get_info_fileobj"
,
&
paddleaudio
::
sox_io
::
get_info_fileobj
,
&
paddleaudio
::
sox_io
::
get_info_fileobj
,
"Get metadata of audio in file object."
);
"Get metadata of audio in file object."
);
// kaldi feat
m
.
def
(
"InitFbank"
,
&
paddleaudio
::
kaldi
::
InitFbank
,
"init fbank"
);
m
.
def
(
"InitFbank"
,
&
paddleaudio
::
kaldi
::
InitFbank
,
"init fbank"
);
m
.
def
(
"ResetFbank"
,
&
paddleaudio
::
kaldi
::
ResetFbank
,
"reset fbank"
);
m
.
def
(
"ResetFbank"
,
&
paddleaudio
::
kaldi
::
ResetFbank
,
"reset fbank"
);
m
.
def
(
"ComputeFbank"
,
&
paddleaudio
::
kaldi
::
ComputeFbank
,
"compute fbank"
);
m
.
def
(
"ComputeFbank"
,
&
paddleaudio
::
kaldi
::
ComputeFbank
,
"compute fbank"
);
...
...
paddlespeech/audio/third_party/kaldi/CMakeLists.txt
浏览文件 @
7ae36b21
...
@@ -70,6 +70,7 @@ add_library(kaldi-feat-common STATIC
...
@@ -70,6 +70,7 @@ add_library(kaldi-feat-common STATIC
feat/feature-functions.cc
feat/feature-functions.cc
feat/feature-window.cc
feat/feature-window.cc
feat/resample.cc
feat/resample.cc
feat/pitch-functions.cc
feat/mel-computations.cc
feat/mel-computations.cc
feat/cmvn.cc
feat/cmvn.cc
)
)
...
@@ -113,4 +114,4 @@ target_link_libraries(libkaldi INTERFACE
...
@@ -113,4 +114,4 @@ target_link_libraries(libkaldi INTERFACE
gfortran
gfortran
-Wl,--no-whole-archive -Wl,--end-group
-Wl,--no-whole-archive -Wl,--end-group
)
)
target_compile_definitions
(
libkaldi INTERFACE
"-DCOMPILE_WITHOUT_OPENFST"
)
target_compile_definitions
(
libkaldi INTERFACE
"-DCOMPILE_WITHOUT_OPENFST"
)
\ No newline at end of file
speechx/speechx/kaldi/feat/feature-plp.h
浏览文件 @
7ae36b21
...
@@ -27,7 +27,7 @@
...
@@ -27,7 +27,7 @@
#include "feat/feature-functions.h"
#include "feat/feature-functions.h"
#include "feat/feature-window.h"
#include "feat/feature-window.h"
#include "feat/mel-computations.h"
#include "feat/mel-computations.h"
#include "
itf
/options-itf.h"
#include "
util
/options-itf.h"
namespace
kaldi
{
namespace
kaldi
{
/// @addtogroup feat FeatureExtraction
/// @addtogroup feat FeatureExtraction
...
...
speechx/speechx/kaldi/feat/online-feature-itf.h
0 → 100644
浏览文件 @
7ae36b21
// itf/online-feature-itf.h
// Copyright 2013 Johns Hopkins University (author: Daniel Povey)
// See ../../COPYING for clarification regarding multiple authors
//
// 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
//
// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
// WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
// MERCHANTABLITY OR NON-INFRINGEMENT.
// See the Apache 2 License for the specific language governing permissions and
// limitations under the License.
#ifndef KALDI_ITF_ONLINE_FEATURE_ITF_H_
#define KALDI_ITF_ONLINE_FEATURE_ITF_H_ 1
#include "base/kaldi-common.h"
#include "matrix/matrix-lib.h"
namespace
kaldi
{
/// @ingroup Interfaces
/// @{
/**
OnlineFeatureInterface is an interface for online feature processing (it is
also usable in the offline setting, but currently we're not using it for
that). This is for use in the online2/ directory, and it supersedes the
interface in ../online/online-feat-input.h. We have a slightly different
model that puts more control in the hands of the calling thread, and won't
involve waiting on semaphores in the decoding thread.
This interface only specifies how the object *outputs* the features.
How it obtains the features, e.g. from a previous object or objects of type
OnlineFeatureInterface, is not specified in the interface and you will
likely define new constructors or methods in the derived type to do that.
You should appreciate that this interface is designed to allow random
access to features, as long as they are ready. That is, the user
can call GetFrame for any frame less than NumFramesReady(), and when
implementing a child class you must not make assumptions about the
order in which the user makes these calls.
*/
class
OnlineFeatureInterface
{
public:
virtual
int32
Dim
()
const
=
0
;
/// returns the feature dimension.
/// Returns the total number of frames, since the start of the utterance, that
/// are now available. In an online-decoding context, this will likely
/// increase with time as more data becomes available.
virtual
int32
NumFramesReady
()
const
=
0
;
/// Returns true if this is the last frame. Frame indices are zero-based, so the
/// first frame is zero. IsLastFrame(-1) will return false, unless the file
/// is empty (which is a case that I'm not sure all the code will handle, so
/// be careful). This function may return false for some frame if
/// we haven't yet decided to terminate decoding, but later true if we decide
/// to terminate decoding. This function exists mainly to correctly handle
/// end effects in feature extraction, and is not a mechanism to determine how
/// many frames are in the decodable object (as it used to be, and for backward
/// compatibility, still is, in the Decodable interface).
virtual
bool
IsLastFrame
(
int32
frame
)
const
=
0
;
/// Gets the feature vector for this frame. Before calling this for a given
/// frame, it is assumed that you called NumFramesReady() and it returned a
/// number greater than "frame". Otherwise this call will likely crash with
/// an assert failure. This function is not declared const, in case there is
/// some kind of caching going on, but most of the time it shouldn't modify
/// the class.
virtual
void
GetFrame
(
int32
frame
,
VectorBase
<
BaseFloat
>
*
feat
)
=
0
;
/// This is like GetFrame() but for a collection of frames. There is a
/// default implementation that just gets the frames one by one, but it
/// may be overridden for efficiency by child classes (since sometimes
/// it's more efficient to do things in a batch).
virtual
void
GetFrames
(
const
std
::
vector
<
int32
>
&
frames
,
MatrixBase
<
BaseFloat
>
*
feats
)
{
KALDI_ASSERT
(
static_cast
<
int32
>
(
frames
.
size
())
==
feats
->
NumRows
());
for
(
size_t
i
=
0
;
i
<
frames
.
size
();
i
++
)
{
SubVector
<
BaseFloat
>
feat
(
*
feats
,
i
);
GetFrame
(
frames
[
i
],
&
feat
);
}
}
// Returns frame shift in seconds. Helps to estimate duration from frame
// counts.
virtual
BaseFloat
FrameShiftInSeconds
()
const
=
0
;
/// Virtual destructor. Note: constructors that take another member of
/// type OnlineFeatureInterface are not expected to take ownership of
/// that pointer; the caller needs to keep track of that manually.
virtual
~
OnlineFeatureInterface
()
{
}
};
/// Add a virtual class for "source" features such as MFCC or PLP or pitch
/// features.
class
OnlineBaseFeature
:
public
OnlineFeatureInterface
{
public:
/// This would be called from the application, when you get more wave data.
/// Note: the sampling_rate is typically only provided so the code can assert
/// that it matches the sampling rate expected in the options.
virtual
void
AcceptWaveform
(
BaseFloat
sampling_rate
,
const
VectorBase
<
BaseFloat
>
&
waveform
)
=
0
;
/// InputFinished() tells the class you won't be providing any
/// more waveform. This will help flush out the last few frames
/// of delta or LDA features (it will typically affect the return value
/// of IsLastFrame.
virtual
void
InputFinished
()
=
0
;
};
/// @}
}
// namespace Kaldi
#endif // KALDI_ITF_ONLINE_FEATURE_ITF_H_
speechx/speechx/kaldi/feat/online-feature.h
浏览文件 @
7ae36b21
...
@@ -34,7 +34,7 @@
...
@@ -34,7 +34,7 @@
#include "feat/feature-mfcc.h"
#include "feat/feature-mfcc.h"
#include "feat/feature-plp.h"
#include "feat/feature-plp.h"
#include "feat/feature-fbank.h"
#include "feat/feature-fbank.h"
#include "
itf
/online-feature-itf.h"
#include "
feat
/online-feature-itf.h"
namespace
kaldi
{
namespace
kaldi
{
/// @addtogroup onlinefeat OnlineFeatureExtraction
/// @addtogroup onlinefeat OnlineFeatureExtraction
...
...
speechx/speechx/kaldi/feat/pitch-functions.h
浏览文件 @
7ae36b21
...
@@ -31,7 +31,7 @@
...
@@ -31,7 +31,7 @@
#include "base/kaldi-error.h"
#include "base/kaldi-error.h"
#include "feat/mel-computations.h"
#include "feat/mel-computations.h"
#include "
itf
/online-feature-itf.h"
#include "
feat
/online-feature-itf.h"
#include "matrix/matrix-lib.h"
#include "matrix/matrix-lib.h"
#include "util/common-utils.h"
#include "util/common-utils.h"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录