forked from mrq/DL-Art-School
Audio resample injector
This commit is contained in:
parent
79367f753d
commit
f36bab95dd
|
@ -1,6 +1,7 @@
|
|||
import random
|
||||
|
||||
import torch.nn
|
||||
import torchaudio.functional
|
||||
from kornia.augmentation import RandomResizedCrop
|
||||
from torch.cuda.amp import autocast
|
||||
|
||||
|
@ -569,6 +570,17 @@ class RandomAudioCropInjector(Injector):
|
|||
return {self.output: inp[:, :, start:start+self.crop_sz]}
|
||||
|
||||
|
||||
class AudioResampleInjector(Injector):
|
||||
def __init__(self, opt, env):
|
||||
super().__init__(opt, env)
|
||||
self.input_sr = opt['input_sample_rate']
|
||||
self.output_sr = opt['output_sample_rate']
|
||||
|
||||
def forward(self, state):
|
||||
inp = state[self.input]
|
||||
return {self.output: torchaudio.functional.resample(inp, self.input_sr, self.output_sr)}
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
inj = MelSpectrogramInjector({'in': 'x', 'out': 'y'}, None)
|
||||
print(inj({'x':torch.rand(10,1,40800)})['y'].shape)
|
Loading…
Reference in New Issue
Block a user