(self, x)
| 235 | |
| 236 | @torch.jit.export |
| 237 | def encode(self, x): |
| 238 | if self.stereo_mode: |
| 239 | if self.n_channels == 1: |
| 240 | x = x[:, 0].unsqueeze(0) |
| 241 | elif self.n_channels > 2: |
| 242 | raise RuntimeError("stereo mode is not available when n_channels > 2") |
| 243 | |
| 244 | if self.is_using_adain: |
| 245 | self.update_adain() |
| 246 | |
| 247 | if self.resampler is not None: |
| 248 | x = self.resampler.to_model_sampling_rate(x) |
| 249 | |
| 250 | batch_size = x.shape[:-2] |
| 251 | if self.input_mode == "pqmf": |
| 252 | x = x.reshape(-1, 1, x.shape[-1]) |
| 253 | x = self.pqmf(x) |
| 254 | x = x.reshape(batch_size + (-1, x.shape[-1])) |
| 255 | elif self.input_mode == "mel": |
| 256 | if self.spectrogram is not None: |
| 257 | x = self.spectrogram(x)[..., :-1] |
| 258 | x = torch.log1p(x).reshape(batch_size + (-1, x.shape[-1])) |
| 259 | else: |
| 260 | raise RuntimeError() |
| 261 | z = self.encoder(x) |
| 262 | z = self.post_process_latent(z) |
| 263 | return z |
| 264 | |
| 265 | @torch.jit.export |
| 266 |
no test coverage detected