Ejemplo n.º 1
0
    def forward(self, x: Tensor) -> Tensor:
        r"""
        Args:
            x (Tensor): A signal to be encoded.

        Returns:
            x_mu (Tensor): An encoded signal.
        """
        return F.mu_law_encoding(x, self.quantization_channels)
Ejemplo n.º 2
0
    def test_torchscript_mu_law_encoding(self):
        @torch.jit.script
        def jit_method(tensor, qc):
            # type: (Tensor, int) -> Tensor
            return F.mu_law_encoding(tensor, qc)

        tensor = torch.rand((10, 1))
        qc = 256

        jit_out = jit_method(tensor, qc)
        py_out = F.mu_law_encoding(tensor, qc)

        self.assertTrue(torch.allclose(jit_out, py_out))
 def func(tensor):
     qc = 256
     return F.mu_law_encoding(tensor, qc)
Ejemplo n.º 4
0
 def jit_method(tensor, qc):
     # type: (Tensor, int) -> Tensor
     return F.mu_law_encoding(tensor, qc)
Ejemplo n.º 5
0
#Mu-Law decoding

reconstructed = torchaudio.transforms.MuLawDecoding()(transformed)

print(f"Shape of recovered waveform: {reconstructed.size()}")

plt.figure()
plt.plot(reconstructed[0,:].numpy())

err = ((waveform-reconstructed).abs() / waveform.abs()).median()
print(f"Median relative difference between original and MuLaw reconstructed signals: {err:.2%}")
# %%

#Using torchaudio.functional

mu_law_encoding_waveform = F.mu_law_encoding(waveform, quantization_channels=256)

print(f"Shape of transformed waveform: {mu_law_encoding_waveform.size()}")

plt.figure()
plt.plot(mu_law_encoding_waveform[0,:].numpy())
# %%

#Functional spectrogram deltas

specgram = torchaudio.transforms.Spectrogram()(waveform)
computed = torchaudio.functional.compute_deltas(specgram.contiguous(), win_length=3)
print(f"Shape of computed deltas: {computed.shape}")

plt.figure()