save(_many)
Encode float32 (or any int dtype, scaled) audio to WAV, FLAC, MP3, OGG,
MP4/AAC, or Opus. WAV writes through the native PCM writer; compressed
formats go through the encoder libraries. The container comes from the
file extension, and save_many encodes a whole batch in parallel.
save
specux.audio.save(path, y, sr, *, subtype=None, bitrate=None, compression_level=None)y, sr = specux.audio.load("take.wav")specux.audio.save("out.wav", y, sr, subtype="PCM_24")specux.audio.save("out.mp3", y, sr, bitrate=192_000)specux.audio.save("out.flac", y, sr, compression_level=5)subtype(WAV):"PCM_16"(default),"PCM_24","PCM_32", or"FLOAT".bitrate(lossy formats): bits per second; None takes the codec default.y:(channels, frames)or(frames,); integer input scales to [-1, 1) before encoding.
save_many
(path, y, sr) triples, encoded across a worker pool; every save
keyword passes through.
ys = specux.audio.load_many(paths, sr=16000, mono=True)items = [(f"out/{i}.flac", y, 16000) for i, (y, _) in enumerate(ys)]specux.audio.save_many(items)on_error="skip" returns a list with None for successes and the
exception for failures instead of raising on the first bad item.
In-memory forms
blob = specux.audio.save_bytes(y, sr, "ogg") # encode to bytesy2 = specux.audio.codec_roundtrip(y, sr, "mp3") # encode+decode in onecodec_roundtrip is the augmentation helper: hear what the codec does to
a signal, same shape out as in, nothing touches the filesystem. The bytes
from save_bytes decode with load directly.