Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bfabe06

Browse filesBrowse files
authored
Merge pull request jameslyons#24 from ybdarrenwang/master
Added delta feature calculation function; also updated test example
2 parents b7223d8 + 726cb75 commit bfabe06
Copy full SHA for bfabe06

2 files changed

+17-1Lines changed: 17 additions & 1 deletion

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎example.py‎

Copy file name to clipboard
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#!/usr/bin/env python
22

33
from python_speech_features import mfcc
4+
from python_speech_features import delta
45
from python_speech_features import logfbank
56
import scipy.io.wavfile as wav
67

78
(rate,sig) = wav.read("english.wav")
89
mfcc_feat = mfcc(sig,rate)
10+
d_mfcc_feat = delta(mfcc_feat, 2)
911
fbank_feat = logfbank(sig,rate)
1012

1113
print(fbank_feat[1:3,:])
Collapse file

‎python_speech_features/base.py‎

Copy file name to clipboardExpand all lines: python_speech_features/base.py
+15-1Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,18 @@ def lifter(cepstra, L=22):
171171
else:
172172
# values of L <= 0, do nothing
173173
return cepstra
174-
174+
175+
def delta(feat, N):
176+
"""Compute delta features from a feature vector sequence.
177+
178+
:param feat: A numpy array of size (NUMFRAMES by number of features) containing features. Each row holds 1 feature vector.
179+
:param N: For each frame, calculate delta features based on preceding and following N frames
180+
:returns: A numpy array of size (NUMFRAMES by number of features) containing delta features. Each row holds 1 delta feature vector.
181+
"""
182+
NUMFRAMES = len(feat)
183+
feat = numpy.concatenate(([feat[0] for i in range(N)], feat, [feat[-1] for i in range(N)]))
184+
denom = sum([2*i*i for i in range(1,N+1)])
185+
dfeat = []
186+
for j in range(NUMFRAMES):
187+
dfeat.append(numpy.sum([n*feat[N+j+n] for n in range(-1*N,N+1)], axis=0)/denom)
188+
return dfeat

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.