Expand description
pydub’s AudioSegment, transcribed operation by operation.
The pipeline’s DAW layers are only byte-identical to Python’s if every quirk of pydub 0.25.1 survives, and several are load-bearing:
AudioSegment.silent()is 11025 Hz mono. Overlaying a 44.1 kHz stereo stem onto it converts the whole layer throughratecv, which changes its frame count.AudioSegment.empty()is width 1, rate 1, mono; the first+=syncs it up to the appended stem.- Slicing is by milliseconds through
int(ms * rate / 1000.0), soseg[a:]can drop or pad a few trailing frames.overlayis built from two such slices, so it can change a buffer’s length. - Negative positions count from the end, and byte slices use Python’s clamping rules — a fade longer than its clip reaches both.
Buffers are raw little-endian bytes, as pydub keeps them, so the same arithmetic applies whatever the sample width.
Modules§
- libm
- The C library’s
pow,logandlog10, called at run time.
Structs§
- Segment
- An immutable-in-spirit block of interleaved PCM. Methods consume and
return segments the way pydub’s
_spawnhands back new objects.
Functions§
- db_
to_ float - pydub’s
db_to_floatin amplitude mode:10 ** (db / 20). - floor_
div 🔒 - Python’s
//on ints: rounds toward negative infinity. - io_err 🔒
- py_
array_ 🔒int int(x)stored into anarray('h'): truncates toward zero; a value outside the type would raiseOverflowErrorin Python.- py_
round - Python’s
round()of a float to an int: ties go to even. - py_
slice 🔒 - Python byte slicing
data[a:b]: negative indexes count from the end, both ends clamp, and an inverted range is empty. - ratio_
to_ db - pydub’s
ratio_to_dbin amplitude mode:20 * log(ratio, 10), which CPython evaluates aslog(ratio) / log(10)— notlog10(ratio).20 * log(2, 10)is6.020599913279623;20 * log10(2)is...624. - read_
wav - pydub’s
read_wav_audio(withextract_wav_headers): scan at most ten sub-chunks up todata, honour its declared size, reject non-PCM.