def test_stft_extractor(): stim = AudioStim(join(AUDIO_DIR, 'barber.wav'), onset=4.2) ext = STFTAudioExtractor(frame_size=1., spectrogram=False, freq_bins=[(100, 300), (300, 3000), (3000, 20000)]) result = ext.transform(stim) df = result.to_df() assert df.shape == (557, 7) assert df['onset'][0] == 4.2 ext = STFTAudioExtractor(frame_size=1., spectrogram=False, freq_bins=5) result = ext.transform(stim) df = result.to_df(timing=False, object_id=False) assert df.shape == (557, 5) assert '0_1102' in df.columns
def test_stft_extractor(): audio_dir = join(get_test_data_path(), 'audio') stim = AudioStim(join(audio_dir, 'barber.wav')) ext = STFTAudioExtractor(frame_size=1., spectrogram=False, freq_bins=[(100, 300), (300, 3000), (3000, 20000)]) result = ext.transform(stim) df = result.to_df() assert df.shape == (557, 5)
def test_convert_to_long(): audio_dir = join(get_test_data_path(), 'audio') stim = AudioStim(join(audio_dir, 'barber.wav')) ext = STFTAudioExtractor(frame_size=1., spectrogram=False, freq_bins=[(100, 300), (300, 3000), (3000, 20000)]) timeline = ext.transform(stim) long_timeline = to_long_format(timeline) assert long_timeline.shape == (timeline.to_df().shape[0] * 3, 4) assert 'feature' in long_timeline.columns assert 'value' in long_timeline.columns assert '100_300' not in long_timeline.columns timeline = ExtractorResult.merge_features([timeline]) long_timeline = to_long_format(timeline) assert 'feature' in long_timeline.columns assert 'extractor' in long_timeline.columns assert '100_300' not in long_timeline.columns
# peep_spectrum.py from pliers.extractors import STFTAudioExtractor import matplotlib snd_0 = 'snd/peep-I-neu-chk.wav' snd_1 = 'snd/peep-I-hap-tlk.mp3' snds = [snd_0, snd_1] # result will generate spectrogram ext = STFTAudioExtractor(freq_bins=10, spectrogram=True) result = ext.transform(snds) print(result[0]) print(result[1])