Example #1
0
 def test_padding_cut_audio_mask(self):
     cut = PaddingCut('cut',
                      duration=2,
                      sampling_rate=16000,
                      use_log_energy=True,
                      num_samples=32000)
     mask = cut.supervisions_audio_mask()
     assert mask.sum() == 0
Example #2
0
 def test_padding_cut_audio_mask(self):
     cut = PaddingCut('cut',
                      duration=2,
                      sampling_rate=16000,
                      feat_value=LOG_EPSILON,
                      num_samples=32000)
     mask = cut.supervisions_audio_mask()
     assert mask.sum() == 0
Example #3
0
def test_padding_cut_perturb():
    cut = PaddingCut(id='cut',
                     duration=5.75,
                     sampling_rate=16000,
                     feat_value=1e-10,
                     num_samples=92000)
    cut_sp = cut.perturb_speed(1.1)
    assert cut_sp.num_samples == 83636
    assert cut_sp.duration == 5.22725
Example #4
0
def test_padding_cut_perturb():
    cut = PaddingCut(id='cut',
                     duration=5.75,
                     sampling_rate=16000,
                     use_log_energy=True,
                     num_samples=92000)
    cut_sp = cut.perturb_speed(1.1)
    assert cut_sp.num_samples == 83636
    assert cut_sp.duration == 5.22725
Example #5
0
 def test_padding_cut_features_mask(self):
     cut = PaddingCut('cut',
                      duration=2,
                      sampling_rate=16000,
                      feat_value=LOG_EPSILON,
                      num_frames=2000,
                      num_features=13)
     mask = cut.supervisions_feature_mask()
     assert mask.sum() == 0
Example #6
0
 def test_padding_cut_features_mask(self):
     cut = PaddingCut('cut',
                      duration=2,
                      sampling_rate=16000,
                      use_log_energy=True,
                      num_frames=2000,
                      num_features=13)
     mask = cut.supervisions_feature_mask()
     assert mask.sum() == 0
Example #7
0
def test_resample_padding_cut():
    original = PaddingCut(id='cut',
                          duration=5.75,
                          sampling_rate=16000,
                          feat_value=1e-10,
                          num_samples=92000)
    resampled = original.resample(8000)
    assert resampled.sampling_rate == 8000
    assert resampled.num_samples == original.num_samples / 2
    samples = resampled.load_audio()
    assert samples.shape[1] == resampled.num_samples
Example #8
0
def test_padding_cut_perturb_volume():
    cut = PaddingCut(
        id="cut",
        duration=5.75,
        sampling_rate=16000,
        feat_value=1e-10,
        num_samples=92000,
    )
    cut_vp = cut.perturb_volume(0.125)
    assert cut_vp.num_samples == cut.num_samples
    assert cut_vp.duration == cut.duration
    np.testing.assert_array_almost_equal(cut_vp.load_audio(), cut.load_audio())
Example #9
0
def test_padding_cut_reverb_rir(rir):
    cut = PaddingCut(
        id="cut",
        duration=5.75,
        sampling_rate=16000,
        feat_value=1e-10,
        num_samples=92000,
    )
    cut_rvb = cut.reverb_rir(rir_recording=rir)
    assert cut_rvb.num_samples == cut.num_samples
    assert cut_rvb.duration == cut.duration
    np.testing.assert_array_almost_equal(cut_rvb.load_audio(), cut.load_audio())
Example #10
0
def padding_cut():
    return PaddingCut(id='padding-1',
                      duration=10.0,
                      num_frames=1000,
                      num_features=40,
                      sampling_rate=16000,
                      num_samples=160000,
                      use_log_energy=True)
Example #11
0
def padding_cut():
    return PaddingCut(id='padding-1',
                      duration=10.0,
                      num_frames=1000,
                      num_features=40,
                      frame_shift=0.01,
                      sampling_rate=16000,
                      num_samples=160000,
                      feat_value=PADDING_LOG_ENERGY)
Example #12
0
def padding_cut():
    return PaddingCut(
        id="padding-1",
        duration=10.0,
        num_frames=1000,
        num_features=40,
        frame_shift=0.01,
        sampling_rate=16000,
        num_samples=160000,
        feat_value=LOG_EPSILON,
    )
def cutset():
    return CutSet.from_cuts([
        # MonoCut
        dummy_cut(0, supervisions=[dummy_supervision(0)]),
        # PaddingCut
        PaddingCut('pad', duration=1.0, sampling_rate=16000, feat_value=-100,
                   num_frames=100, frame_shift=0.01, num_features=80, num_samples=16000),
        # MixedCut
        dummy_cut(0, supervisions=[dummy_supervision(0)]).mix(
            dummy_cut(1, supervisions=[dummy_supervision(1)]),
            offset_other_by=0.5,
            snr=10
        )
    ])
import pytest

from lhotse import CutSet
from lhotse.cut import PaddingCut
from lhotse.testing.dummies import dummy_cut, dummy_supervision

parametrize_on_cut_types = pytest.mark.parametrize(
    'cut', [
        # MonoCut
        dummy_cut(0, supervisions=[dummy_supervision(0)]),
        # PaddingCut
        PaddingCut('pad', duration=1.0, sampling_rate=16000, feat_value=-100,
                   num_frames=100, frame_shift=0.01, num_features=80, num_samples=16000),
        # MixedCut
        dummy_cut(0, supervisions=[dummy_supervision(0)]).mix(
            dummy_cut(1, supervisions=[dummy_supervision(1)]),
            offset_other_by=0.5,
            snr=10
        )
    ]
)


@parametrize_on_cut_types
def test_drop_features(cut):
    assert cut.has_features
    cut_drop = cut.drop_features()
    assert cut.has_features
    assert not cut_drop.has_features