You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was looking at using ResizeSignal to cut an input and output down to the same chunk of audio and realized that's not currently an easy thing to do. I was thinking that adding an option that would allow for crop_start to be set during initialization would be helpful. I haven't written anything yet, but wanted to see if that's something that would be helpful for anybody else.
Code in question:
class ResizeSignal(Transform):
"""Crops signal to be length specified in ms by duration, padding if needed"""
def __init__(self, duration, pad_mode=AudioPadType.Zeros):
self.duration = duration
self.pad_mode = pad_mode
if pad_mode not in [
AudioPadType.Zeros,
AudioPadType.Zeros_After,
AudioPadType.Repeat,
]:
raise ValueError(
f"""pad_mode {pad_mode} not currently supported,
only AudioPadType.Zeros, AudioPadType.Zeros_After,
or AudioPadType.Repeat"""
)
def encodes(self, ai: AudioTensor) -> AudioTensor:
sig = ai.data
orig_samples = ai.nsamples
crop_samples = int((self.duration / 1000) * ai.sr)
if orig_samples == crop_samples:
return ai
elif orig_samples < crop_samples:
ai.data = _tfm_pad_signal(sig, crop_samples, pad_mode=self.pad_mode)
else:
crop_start = random.randint(0, int(orig_samples - crop_samples)) ########################Always Random at the moment
ai.data = sig[:, crop_start : crop_start + crop_samples]
return ai
The other thing I though is that you could potentially set a random.seed but I wasn't able to make that solution to work in my code.
The text was updated successfully, but these errors were encountered:
I was looking at using ResizeSignal to cut an input and output down to the same chunk of audio and realized that's not currently an easy thing to do. I was thinking that adding an option that would allow for crop_start to be set during initialization would be helpful. I haven't written anything yet, but wanted to see if that's something that would be helpful for anybody else.
Code in question:
The other thing I though is that you could potentially set a random.seed but I wasn't able to make that solution to work in my code.
The text was updated successfully, but these errors were encountered: