voxseg_/extract_feats.py
def _calculate_feats(row: pd.DataFrame, params: dict, rate: int, interval_length: int) -> np.ndarray:
    '''Auxiliary function used by extract(). Extracts log-mel spectrograms from a row of a pd.DataFrame
    containing dataset information created by prep_data().

    Args:
        row: A row of a pd.DataFrame created by prep_data().
        params: a dictionary containing
                    frame_length -- the size of the input to the CNN, 
                    nfilt -- number of filters for logfbank
                    winlen -- size of the window for logfbank
                    winstep -- step for logfbank 
        rate: Sample rate.

    Returns:
        An np.ndarray of features.
    '''

    sig = row['signal']
    if 'utterance-id' in row:
        id = row['utterance-id']
    else:
        id = row['recording-id']
        
    try:
        nfft = int(params['winlen'] * rate)
        len_sig = len(sig)
        
        assert len(range(0, len_sig-1-interval_length, interval_length)) > 0
        feats = []
        ends = []
        
        for j in utils.progressbar(range(0, len_sig-1-interval_length, interval_length), id):
            feats.append(np.flipud(logfbank(sig[j:j + interval_length], rate, winlen=params['winlen'], winstep=params['winstep'], nfilt=params['nfilt'], nfft=nfft).T))
            ends.append([j, j+interval_length])
            
        ## add last incomplete interval
        if ends[-1][1] < len_sig:
            feats.append(np.flipud(logfbank(sig[len_sig-interval_length:len_sig], rate, winlen=params['winlen'], winstep=params['winstep'], nfilt=params['nfilt'], nfft=nfft).T))
            ends.append([len_sig-interval_length, len_sig])    
                        
        return (np.array(feats), np.array(ends))
        #return np.array(feats)
    
    except AssertionError:
        print(f'WARNING: {id} is too short to extract features, will be ignored.')
        return (np.nan, np.nan)
        #return np.nan
Auxiliary function used by extract(). Extracts log-mel spectrograms from a row of a pd.DataFrame
    containing dataset information created by prep_data().

    Args:
        row: A row of a pd.DataFrame created by prep_data().
        params: a dictionary containing
                    frame_length -- the size of the input to the CNN, 
                    nfilt -- number of filters for logfbank
                    winlen -- size of the window for logfbank
                    winstep -- step for logfbank 
        rate: Sample rate.

    Returns:
        An np.ndarray of features.
    
Auxiliary function used by extract(). Extracts log-mel spectrograms from a row of a pd.DataFrame
containing dataset information created by prep_data().
Auxiliary function used by extract () . Extracts log - mel spectrograms from a row of a pd . DataFrame containing dataset information created by prep_data () .
def _calculate_feats(row: pd.DataFrame, params: dict, rate: int, interval_length: int) -> np.ndarray:
    sig = row['signal']
    if 'utterance-id' in row:
        id = row['utterance-id']
    else:
        id = row['recording-id']
    try:
        nfft = int(params['winlen'] * rate)
        len_sig = len(sig)
        assert len(range(0, len_sig-1-interval_length, interval_length)) > 0
        feats = []
        ends = []
        for j in utils.progressbar(range(0, len_sig-1-interval_length, interval_length), id):
            feats.append(np.flipud(logfbank(sig[j:j + interval_length], rate, winlen=params['winlen'], winstep=params['winstep'], nfilt=params['nfilt'], nfft=nfft).T))
            ends.append([j, j+interval_length])
        if ends[-1][1] < len_sig:
            feats.append(np.flipud(logfbank(sig[len_sig-interval_length:len_sig], rate, winlen=params['winlen'], winstep=params['winstep'], nfilt=params['nfilt'], nfft=nfft).T))
            ends.append([len_sig-interval_length, len_sig])    
        return (np.array(feats), np.array(ends))
    except AssertionError:
        print(f'WARNING: {id} is too short to extract features, will be ignored.')
        return (np.nan, np.nan)
def _calculate_feats ( row : pd . DataFrame , params : dict , rate : int , interval_length : int ) -> np . ndarray : sig = row [ 'signal' ] if 'utterance-id' in row : id = row [ 'utterance-id' ] else : id = row [ 'recording-id' ] try : nfft = int ( params [ 'winlen' ] * rate ) len_sig = len ( sig ) assert len ( range ( 0 , len_sig - 1 - interval_length , interval_length ) ) > 0 feats = [ ] ends = [ ] for j in utils . progressbar ( range ( 0 , len_sig - 1 - interval_length , interval_length ) , id ) : feats . append ( np . flipud ( logfbank ( sig [ j : j + interval_length ] , rate , winlen = params [ 'winlen' ] , winstep = params [ 'winstep' ] , nfilt = params [ 'nfilt' ] , nfft = nfft ) . T ) ) ends . append ( [ j , j + interval_length ] ) if ends [ - 1 ] [ 1 ] < len_sig : feats . append ( np . flipud ( logfbank ( sig [ len_sig - interval_length : len_sig ] , rate , winlen = params [ 'winlen' ] , winstep = params [ 'winstep' ] , nfilt = params [ 'nfilt' ] , nfft = nfft ) . T ) ) ends . append ( [ len_sig - interval_length , len_sig ] ) return ( np . array ( feats ) , np . array ( ends ) ) except AssertionError : print ( f'WARNING: {id} is too short to extract features, will be ignored.' ) return ( np . nan , np . nan )
Auxiliary function used by extract().
Auxiliary function used by extract () .
'''Auxiliary function used by extract(). Extracts log-mel spectrograms from a row of a pd.DataFrame
    containing dataset information created by prep_data().

    Args:
        row: A row of a pd.DataFrame created by prep_data().
        params: a dictionary containing
                    frame_length -- the size of the input to the CNN, 
                    nfilt -- number of filters for logfbank
                    winlen -- size of the window for logfbank
                    winstep -- step for logfbank 
        rate: Sample rate.

    Returns:
        An np.ndarray of features.
    ''' ## add last incomplete interval #return np.array(feats) #return np.nan
An np.ndarray of features.
An np . ndarray of features .
row
pd.DataFrame
A row of a pd.DataFrame created by prep_data().
A row of a pd . DataFrame created by prep_data () .
params
dict
a dictionary containing
frame_length -- the size of the input to the CNN,
nfilt -- number of filters for logfbank
winlen -- size of the window for logfbank
winstep -- step for logfbank
a dictionary containing frame_length -- the size of the input to the CNN nfilt -- number of filters for logfbank winlen -- size of the window for logfbank winstep -- step for logfbank
rate
int
None
interval_length
int