voxseg_/utils.py
def process_data_dir(path: str, params, mode: str='train') -> Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame]:
    '''Function for processing Kaldi-style data directory containing wav.scp,
    segments (optional), and utt2spk (optional).

    Args:
        path: The path to the data directory.
        params: sound processing parameters -- used to extend slightly each segment, such that in training we can have frames that overlap segment boundaries (if most of the segment is part of a vocalization, it's label will be 1, if not, it will be 0)

    Returns:
        A tuple of pd.DataFrame in the format (wav_scp, segments, utt2spk), where
        pd.DataFrame contain data from the original files -- see docs for read_data_file().
        If a file is missing a null value is returned eg. a directory without utt2spk would
        return:
        (wav_scp, segments, None)

    Raises:
        FileNotFoundError: If wav.scp is not found.
    '''
    
    logging.info("Processing directory: {}".format(path))

    files = [f for f in os.listdir(path) if os.path.isfile(f'{path}/{f}')]
    try:
        wav_scp = read_data_file(f'{path}/wav.scp')
        wav_scp.columns = ['recording-id', 'extended filename']
    except FileNotFoundError:
        print('ERROR: Data directory needs to contain wav.scp file to be processed.')
        raise
    
    if 'segments' not in files:
        segments = None
    else:
        segments = read_data_file(f'{path}/segments')
        segments.columns = ['utterance-id', 'recording-id', 'start', 'end']
        segments[['start', 'end']] = segments[['start', 'end']].astype(float)
        
        '''
        ## extend the segments that are shorter than what is necessary to make a frame of the given frame length
        if mode != 'eval':
            wav_lens = dict()
            for _, row in wav_scp.iterrows():        
                rate, signal = wavfile.read(row['extended filename'])
                wav_lens[row['recording-id']] = len(signal)/rate

            min_len = (params['frame_length']-1) * params['winstep'] + params['winlen']            
            segments[['start','end']] = segments.apply(lambda x: _change_ends(x, min_len, wav_lens), axis=1)
        '''

    
    if 'utt2spk' not in files:
        utt2spk = None
    else:
        utt2spk = read_data_file(f'{path}/utt2spk')
        utt2spk.columns = ['utterance-id', 'speaker-id']
    return wav_scp, segments, utt2spk
Function for processing Kaldi-style data directory containing wav.scp,
    segments (optional), and utt2spk (optional).

    Args:
        path: The path to the data directory.
        params: sound processing parameters -- used to extend slightly each segment, such that in training we can have frames that overlap segment boundaries (if most of the segment is part of a vocalization, it's label will be 1, if not, it will be 0)

    Returns:
        A tuple of pd.DataFrame in the format (wav_scp, segments, utt2spk), where
        pd.DataFrame contain data from the original files -- see docs for read_data_file().
        If a file is missing a null value is returned eg. a directory without utt2spk would
        return:
        (wav_scp, segments, None)

    Raises:
        FileNotFoundError: If wav.scp is not found.
    
Function for processing Kaldi-style data directory containing wav.scp,
segments (optional), and utt2spk (optional).
Function for processing Kaldi - style data directory containing wav . scp segments ( optional ) and utt2spk ( optional ) .
def process_data_dir(path: str, params, mode: str='train') -> Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame]:
    logging.info("Processing directory: {}".format(path))
    files = [f for f in os.listdir(path) if os.path.isfile(f'{path}/{f}')]
    try:
        wav_scp = read_data_file(f'{path}/wav.scp')
        wav_scp.columns = ['recording-id', 'extended filename']
    except FileNotFoundError:
        print('ERROR: Data directory needs to contain wav.scp file to be processed.')
        raise
    if 'segments' not in files:
        segments = None
    else:
        segments = read_data_file(f'{path}/segments')
        segments.columns = ['utterance-id', 'recording-id', 'start', 'end']
        segments[['start', 'end']] = segments[['start', 'end']].astype(float)
    if 'utt2spk' not in files:
        utt2spk = None
    else:
        utt2spk = read_data_file(f'{path}/utt2spk')
        utt2spk.columns = ['utterance-id', 'speaker-id']
    return wav_scp, segments, utt2spk
