Skip to content

Commit

Permalink
closes #19; moves splice to combine
Browse files Browse the repository at this point in the history
  • Loading branch information
rabitt committed Aug 22, 2016
1 parent 4d0fe3a commit 9b80a80
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
3 changes: 3 additions & 0 deletions sox/combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ def set_input_format(self, file_type=None, rate=None, bits=None,
self.input_format = input_format
return self

def splice(self):
raise NotImplementedError


def _validate_file_formats(input_filepath_list, combine_type):
'''Validate that combine method can be performed with given files.
Expand Down
23 changes: 20 additions & 3 deletions sox/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -1806,10 +1806,27 @@ def silence(self, location=0, silence_threshold=0.1,
def sinc(self):
raise NotImplementedError

def speed(self):
raise NotImplementedError
def speed(self, factor):
'''Adjust the audio speed (pitch and tempo together).
Technically, the speed effect only changes the sample rate information,
leaving the samples themselves untouched. The rate effect is invoked
automatically to resample to the output sample rate, using its default
quality/speed. For higher quality or higher speed resampling, in
addition to the speed effect, specify the rate effect with the desired
quality option.
Parameters
----------
factor : float
The ratio of the new tempo to the old tempo.
For ex. 1.1 speeds up the tempo by 10%; 0.9 slows it down by 10%.
Note - this argument is the inverse of what is passed to the sox
stretch effect for consistency with tempo.
def splice(self):
See Also
--------
tempo, pitch, rate
'''
raise NotImplementedError

def swap(self):
Expand Down
38 changes: 37 additions & 1 deletion tests/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -2354,6 +2354,42 @@ def test_buffer_around_silence_invalid(self):
tfm.silence(buffer_around_silence=0)


class TestTransformerSpeed(unittest.TestCase):

def test_default(self):
tfm = new_transformer()
tfm.speed(1.5)

actual_args = tfm.effects
expected_args = ['speed', '1.5']
self.assertEqual(expected_args, actual_args)

actual_log = tfm.effects_log
expected_log = ['speed']
self.assertEqual(expected_log, actual_log)

actual_res = tfm.build(INPUT_FILE, OUTPUT_FILE)
expected_res = True
self.assertEqual(expected_res, actual_res)

def test_factor_valid(self):
tfm = new_transformer()
tfm.speed(0.7)

actual_args = tfm.effects
expected_args = ['speed', '0.7']
self.assertEqual(expected_args, actual_args)

actual_res = tfm.build(INPUT_FILE, OUTPUT_FILE)
expected_res = True
self.assertEqual(expected_res, actual_res)

def test_factor_invalid(self):
tfm = new_transformer()
with self.assertRaises(ValueError):
tfm.speed(-1)


class TestTransformerSwap(unittest.TestCase):

def test_default(self):
Expand Down Expand Up @@ -2396,7 +2432,7 @@ def test_factor_valid(self):
tfm.stretch(0.7)

actual_args = tfm.effects
expected_args = ['stretch', '0.9', '20']
expected_args = ['stretch', '0.7', '20']
self.assertEqual(expected_args, actual_args)

actual_res = tfm.build(INPUT_FILE, OUTPUT_FILE)
Expand Down

0 comments on commit 9b80a80

Please sign in to comment.