Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -242,22 +242,22 @@ In the following example OGG is converted to WAV entirely in memory (without wri

Controlling bitrate mode and compression level
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
For some audio formats, you can control the bitrate and compression level.
For some audio formats, you can control the bitrate and compression level.

`compression_level` is a float between 0 and 1, with 1 being the highest compression,
`compression_level` is a float between 0 and 1, with 1 being the highest compression,
and `bitrate_mode` is 'VARIABLE', 'CONSTANT', or 'AVERAGE'.

.. code:: python

import soundfile as sf

# for example, this uncompressed 5 minute wav file with 32 kHz sample rate is 18 Mb
data, samplerate = sf.read('5min_32kHz.wav')
data, samplerate = sf.read('5min_32kHz.wav')

# maximum mp3 compression results in 1.1 Mb file, with either CONSTANT or VARIABLE bit rate
sf.write('max_compression_vbr.mp3', data, samplerate, bitrate_mode='VARIABLE', compression_level=.99)
sf.write('max_compression_vbr.mp3', data, samplerate, bitrate_mode='VARIABLE', compression_level=.99)
sf.write('max_compression_cbr.mp3', data, samplerate, bitrate_mode='CONSTANT', compression_level=.99)

# minimum mp3 compression results in 3.5 Mb file
sf.write('min_compression_vbr.mp3', data, samplerate, bitrate_mode='VARIABLE', compression_level=0)

Expand Down Expand Up @@ -407,4 +407,14 @@ News
2025-01-25 V0.13.1 Bastian Bechtold
Thank you, Brian McFee and Guy Illes

- Fixed regression in blocks
- Fixed regression in blocks

2026-06-06 V0.14.0 Bastian Bechtold
Thank you GesonAnko, Trevor Gamblin, Andreas Karatzas, Harish RS, Hunter Hogan

- Added type annotations
- Added Licensing note to wheel
- Fixed race condition when opening files concurrently
- Fixed regressions in test suite
- Removed support for Python <= 3.9
- Added ARM64 support for Windows
15 changes: 7 additions & 8 deletions soundfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
For further information, see https://python-soundfile.readthedocs.io/.

"""
__version__ = "0.13.1"
__version__ = "0.14.0"

import os as _os
import sys as _sys
Expand Down Expand Up @@ -164,18 +164,17 @@
from platform import machine as _machine
_packaged_libname = 'libsndfile_' + _machine() + '.dylib'
elif _sys.platform == 'win32':
from platform import architecture as _architecture
from platform import machine as _machine
import sysconfig as _sysconfig

_win_machine = _machine().lower()
if _win_machine in ('arm64', 'aarch64'):
_win_machine = _sysconfig.get_platform()
if _win_machine == 'win-arm64':
_packaged_libname = 'libsndfile_arm64.dll'
elif _architecture()[0] == '64bit':
elif _win_machine == 'win-amd64':
_packaged_libname = 'libsndfile_x64.dll'
elif _architecture()[0] == '32bit':
elif _win_machine == 'win32':
_packaged_libname = 'libsndfile_x86.dll'
else:
raise OSError(f'no packaged library for Windows {_architecture()} {_machine()}')
raise OSError(f'no packaged library for Windows {_win_machine}')
elif _sys.platform == 'linux':
from platform import machine as _machine
if _machine() in ["aarch64", "aarch64_be", "armv8b", "armv8l"]:
Expand Down
Loading