def process_data_dir ( path : str , params , mode : str = 'train' ) -> Tuple [ pd . DataFrame , pd . DataFrame , pd . DataFrame ] : logging . info ( "Processing directory: {}" . format ( path ) ) files = [ f for f in os . listdir ( path ) if os . path . isfile ( f'{path}/{f}' ) ] try : wav_scp = read_data_file ( f'{path}/wav.scp' ) wav_scp . columns = [ 'recording-id' , 'extended filename' ] except FileNotFoundError : print ( 'ERROR: Data directory needs to contain wav.scp file to be processed.' ) raise if 'segments' not in files : segments = None else : segments = read_data_file ( f'{path}/segments' ) segments . columns = [ 'utterance-id' , 'recording-id' , 'start' , 'end' ] segments [ [ 'start' , 'end' ] ] = segments [ [ 'start' , 'end' ] ] . astype ( float ) '''
        ## extend the segments that are shorter than what is necessary to make a frame of the given frame length
        if mode != 'eval':
            wav_lens = dict()
            for _, row in wav_scp.iterrows():        
                rate, signal = wavfile.read(row['extended filename'])
                wav_lens[row['recording-id']] = len(signal)/rate

            min_len = (params['frame_length']-1) * params['winstep'] + params['winlen']            
            segments[['start','end']] = segments.apply(lambda x: _change_ends(x, min_len, wav_lens), axis=1)
        ''' if 'utt2spk' not in files : utt2spk = None else : utt2spk = read_data_file ( f'{path}/utt2spk' ) utt2spk . columns = [ 'utterance-id' , 'speaker-id' ] return wav_scp , segments , utt2spk
Function for processing Kaldi-style data directory containing wav.scp,
segments (optional), and utt2spk (optional).
Function for processing Kaldi - style data directory containing wav . scp segments ( optional ) and utt2spk ( optional ) .
'''Function for processing Kaldi-style data directory containing wav.scp,
    segments (optional), and utt2spk (optional).

    Args:
        path: The path to the data directory.
        params: sound processing parameters -- used to extend slightly each segment, such that in training we can have frames that overlap segment boundaries (if most of the segment is part of a vocalization, it's label will be 1, if not, it will be 0)

    Returns:
        A tuple of pd.DataFrame in the format (wav_scp, segments, utt2spk), where
        pd.DataFrame contain data from the original files -- see docs for read_data_file().
        If a file is missing a null value is returned eg. a directory without utt2spk would
        return:
        (wav_scp, segments, None)

    Raises:
        FileNotFoundError: If wav.scp is not found.
    ''' '''
        ## extend the segments that are shorter than what is necessary to make a frame of the given frame length
        if mode != 'eval':
            wav_lens = dict()
            for _, row in wav_scp.iterrows():        
                rate, signal = wavfile.read(row['extended filename'])
                wav_lens[row['recording-id']] = len(signal)/rate

            min_len = (params['frame_length']-1) * params['winstep'] + params['winlen']            
            segments[['start','end']] = segments.apply(lambda x: _change_ends(x, min_len, wav_lens), axis=1)
        '''
A tuple of pd.DataFrame in the format (wav_scp, segments, utt2spk), where
pd.DataFrame contain data from the original files -- see docs for read_data_file().
If a file is missing a null value is returned eg. a directory without utt2spk would
return:
(wav_scp, segments, None)
A tuple of pd . DataFrame in the format ( wav_scp segments utt2spk ) where pd . DataFrame contain data from the original files -- see docs for read_data_file () . If a file is missing a null value is returned eg . a directory without utt2spk would return : ( wav_scp segments None )
If wav.scp is not found.
If wav . scp is not found .
FileNotFoundError
path
str
The path to the data directory.
The path to the data directory .
params
sound processing parameters -- used to extend slightly each segment, such that in training we can have frames that overlap segment boundaries (if most of the segment is part of a vocalization, it's label will be 1, if not, it will be 0)
sound processing parameters -- used to extend slightly each segment such that in training we can have frames that overlap segment boundaries ( if most of the segment is part of a vocalization it ' s label will be 1 if not it will be 0 )
mode
str