#https://appliedmachinelearning.blog/2017/11/14/spoken-speaker-identification-based-on-gaussian-mixture-models-python-implementation/
import numpy as np
from sklearn import preprocessing
import python_speech_features as mfcc
import python_speech_features

def calculate_delta(array):
    return python_speech_features.base.delta(array,2)

def extract_features(audio,rate):
    """extract 20 dim mfcc features from an audio, performs CMS and combines
    delta to make it 40 dim feature vector"""

    mfcc_feat = mfcc.mfcc(audio,rate, 0.025, 0.01, 20, appendEnergy = True) #winlen=0.025, #winstep=0.01 #number of cepstrum to return=20
    mfcc_feat = preprocessing.scale(mfcc_feat)
    delta = calculate_delta(mfcc_feat) #compute delta feature from a feature vector sequence
    combined = np.hstack((mfcc_feat,delta))
    return combined
