(self, args)
return results
Utt to samples of (feat_chunk, spk_id, sample_key).
    Will be run in a process pool so restrictions apply.
Utt to samples of (feat_chunk, spk_id, sample_key).
    Will be run in a process pool so restrictions apply.
Utt to samples of ( feat_chunk spk_id sample_key ) . Will be run in a process pool so restrictions apply .
def utt_to_samples(self, args):
    '''
    Utt to samples of (feat_chunk, spk_id, sample_key).
    Will be run in a process pool so restrictions apply.
    '''
    result_queue, utt_info = args
    logging.debug(utt_info)

    # TODO: wrap into a function or something
    utt_key, utt_meta = utt_info

    # Load features and select voiced frames.
    feat_scp = utt_meta['feat']
    feat_mat = kaldiio.load_mat(feat_scp)
    num_frames_feat, feat_dim = feat_mat.shape
    vad_scp = utt_meta['vad']

    if vad_scp:
      vad_mat = kaldiio.load_mat(vad_scp)
      num_frames_vad = vad_mat.shape[0]
      logging.debug('feat_mat: %s, vad_mat: %s' %
                    (str(feat_mat.shape), str(vad_mat.shape)))
      if num_frames_feat != num_frames_vad:
        logging.debug('num_frames_feat != num_frames_vad: %d vs %d' %
                      (num_frames_feat, num_frames_vad))
        return None
      voiced_frames_index = np.where(vad_mat == 1)[0]
      logging.debug('voiced_frames_index: %s' %
                    (str(voiced_frames_index.shape)))
      feat_mat_voiced = feat_mat[voiced_frames_index, :]
    else:
      # If no VAD info was found, the entire utt will be used.
      feat_mat_voiced = feat_mat
    num_frames_voiced = feat_mat_voiced.shape[0]
    logging.debug('feat_mat_voiced: %s' % (str(feat_mat_voiced.shape)))

    spk_id = utt_meta['spkid']

    logging.debug('Chunk size: %d' % (self.chunk_size))

    results = []
    chunk_idx = 0
    if self.add_random_offset:
      random_offset = np.random.randint(0, self.chunk_size)
    else:
      random_offset = 0
    for offset in range(random_offset, num_frames_voiced, self.chunk_size):
      if self.single_chunk:
        available = num_frames_voiced - self.chunk_size
        if available < 0:
          # No padding.
          logging.warn('Single chunk mode: available < 0.')
          break
        offset = random.randint(0, available)
      logging.debug('offset = %d' % (offset))
      feat_chunk = feat_mat_voiced[offset:offset + self.chunk_size, :]
      unpadded_frames = feat_chunk.shape[0]
      if self.pad_chunks and unpadded_frames < self.chunk_size:
        rel_chunk_len = float(unpadded_frames) / self.chunk_size
        if rel_chunk_len < self.drop_short_chunks:
          continue
        logging.debug('Padding chunk of frames %d ...' % (unpadded_frames))
        padded = np.zeros((self.chunk_size, feat_dim), dtype=feat_chunk.dtype)
        padded[:unpadded_frames, :] = feat_chunk
        feat_chunk = padded
      feat_chunk = np.expand_dims(feat_chunk, axis=2)  # TODO: not here
      sample_key = '%s_chunk%02d' % (utt_key, chunk_idx)
      sample = (feat_chunk, spk_id, sample_key)
      chunk_idx += 1
      results.append(sample)
      if self.single_chunk:
        break
    if result_queue:
      # queue mode
      result_queue.put(results)
      return None
    # imap mode
    return results
def utt_to_samples ( self , args ) : result_queue , utt_info = args logging . debug ( utt_info ) # TODO: wrap into a function or something utt_key , utt_meta = utt_info # Load features and select voiced frames. feat_scp = utt_meta [ 'feat' ] feat_mat = kaldiio . load_mat ( feat_scp ) num_frames_feat , feat_dim = feat_mat . shape vad_scp = utt_meta [ 'vad' ] if vad_scp : vad_mat = kaldiio . load_mat ( vad_scp ) num_frames_vad = vad_mat . shape [ 0 ] logging . debug ( 'feat_mat: %s, vad_mat: %s' % ( str ( feat_mat . shape ) , str ( vad_mat . shape ) ) ) if num_frames_feat != num_frames_vad : logging . debug ( 'num_frames_feat != num_frames_vad: %d vs %d' % ( num_frames_feat , num_frames_vad ) ) return None voiced_frames_index = np . where ( vad_mat == 1 ) [ 0 ] logging . debug ( 'voiced_frames_index: %s' % ( str ( voiced_frames_index . shape ) ) ) feat_mat_voiced = feat_mat [ voiced_frames_index , : ] else : # If no VAD info was found, the entire utt will be used. feat_mat_voiced = feat_mat num_frames_voiced = feat_mat_voiced . shape [ 0 ] logging . debug ( 'feat_mat_voiced: %s' % ( str ( feat_mat_voiced . shape ) ) ) spk_id = utt_meta [ 'spkid' ] logging . debug ( 'Chunk size: %d' % ( self . chunk_size ) ) results = [ ] chunk_idx = 0 if self . add_random_offset : random_offset = np . random . randint ( 0 , self . chunk_size ) else : random_offset = 0 for offset in range ( random_offset , num_frames_voiced , self . chunk_size ) : if self . single_chunk : available = num_frames_voiced - self . chunk_size if available < 0 : # No padding. logging . warn ( 'Single chunk mode: available < 0.' ) break offset = random . randint ( 0 , available ) logging . debug ( 'offset = %d' % ( offset ) ) feat_chunk = feat_mat_voiced [ offset : offset + self . chunk_size , : ] unpadded_frames = feat_chunk . shape [ 0 ] if self . pad_chunks and unpadded_frames < self . chunk_size : rel_chunk_len = float ( unpadded_frames ) / self . chunk_size if rel_chunk_len < self . drop_short_chunks : continue logging . debug ( 'Padding chunk of frames %d ...' % ( unpadded_frames ) ) padded = np . zeros ( ( self . chunk_size , feat_dim ) , dtype = feat_chunk . dtype ) padded [ : unpadded_frames , : ] = feat_chunk feat_chunk = padded feat_chunk = np . expand_dims ( feat_chunk , axis = 2 ) # TODO: not here sample_key = '%s_chunk%02d' % ( utt_key , chunk_idx ) sample = ( feat_chunk , spk_id , sample_key ) chunk_idx += 1 results . append ( sample ) if self . single_chunk : break if result_queue : # queue mode result_queue . put ( results ) return None # imap mode return results