Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extracting 12 Mel-frequency cepstral coefficients #21

Closed
calebstrait opened this issue Oct 28, 2019 · 7 comments
Closed

Extracting 12 Mel-frequency cepstral coefficients #21

calebstrait opened this issue Oct 28, 2019 · 7 comments

Comments

@calebstrait
Copy link

Hi Yannick, I was hoping you might be willing to help me get past just one more issue:

I'm trying to extract 12 Mel-frequency cepstral coefficients (MFCCs) from a .wav file, and when I do the following:

sound = parselmouth.Sound(path)
mfcc_object = sound.to_mfcc(number_of_coefficients=12)
mfccs = mfcc_object.extract_features()
mfcc_arr = mfccs.as_array()
print(mfcc_arr.shape)

...the result on 3 different .wavs are

(4, 21)
(4, 2439)
(4, 114)

I'm expecting the resulting arrays to be 12 by (something), not 4 by (something). Where am I going wrong?

@YannickJadoul
Copy link
Owner

Hi @calebstrait. I thought I'd answered this as reply to the private email you had sent, but maybe something went wrong, there?

Anyway, I'll quote that reply here:

Your current problem is that Praat is annoyingly confusing, I think. The mfcc variable has type parselmouth.MFCC and already contains the MFCC coefficients. Calling extract_features() is doing some weird hidden action in Praat "To Matrix (features)..." (that used to be called "Extract features", I think?).
Anyhow, the comments in Praat's code say:

/* 1: cepstral difference function (d)
 * 2: spectral stability (dstab)
 * 3: spectral center of gravity (gs)
 * 4: stable internal duration
 */

So this is probably not what you want. Rather, you want to call mfcc.to_array() to get a numpy array containing the actual MFCCs. This should give a 13 by N matrix, (as the first feature contains the C0 value, related to the energy, and is not contained in the number_of_coefficients=12 argument, according to Praat).

Sorry that this is so confusing. Creating Parselmouth is always a thin line between trying to be clear from a Python point-of-view and trying to stay close to Praat :-/

By the way, there's also the Gitter chatroom for quick questions and answers, for things that are not per se an issue/bug.

@calebstrait
Copy link
Author

Yes, thanks so much!! And apologies for missing your email response- looks like I need to update my spam rules.

@YannickJadoul
Copy link
Owner

No problem! Good luck with the rest of your project :)

@pranaswi23
Copy link

can u please give me the correct code of mfcc feature extraction because i am unable to understand your explanation.
Thanks in advance!!

@YannickJadoul
Copy link
Owner

can u please give me the correct code of mfcc feature extraction because i am unable to understand your explanation.
Thanks in advance!!

Asked (and answered) on Gitter: https://gitter.im/PraatParselmouth/Lobby?at=5efe111fc223cc536a4cf2a2

@pranaswi23
Copy link

Thanks for giving me the link of doccumentation but there is no explanation what the function is doing there.For example "to_mfcc" is there .Like it is taking no_of_coefficients as attribute but what is it doing ,no where mentioned.I am new to parselmouth and python.Please say how to know definition of a function in doccumentation.
I got wrong answer.Please tell me how to resolve .

from glob2 import glob
import librosa
import parselmouth

data_dir='D:\extraction'#folder path containing the .mp3 files
audio_file=glob(data_dir +'/*.mp3')
print(len(audio_file))
print(audio_file)

sound = parselmouth.Sound(audio_file[0])
print("sound",sound)
mfcc_object = sound.to_mfcc(number_of_coefficients = 12)
print("mfcc_object",mfcc_object)
mfccs = mfcc_object.extract_features(window_length=0.025)
print("mfccs",mfccs)
mfcc_arr=mfccs.as_array()
print("mfcc_arr",mfcc_arr)
print("mfcc_shape",mfcc_arr.shape)

i didn't understand your previous explanation how to get exact (12 mfcc coefficients) output.please explain.

@YannickJadoul
Copy link
Owner

@pranaswi23 That's what I answered above in this issue:

Calling extract_features() is doing some weird hidden action in Praat "To Matrix (features)..." (that used to be called "Extract features", I think?).

So this is probably not what you want. Rather, you want to call mfcc.to_array() to get a numpy array containing the actual MFCCs. This should give a 13 by N matrix, (as the first feature contains the C0 value, related to the energy, and is not contained in the number_of_coefficients=12 argument, according to Praat).

So extract_features is extracting different features, and you don't want to use that. Use to_array on the MFCC object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants