def test_save(self): filename = get_file_name() df = AudioDataFile() df.load(filename, formatter=AIFFormatter()) df.save("tmp.h5", formatter=HDF5Formatter()) df2 = AudioDataFile().load("tmp.h5", formatter=HDF5Formatter()) assert df2.duration.seconds > 0
def test_scale(): file_name = get_file_name() df = AudioDataFile().load(file_name, formatter=AIFFormatter()) p = Scale() p.parameters["data"] = df result = p.transform() assert p.description != "" assert type(result) is df.__class__
def test_identity(): file_name = get_file_name() df = AudioDataFile().load(file_name, formatter=AIFFormatter()) f = Identity() f.parameters["data"] = df t = f.transform() np.testing.assert_allclose(df.data.values.ravel(), t.data.values.ravel()) assert f.description != "" assert t.data.values.ndim == 2
def test_add_remove_datafile(self): filename = get_file_name() df = AudioDataFile() df.load(filename, formatter=AIFFormatter()) ds = OneDataFileOut() ds.add_data_file(df) assert len(ds.datafiles) == 1 ds.remove_data_file(df) assert len(ds.datafiles) == 0
def test_skewness(): file_name = get_file_name() df = AudioDataFile().load(file_name, formatter=AIFFormatter()) df.data -= df.data.mean() f = Skewness() f.parameters["data"] = df t = f.transform() assert t.data.values.shape[1] == 1 assert f.description != "" assert t.data.values.ndim == 2
def test_sliding_windows(): filename = get_file_name() p = SlidingWindows() p.parameters["sliding_window_width"] = "13s" p.parameters["overlap"] = 0.12 df = AudioDataFile() df.load(filename, formatter=AIFFormatter()) p.parameters["data"] = df new_df = p.transform() new_df.get_windows_data_frame() assert p.description != ""
def test_spectral_frames(): file_name = get_file_name() df = AudioDataFile().load(file_name, formatter=AIFFormatter()) df.data -= df.data.mean() f = SpectralFrames() f.parameters["sampling_rate"] = df.sampling_rate f.parameters["data"] = df t = f.transform() assert t.data.values.shape[0] == 1 assert f.description != "" assert t.data.values.ndim == 2
def test_mfcc(): file_name = get_file_name() df = AudioDataFile().load(file_name, formatter=AIFFormatter()) df.data -= df.data.mean() f = MFCC() f.parameters["sampling_rate"] = df.sampling_rate f.parameters["n_components"] = 25 f.parameters["data"] = df t = f.transform() assert t.data.values.shape[1] == 25 assert f.description != "" assert t.data.values.ndim == 2
def test_load(self): filename = get_file_name() df = AudioDataFile() # No attribute data assert str(df) == "AudioDataFile" with pytest.raises(RuntimeError): df.duration with pytest.raises(RuntimeError): df.start_time with pytest.raises(RuntimeError): df.end_time df.load(filename, formatter=AIFFormatter()) assert df.duration.seconds > 0 assert str(df) == "AudioDataFile (0 days 00:14:59.999500)"
def test_read(self): filename = get_file_name() formatter = AIFFormatter() df = formatter.read(filename) assert type(df) is pd.Series assert len(df) > 0 assert type(df.index) is pd.DatetimeIndex new_filename = "same_file_new_name.aif" rename(filename, "same_file_new_name.aif") df = formatter.read(new_filename) assert type(df) is pd.Series assert len(df) > 0 assert type(df.index) is pd.RangeIndex
def test_sampling_rate(self): filename = get_file_name() df = AudioDataFile() assert df.sampling_rate is None df.load(filename, formatter=AIFFormatter()) assert df.sampling_rate > 0
def test_read_metadata(self): filename = get_file_name() formatter = AIFFormatter() metadata = formatter.read_metadata(filename) assert type(metadata) is dict