(*args, **kwargs)
pyfeat, extract feat from utt and dump it
pyfeat, extract feat from utt and dump it
pyfeat extract feat from utt and dump it
def extract_feat(*args, **kwargs):
  ''' pyfeat, extract feat from utt and dump it '''
  logging.debug("extract_feat : {}".format(kwargs))

  winlen = kwargs.get('winlen')
  winstep = kwargs.get('winstep')
  feature_size = kwargs.get('feature_size')
  sr = kwargs.get('sr')  #pylint: disable=invalid-name
  nfft = kwargs.get('nfft')
  lowfreq = kwargs.get('lowfreq')
  highfreq = kwargs.get('highfreq')
  preemph = kwargs.get('preemph')
  save_feat_path = kwargs.get('save_feat_path')
  dry_run = kwargs.get('dry_run')
  feat_type = kwargs.get('feat_type')

  del lowfreq, preemph

  if save_feat_path and not os.path.exists(save_feat_path):
    os.makedirs(save_feat_path)

  for wavpath in args:
    if save_feat_path:
      filename = os.path.splitext(os.path.split(wavpath)[-1])[0] + '.npy'
      savepath = os.path.join(save_feat_path, filename)
    else:
      savepath = os.path.splitext(wavpath)[0] + '.npy'
    logging.debug('input: {}, output: {}'.format(wavpath, savepath))

    sr_out, samples = load_wav(wavpath, sr=sr)
    del sr_out
    feat = powspec_feat(
        samples, sr=sr, nfft=nfft, winlen=winlen, winstep=winstep)
    logging.debug('apply power spectorgram')

    if feat_type == 'spectrogram':
      # shape: [T, F]
      feat = psf.logpowerspec(feat)
      if highfreq:
        resolution = freq_resolution(sr, nfft)
        ps = int(points(highfreq, resolution))  #pylint: disable=invalid-name
        logging.debug("feat slice: {} {}".format(ps, type(ps)))
        feat = feat[:, :ps]
      logging.debug('apply log power spectorgram')
    elif feat_type == 'logfbank':
      feat = fbank_feat(feat, sr=sr, nfft=nfft, feature_size=feature_size)
      logging.debug('apply fbank spectorgram')
    else:
      raise ValueError("not support feat method")

    feat = feat.astype(np.float32)
    if dry_run:
      logging.info('save feat: path {} shape:{} dtype:{}'.format(
          savepath, feat.shape, feat.dtype))
    else:
      np.save(savepath, feat)
def extract_feat ( * args , * * kwargs ) : logging . debug ( "extract_feat : {}" . format ( kwargs ) ) winlen = kwargs . get ( 'winlen' ) winstep = kwargs . get ( 'winstep' ) feature_size = kwargs . get ( 'feature_size' ) sr = kwargs . get ( 'sr' ) #pylint: disable=invalid-name nfft = kwargs . get ( 'nfft' ) lowfreq = kwargs . get ( 'lowfreq' ) highfreq = kwargs . get ( 'highfreq' ) preemph = kwargs . get ( 'preemph' ) save_feat_path = kwargs . get ( 'save_feat_path' ) dry_run = kwargs . get ( 'dry_run' ) feat_type = kwargs . get ( 'feat_type' ) del lowfreq , preemph if save_feat_path and not os . path . exists ( save_feat_path ) : os . makedirs ( save_feat_path ) for wavpath in args : if save_feat_path : filename = os . path . splitext ( os . path . split ( wavpath ) [ - 1 ] ) [ 0 ] + '.npy' savepath = os . path . join ( save_feat_path , filename ) else : savepath = os . path . splitext ( wavpath ) [ 0 ] + '.npy' logging . debug ( 'input: {}, output: {}' . format ( wavpath , savepath ) ) sr_out , samples = load_wav ( wavpath , sr = sr ) del sr_out feat = powspec_feat ( samples , sr = sr , nfft = nfft , winlen = winlen , winstep = winstep ) logging . debug ( 'apply power spectorgram' ) if feat_type == 'spectrogram' : # shape: [T, F] feat = psf . logpowerspec ( feat ) if highfreq : resolution = freq_resolution ( sr , nfft ) ps = int ( points ( highfreq , resolution ) ) #pylint: disable=invalid-name logging . debug ( "feat slice: {} {}" . format ( ps , type ( ps ) ) ) feat = feat [ : , : ps ] logging . debug ( 'apply log power spectorgram' ) elif feat_type == 'logfbank' : feat = fbank_feat ( feat , sr = sr , nfft = nfft , feature_size = feature_size ) logging . debug ( 'apply fbank spectorgram' ) else : raise ValueError ( "not support feat method" ) feat = feat . astype ( np . float32 ) if dry_run : logging . info ( 'save feat: path {} shape:{} dtype:{}' . format ( savepath , feat . shape , feat . dtype ) ) else : np . save ( savepath , feat )