Re:Lyra V2 – a better, faster, and more versatile speech codec
by muziq on Wednesday October 05, 2022 @05:07PM
(#33101255)
You’ve not done this before have you ?
[ Parent
| on HN ]
Re:Lyra V2 – a better, faster, and more versatile speech codec
by orlp on Thursday October 13, 2022 @10:15AM
(#33191258)
I haven't, but now I have. I took https://opus-codec.org/static/examples/samples/music_orig.wa... from https://opus-codec.org/examples/. Then I wrote the following snippet of Python code:
from scipy.io import wavfile
import numpy as np
import zstd
sampling_rate, samples = wavfile.read(r'data/bootleg-compress/music_orig.wav')
orig = samples.tobytes()
naive_compressed = zstd.ZSTD_compress(orig)
deltas = np.diff(samples, prepend=samples.dtype.type(0), axis=0) # Per-channel deltas.
compressed_deltas = zstd.ZSTD_compress(deltas.ravel()) # Interleave channels and compress.
decompressed_deltas = np.frombuffer(zstd.ZSTD_uncompress(compressed_deltas), dtype=samples.dtype)
decompressed = np.cumsum(decompressed_deltas.reshape(deltas.shape), axis=0, dtype=samples.dtype)
assert np.array_equal(samples, decompressed)
print(len(orig))
print(len(naive_compressed))
print(len(compressed_deltas))
giving: 17432876
15518973
12817602
Looks like my initial estimation of 2-4 was way off (when FLAC achieves ~2 this should've been a red flag), but you do get a ~1.36x reduction in space at basically memory read speed.