def main(): parser = get_parser() args = parser.parse_args() logfmt = "%(asctime)s (%(module)s:%(lineno)d) %(levelname)s: %(message)s" if args.verbose > 0: logging.basicConfig(level=logging.INFO, format=logfmt) else: logging.basicConfig(level=logging.WARN, format=logfmt) logging.info(get_commandline_args()) with kaldiio.ReadHelper(args.rspecifier, segments=args.segments) as reader, \ file_writer_helper(args.wspecifier, filetype=args.filetype, write_num_frames=args.write_num_frames, compress=args.compress, compression_method=args.compression_method ) as writer: for utt_id, (_, array) in reader: array = array.astype(numpy.float32) if args.normalize is not None and args.normalize != 1: array = array / (1 << (args.normalize - 1)) spc = spectrogram(x=array, n_fft=args.n_fft, n_shift=args.n_shift, win_length=args.win_length, window=args.window) writer[utt_id] = spc
def test_compatible_with_espnet1(): layer = LogSpectrogram(n_fft=16, hop_length=4) x = torch.randn(1, 100) y, _ = layer(x, torch.LongTensor([100])) y = y.numpy()[0] y2 = np.log10(spectrogram(x[0].numpy(), n_fft=16, n_shift=4)) np.testing.assert_allclose(y, y2, rtol=0, atol=1e-4)