示例#1
0
def extract(mp3file,npyfile=''):
    """
    Get an mp3 file, reads it, extract fingerprints features,
    saves it to a given npyfile (if different than '')
    RETURN numpy array for debugging purposes
    """
    # read mp3 through MATLAB mp3 file
    x,fs,tmp = audioio.audioread(mp3file)
    x = np.average(x,axis=1)
    assert x.shape[0] > 2,'bad signal averaging'
    # get the fingerprint features
    L,S,T,maxes = LANDMARKS.find_landmarks(x,fs)
    # create the maxes matrix
    maxes = maxes - 1 # matlab starts at 0
    nfreq = 256
    assert np.max(maxes[1,:]) < nfreq,'max freq too high'
    nsamp = int(np.max(maxes[0,:]) + 1)
    data = np.zeros([nfreq,nsamp])
    # fill in data
    for m in range(maxes.shape[1]):
        data[maxes[1,m],maxes[0,m]] += 1
    # save to npy
    if npyfile != '':
        np.save(npyfile,data)
    # return data for debugging or ipython usage
    return data
def maxes_beattimes_segs_from_audiofile(wavfile):
    """
    Utility function
    From a given eavfile:
    - computes the fingerprint maxes
    - gets the corresponding en beat times
    - gets the corresponding annotated segments
    RETURN:
    signal, sampling rate, maxes, beatstarts, duration, segstarts, labels
    """
    # fingerprint it
    wav = LANDMARKS.AUDIOLAB.wavread(wavfile)
    L,S,T,maxes = LANDMARKS.find_landmarks(wav[0],wav[1])
    # find the EN matfile
    relwavfile = os.path.relpath(wavfile,start=_audio_dir)
    enmatfile = os.path.join(_enfeats_dir,relwavfile+'.mat')
    assert os.path.exists(enmatfile),'can not find matfile %s' % enmatfile
    mat = sio.loadmat(enmatfile)
    btstart = mat['btstart']
    try:
        duration = mat['duration'][0][0] # must be some bug in encoding
    except TypeError:
        duration = mat['duration']
    # get the segments
    labfile = enmatfile+'.lab'
    assert os.path.exists(labfile),'can not find labfile %s' % labfile
    segstarts, segstops, labels = DUMMY.read_lab_file(labfile)
    # done, return
    return wav[0], wav[1], maxes, btstart, duration, segstarts, labels
def maxes_beattimes_segs_from_audiofile(wavfile):
    """
    Utility function
    From a given eavfile:
    - computes the fingerprint maxes
    - gets the corresponding en beat times
    - gets the corresponding annotated segments
    RETURN:
    signal, sampling rate, maxes, beatstarts, duration, segstarts, labels
    """
    # fingerprint it
    wav = LANDMARKS.AUDIOLAB.wavread(wavfile)
    L, S, T, maxes = LANDMARKS.find_landmarks(wav[0], wav[1])
    # find the EN matfile
    relwavfile = os.path.relpath(wavfile, start=_audio_dir)
    enmatfile = os.path.join(_enfeats_dir, relwavfile + '.mat')
    assert os.path.exists(enmatfile), 'can not find matfile %s' % enmatfile
    mat = sio.loadmat(enmatfile)
    btstart = mat['btstart']
    try:
        duration = mat['duration'][0][0]  # must be some bug in encoding
    except TypeError:
        duration = mat['duration']
    # get the segments
    labfile = enmatfile + '.lab'
    assert os.path.exists(labfile), 'can not find labfile %s' % labfile
    segstarts, segstops, labels = DUMMY.read_lab_file(labfile)
    # done, return
    return wav[0], wav[1], maxes, btstart, duration, segstarts, labels