示例#1
0
def test_signal_cutout():
    c, s = 2, 16000
    min_cut_pct, max_cut_pct = 0.10, 0.15
    # Create tensor with no zeros
    audio = AudioTensor(torch.rand([c, s]), sr=16000) * 0.9 + 0.1
    cutout = SignalCutoutGPU(p=1.0, min_cut_pct=min_cut_pct, max_cut_pct=max_cut_pct)
    inp, out = apply_transform(cutout, audio)

    _test_ne(inp.data, out.data)

    num_zeros = (out == 0).sum()
    assert min_cut_pct * s * c <= num_zeros <= max_cut_pct * s * c, num_zeros
示例#2
0
def test_spectrograms_right_side_up():
    DBMelSpec = SpectrogramTransformer(mel=True, to_db=True)
    a2s_5hz = DBMelSpec(
        sample_rate=16000,
        n_fft=1024,
        win_length=1024,
        hop_length=512,
        f_min=0.0,
        f_max=20000,
        pad=0,
        n_mels=137,
    )
    sine_5hz = 0.5 * torch.cos(2 * math.pi * 5 * torch.arange(0, 1.0, 1.0 / 16000))
    at_5hz = AudioTensor(sine_5hz[None], 16000)
    sg_5hz = a2s_5hz(at_5hz)
    max_row = sg_5hz.max(dim=1).indices.mode().values.item()
    assert max_row < 2
示例#3
0
def test_check_nchannels():
    audio_tensor = AudioTensor(torch.ones(1, 3, 10), sr=120)
    assert audio_tensor.nchannels == 3
示例#4
0
def test_add_tensors():
    tst0 = AudioTensor(torch.ones(10), sr=120)
    tst1 = AudioTensor(torch.ones(10), sr=150)
    assert (tst0 + tst1).sr == 120