Exemplo n.º 1
0
def save(filepath, src, sample_rate, precision=16, channels_first=True):
    r"""See torchaudio.save"""

    si = torchaudio.sox_signalinfo_t()
    ch_idx = 0 if channels_first else 1
    si.rate = sample_rate
    si.channels = 1 if src.dim() == 1 else src.size(ch_idx)
    si.length = src.numel()
    si.precision = precision
    return torchaudio.save_encinfo(filepath, src, channels_first, si)
Exemplo n.º 2
0
 def test_ulaw_and_siginfo(self):
     si_out = torchaudio.sox_signalinfo_t()
     ei_out = torchaudio.sox_encodinginfo_t()
     si_out.precision = 8
     ei_out.encoding = torchaudio.get_sox_encoding_t(9)
     ei_out.bits_per_sample = 8
     si_in, ei_in = torchaudio.info(self.test_filepath)
     si_out.rate = 44100
     si_out.channels = 2
     E = torchaudio.sox_effects.SoxEffectsChain(out_siginfo=si_out, out_encinfo=ei_out)
     E.set_input_file(self.test_filepath)
     x, sr = E.sox_build_flow_effects()
     # Note: the output was encoded into ulaw because the
     #       number of unique values in the output is less than 256.
     self.assertLess(x.unique().size(0), 2**8 + 1)
     self.assertEqual(x.numel(), si_in.length)