Ejemplo n.º 1
0
 def test_time_slice_should_return_audio_samples(self):
     silence = AudioSamples.silence(SR11025(), Seconds(10))
     ts = TimeSlice(duration=Seconds(1))
     sliced = silence[ts]
     self.assertIsInstance(sliced, AudioSamples)
     self.assertEqual(int(SR11025()), len(sliced))
     self.assertEqual(SR11025(), sliced.samplerate)
Ejemplo n.º 2
0
 def test_stereo(self):
     silence = AudioSamples.silence(SR11025(), Seconds(10))
     self.assertEqual(1, silence.channels)
     stereo = silence.stereo
     self.assertEqual(2, stereo.channels)
     self.assertEqual((len(silence), 2), stereo.shape)
     np.testing.assert_allclose(silence, stereo[:, 0])
     np.testing.assert_allclose(silence, stereo[:, 1])
Ejemplo n.º 3
0
 def test_sliding_window_dimensions(self):
     samplerate = SR11025()
     samples = AudioSamples.silence(SR11025(), Seconds(10))
     window_sr = SampleRate(
         duration=samplerate.frequency * 512,
         frequency=samplerate.frequency * (512 - 25))
     windowed = samples.sliding_window(window_sr)
     self.assertEqual(window_sr, windowed.dimensions[0].samplerate)
Ejemplo n.º 4
0
 def test_sliding_window(self):
     samples = AudioSamples.silence(SR11025(), Seconds(30))
     sr = samples.samplerate * Stride(frequency=16, duration=512)
     windowed = samples.sliding_window(sr)
     self.assertEqual((512,), windowed.shape[1:])
     long_sr = SampleRate(
         frequency=sr.frequency * 2, duration=sr.frequency * 32)
     frequency = TimeSlice(duration=long_sr.frequency)
     duration = TimeSlice(duration=long_sr.duration)
     _, long_windowed = windowed.sliding_window_with_leftovers(
         windowsize=duration, stepsize=frequency, dopad=True)
     self.assertEqual((32, 512), long_windowed.shape[1:])
     self.assertEqual(3, long_windowed.ndim)
Ejemplo n.º 5
0
 def test_silence_like_creates_silence(self):
     silence = AudioSamples.silence(SR11025(), Seconds(1), channels=2)
     silence2 = silence.silence_like(Seconds(2))
     self.assertEqual((22050, 2), silence2.shape)
     self.assertEqual(SR11025(), silence2.samplerate)
     self.assertEqual(2, silence2.channels)
Ejemplo n.º 6
0
 def test_silence_honors_channels(self):
     silence = AudioSamples.silence(SR11025(), Seconds(1), channels=2)
     self.assertEqual((11025, 2), silence.shape)
     self.assertEqual(2, silence.channels)
Ejemplo n.º 7
0
 def test_silence_creates_silence(self):
     silence = AudioSamples.silence(SR11025(), Seconds(10))
     self.assertEqual(0, silence.sum())
Ejemplo n.º 8
0
 def test_integer_slice_should_return_scalar(self):
     silence = AudioSamples.silence(SR11025(), Seconds(10))
     sliced = silence[10]
     self.assertIsInstance(sliced, np.float32)
Ejemplo n.º 9
0
 def test_expanding_first_dimension_should_create_identity_dimension(self):
     silence = AudioSamples.silence(SR11025(), Seconds(10))
     expanded = silence[None, ...]
     self.assertEqual(2, len(expanded.dimensions))
     self.assertIsInstance(expanded.dimensions[0], IdentityDimension)
     self.assertEqual(silence.dimensions[0], expanded.dimensions[1])