Skip to content

Commit

Permalink
add shifted delta coef feature
Browse files Browse the repository at this point in the history
  • Loading branch information
matiaslindgren committed Sep 6, 2019
1 parent 217db70 commit 51059ee
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions speechbox/preprocess/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,23 @@ def mfcc_deltas_012(utterance, **kwargs):
features[2::3] = librosa.feature.delta(mfccs, order=2, width=5)
return features.T

def sdc(frames, d, P, k, **kwargs):
"""
Shifted-delta coefficients from
Torres-Carrasquillo, P. A. el al. (2002).
https://www.isca-speech.org/archive/icslp_2002/i02_0089.html
N is assumed to be frames.shape[1].
"""
assert d > 0 and P > 0 and k > 0, "invalid sdc parameters d = {}, P = {}, k = {}".format(d, P, k)
assert frames.ndim > 1, "invalid dimensions for feature frames: {}".format(frames.ndim)
num_frames = frames.shape[0]
frames = np.pad(frames, pad_width=((0, d + k*P), (0, 0)), mode='constant', constant_values=0)
#TODO without loop expression
return np.concatenate([frames[i+2*d::P][:k] - frames[i::P][:k] for i in range(num_frames)])

all_extractors = collections.OrderedDict([
("mfcc", mfcc),
("mfcc-deltas-012", mfcc_deltas_012),
("sdc", sdc),
])

0 comments on commit 51059ee

Please sign in to comment.