本文整理汇总了Python中scikits.talkbox.features.mfcc函数的典型用法代码示例。如果您正苦于以下问题:Python mfcc函数的具体用法?Python mfcc怎么用?Python mfcc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mfcc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_validation_set
def load_validation_set():
"""
Output
a tuple of features: (fft features, mfcc features, mean-std features)
Description
extracts three types of features from validation set.
"""
ffts = dict()
mfccs = dict()
mean_stds = dict()
for i in validation_ids:
path = './validation/validation.{i}.wav'.format(i=i)
_, X = read_wav(path)
# FFT
fft = np.array(abs(sp.fft(X)[:1000]))
ffts.update({i: fft})
# MFCC
ceps, mspec, spec = mfcc(X)
num_ceps = len(ceps)
x = np.mean(ceps[int(num_ceps*1/10):int(num_ceps*9/10)], axis=0)
mfccs.update({i: x})
# Mean-Std
[Fs, x] = audioBasicIO.readAudioFile(path);
F = audioFeatureExtraction.stFeatureExtraction(x, Fs, 0.050*Fs, 0.025*Fs);
mean_std = []
for f in F:
mean_std.extend([f.mean(), f.std()])
mean_stds.update({i: np.array(mean_std)})
return (ffts, mfccs, mean_stds)
示例2: BED_extract
def BED_extract(path, nfft=784):
list_data = numpy.array([])
list_label = numpy.array([])
#W:anger:0 N:neutral:1 F:happiness:2 T:sadness:3
dic = {'W':0,'L':1,'E':3,'A':0,'F':2,'T':3,'N':1}
for root, dir, files in os.walk(path):
rootpath = os.path.join(os.path.abspath(path), root)
for file in files:
if os.path.splitext(file)[1].lower()=='.wav':
filepath = os.path.join(rootpath, file)
SR, X = wavfile.read(filepath)
_, _, spec = mfcc(X, fs=SR, nfft=(nfft*2))
print(filepath)
list_data = numpy.append(list_data, numpy.mean(spec, axis=0)[:nfft]/numpy.max(spec))
list_label = numpy.append(list_label, int(dic[file[5]]))
list_data = numpy.reshape(list_data, (len(list_data)/nfft, nfft))
return list_data, list_label
示例3: apply
def apply(self, data):
all_ceps = []
for ch in data:
ceps, mspec, spec = mfcc(ch)
all_ceps.append(ceps.ravel())
return np.array(all_ceps)
示例4: getmfccdata
def getmfccdata(path):
"""
This function extracts the mfcc data from the wav files
Parameters:
-----------
path - path to get the directory name of the songs present "E:\UNM\CS 529 - Intro to Machine Learning\Assignment 3\opihi.cs.uvic.ca\sound\genres"
Returns:
--------
mfccdata - mfcc data matrix of size (600,13)
"""
classesmatrix = np.zeros((no_of_docs, 1)) # Stores the song, genre information in classesmatrix.txt file -> Line number as song index, genre
mfccdata = np.zeros((no_of_docs, no_of_mfcc_features)) # Matrix (600,13) to store the fft features information of all the songs in 6 genres
fileindex = 0 # to store the current offset of the song
for subdir, dirs, files in os.walk(path): # Traversing all the files in 6 genres
if os.path.basename(subdir) in genres.keys():
for f in files:
if f.endswith('.wav'):
print "Processing file : " + f
sample_rate, X = scipy.io.wavfile.read(os.path.join(subdir, f))
ceps, mspec, spec = mfcc(X)
num_ceps = ceps.shape[0]
mfcc_features = np.mean(ceps[int(num_ceps * 1 / 10):int(num_ceps * 9 / 10)], axis=0) # Extracts 13 features.
for i in range(len(mfcc_features)):
mfccdata[fileindex][i] = mfcc_features[i]
classesmatrix[fileindex] = genres[os.path.basename(subdir)] # Storing the genre of every song in a matrix.
fileindex += 1
np.savetxt('classesmatrix.txt', classesmatrix, '%d') # Writing the classesmatrix to a file.
return mfccdata
示例5: BED_extract
def BED_extract(path, nfft):
list_data = numpy.array([])
list_label = numpy.array([])
"""
dic = {'W':[1,0],'L':[0,1],'E':[0,1],'A':[0,1],'F':[1,0],'T':[0,1],'N':[0.5,0.5]}
"""
dic = {'W':[0,1],'L':[0,1],'E':[0,1],'A':[0,1],'F':[1,0],'T':[0,1],'N':[0.5,0.5]}
for root, dir, files in os.walk(path):
rootpath = os.path.join(os.path.abspath(path), root)
for file in files:
if os.path.splitext(file)[1].lower()=='.wav':
filepath = os.path.join(rootpath, file)
SR, X = wavfile.read(filepath)
_, _, spec = mfcc(X, fs=SR, nfft=(nfft*2))
list_data = numpy.append(list_data, numpy.mean(spec, axis=0)[:nfft]/numpy.max(spec))
list_label = numpy.append(list_label, dic[file[5]])
list_data = numpy.reshape(list_data, (len(list_data)/nfft, nfft))
list_label = numpy.reshape(list_label, (len(list_label)/label_length, label_length))
return list_data, list_label
示例6: sparkFeatureExt
def sparkFeatureExt(line):
print line
string1= file
cut=string1[72:]
cut=cut[:-10]
intClass=ClassToInt(cut)
(samplerate, wavedata) = wavfile.read(file)
(s1,n1)= spectral_centroid(wavedata,512,samplerate)
(sr1,nr1)= spectral_rolloff(wavedata,512,samplerate)
(sf1,nf1)= spectral_flux(wavedata,512,samplerate)
(rms,ts) = root_mean_square(wavedata, 512, samplerate);
rms= rms[~np.isnan(rms)] #rms array contains NAN values and we have to remove these values
(zcr,ts1) = zero_crossing_rate(wavedata, 512, samplerate);
(MFCCs, mspec, spec) = mfcc(wavedata)
MFCC_coef=list()
ran=MFCCs.shape
ran1=ran[0]
for ind1 in range(13):
sum=0
summ=0
for ind in range(ran1):
sum+=MFCCs[ind,ind1]
MFCC_coef.append(sum/ran1)
eng= stEnergy(wavedata)
#Win = 0.050
#Step = 0.050
#eps = 0.00000001
return s1,sr1,sf1,rms,zcr,eng,MFCC_coef,intClass
示例7: create_ceps
def create_ceps(fn):
#print(">>>: [%s]" % fn)
sample_rate, X = scipy.io.wavfile.read(fn)
#print("> - [%d]" % sample_rate)
ceps, mspec, spec = mfcc(X,nceps=13)
write_ceps(ceps, fn)
示例8: apply
def apply(self, data, meta=None):
all_ceps = []
for ch in data:
ceps, mspec, spec = mfcc(ch)
all_ceps.append(ceps.ravel())
return to_np_array(all_ceps)
示例9: mfccIFY
def mfccIFY(dict_read):
dict = {}
for each in dict_read.keys():
[sample_rate,X] = dict_read.get(each)
ceps, mspec, spec = mfcc(X)
dict[each] = ceps
return dict
示例10: compute_features
def compute_features(source, features):
"""
compute features for all the tracks
"""
for label in source.keys():
for i in range(0,100):
base_path = os.path.join(FT_DIR, "%s_%d" % (label, i))
ft = []
if 'zcr' in features:
zcr, ts = zero_crossing_rate(source[label][i]['wavedata'], 512, source[label][i]['sample_rate'])
ft.append(zcr)
if 'rms' in features:
rms, ts = root_mean_square(source[label][i]['wavedata'], 512, source[label][i]['sample_rate'])
ft.append(rms)
if 'sc' in features:
sc, ts = spectual_centroid(source[label][i]['wavedata'], 2048, source[label][i]['sample_rate'])
ft.append(sc)
if 'sr' in features:
sr, ts = spectral_rolloff(source[label][i]['wavedata'], 2048, source[label][i]['sample_rate'])
ft.append(sr)
if 'sf' in features:
sf, ts = spectral_flux(source[label][i]['wavedata'], 2048, source[label][i]['sample_rate'])
ft.append(sf)
if 'mfcc' in features:
ceps, mspec, spec = mfcc(source[label][i]['wavedata'])
ft.append(ceps)
write_features(ft, base_path)
示例11: convert
def convert(path):
data = {}
data["sample_rate"], X = scipy.io.wavfile.read(path)
data["ceps"], data["mspec"], data["spec"] = mfcc(X) #save everything it gives us in case it's useful lmao
cep_count = len(data["ceps"])
input_vector = np.array([np.mean(data["ceps"][int(cep_count / 10):int(cep_count * 9 / 10)], axis=0)])
return input_vector
示例12: create_ceps
def create_ceps(fn):
"""
Creates the MFCC features.
"""
sample_rate, X = scipy.io.wavfile.read(fn)
X[X==0]=1
ceps, mspec, spec = mfcc(X)
write_ceps(ceps, fn)
示例13: mfcc_sound_features
def mfcc_sound_features(self):
ceps, mspec, spec = mfcc(self.audio)
num_ceps = len(ceps)
#v = np.mean(ceps[int(num_ceps / 10):int(num_ceps * 9 / 10)], axis=0)
v = np.mean(ceps, axis=0)
return v
示例14: create_ceps
def create_ceps(wavfile):
sampling_rate, song_array = scipy.io.wavfile.read(wavfile)
"""Get MFCC
ceps : ndarray of MFCC
mspec : ndarray of log-spectrum in the mel-domain
spec : spectrum magnitude
"""
ceps, mspec, spec = mfcc(song_array)
write_ceps(ceps, wavfile)
示例15: show
def show(self, example):
sound = audiolab.sndfile(self.base + example.file)
frames = sound.read_frames(sound.get_nframes()) * 0.8
mfcc = features.mfcc(frames[example.start: example.stop:2], fs=41000)
print mfcc[0].shape
fig = plt.figure()
fig.set_size_inches(20, 20)
ax = fig.add_subplot(111)
ax.imshow(mfcc[0].transpose()[:, :100])