Wraps NeMo's AudioToMelSpectrogramPreprocessor for single-sample export. Input: 1D audio waveform (N,) and length (1,) int64. Output: mel spectrogram (1, 128, T_mel) and mel_len (1,) int64.
| 25 | |
| 26 | |
| 27 | class PreprocessorWrapper(torch.nn.Module): |
| 28 | """Wraps NeMo's AudioToMelSpectrogramPreprocessor for single-sample export. |
| 29 | |
| 30 | Input: 1D audio waveform (N,) and length (1,) int64. |
| 31 | Output: mel spectrogram (1, 128, T_mel) and mel_len (1,) int64. |
| 32 | """ |
| 33 | |
| 34 | def __init__(self, preprocessor): |
| 35 | super().__init__() |
| 36 | self.preprocessor = preprocessor |
| 37 | |
| 38 | def forward( |
| 39 | self, audio: torch.Tensor, length: torch.Tensor |
| 40 | ) -> tuple[torch.Tensor, torch.Tensor]: |
| 41 | audio_signal = audio.unsqueeze(0) |
| 42 | mel, mel_len = self.preprocessor(input_signal=audio_signal, length=length) |
| 43 | return mel, mel_len |
| 44 | |
| 45 | |
| 46 | class PreEncodeWrapper(torch.nn.Module): |