def test_pad_sound_with_silence(self): sound = SoundBuffer('tests/sounds/guitar1s.wav') # Pad start original_length = len(sound) silence_length = random.randint(100, 44100) sound.pad(silence_length) self.assertEqual(len(sound), silence_length + original_length) self.assertEqual(sound[0], (0,0)) # Pad end original_length = len(sound) silence_length = random.randint(100, 44100) sound.pad(end=silence_length) self.assertEqual(len(sound), silence_length + original_length) self.assertEqual(sound[-1], (0,0))
def test_pad_sound_with_silence(self): sound = SoundBuffer(filename='tests/sounds/guitar1s.wav') # Pad start original_length = len(sound) silence_length = random.triangular(0.001, 1) sound = sound.pad(silence_length) self.assertEqual(len(sound), int((sound.samplerate * silence_length) + original_length)) self.assertEqual(sound[0], (0,0)) # Pad end original_length = len(sound) silence_length = random.triangular(0.001, 1) sound = sound.pad(end=silence_length) self.assertEqual(len(sound), int((sound.samplerate * silence_length) + original_length)) self.assertEqual(sound[-1], (0,0))
def test_trim_silence(self): sound = SoundBuffer( filename='tests/sounds/guitar1s.wav').env('hannout') firstval = abs(sum(sound[0])) lastval = abs(sum(sound[-1])) sound = sound.pad(start=1, end=1) self.assertEqual(sound.dur, 3) sound.write('tests/renders/trim_silence_before.wav') for threshold in (0, 0.01, 0.5): trimstart = sound.trim(start=True, end=False, threshold=threshold) trimstart.write('tests/renders/trim_silence_start%s.wav' % threshold) trimend = sound.trim(start=False, end=True, threshold=threshold) trimend.write('tests/renders/trim_silence_end%s.wav' % threshold)