示例#1
0
def create_feature_files(data_path, output_path, df_files, feat_config):
    files = df_files.copy()

    # Extract the feature settings
    wlen = feat_config['window_length']
    wstep = feat_config['window_step']
    srate = feat_config['sample_rate']
    fsize = feat_config['feature_size']

    # load all the files needer per subjects
    l = df_files.shape[0]
    for i in range(0, l):
        print('Processing file ', i + 1, ' of ', l)
        file_name = df_files.at[i, 'FileName']
        feat_file = savepath = os.path.splitext(file_name)[0] + '.npy'

        # DELTA function that extracts from the file the features
        # the resulting data gets dumped to an equivalently named
        # feature numpy file.
        speech_feature.extract_feature(file_name,
                                       winlen=wlen,
                                       winstep=wstep,
                                       sr=srate,
                                       feature_size=fsize,
                                       feature_name='fbank')

        # Move the file to the feature path
        dest_file = output_path + '/' + os.path.basename(feat_file)
        data = np.load(feat_file)
        os.rename(feat_file, dest_file)

        # Replace the file name with the feature file name
        files.at[i, 'FileName'] = dest_file
    return files
示例#2
0
  def test_tf_delta_detla(self):
    ''' test tensorflow delta delta '''
    speech_feature.extract_feature((self.wavfile),
                                      winlen=self.winlen,
                                      winstep=self.winstep,
                                      sr=self.sr,
                                      feature_size=self.feature_size,
                                      feature_name='fbank')

    feat = np.load(self.featfile)
    self.assertEqual(feat.shape, (425, 40, 1))
    feat = speech_feature.add_delta_delta(feat, 40, order=2)
    self.assertEqual(feat.shape, (425, 40, 3))
示例#3
0
  def test_tf_spec(self):
    ''' test tensorflow spec feature interface '''
    speech_feature.extract_feature((self.wavfile),
                                      winlen=self.winlen,
                                      winstep=self.winstep,
                                      sr=self.sr,
                                      feature_size=self.feature_size,
                                      feature_name='spec')
    feat = np.load(self.featfile)
    self.assertEqual(feat.shape, (425, 129, 1))

    with self.session(use_gpu=False):
      feat = speech_ops.delta_delta(feat, 2)
      self.assertEqual(feat.eval().shape, (425, 129, 3))
示例#4
0
  def test_tf_fbank(self):
    ''' test tensorflow fbank feature interface '''
    speech_feature.extract_feature((self.wavfile),
                                      winlen=self.winlen,
                                      winstep=self.winstep,
                                      sr=self.sr,
                                      feature_size=self.feature_size,
                                      feature_name='fbank')

    feat = np.load(self.featfile)
    logging.info(f"feat : {feat}")
    self.assertEqual(feat.shape, (425, 40, 1))

    with self.session(use_gpu=False):
      feat = speech_ops.delta_delta(feat, 2)
      self.assertEqual(feat.eval().shape, (425, 40, 3))