Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion audiotools/core/effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def pitch_shift(self, n_semitones: int, quick: bool = True):
self.audio_data = self._to_3d(waveform)
return self.to(device)

def time_stretch(self, factor: float, quick: bool = True):
def time_stretch(self, factor: float, quick: bool = True, speech: bool = True):
"""Time stretch the audio signal.

Parameters
Expand All @@ -300,6 +300,9 @@ def time_stretch(self, factor: float, quick: bool = True):
if quick:
effects[0].insert(1, "-q")

if speech:
effects[0].insert(1, "-s")

waveform = self._to_2d().cpu()
waveform, sample_rate = torchaudio.sox_effects.apply_effects_tensor(
waveform, self.sample_rate, effects, channels_first=True
Expand Down
7 changes: 7 additions & 0 deletions tests/core/test_effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ def test_time_stretch():

batched = spk_batch.deepcopy().time_stretch(0.8)

#non-default case
single = spk.deepcopy().time_stretch(0.8, speech=False)

spk_batch = AudioSignal.batch([spk.deepcopy() for _ in range(batch_size)])

batched = spk_batch.deepcopy().time_stretch(0.8, speech=False)

assert np.allclose(batched[0].audio_data, single[0].audio_data)


Expand Down