Skip to main content

Simple API for reading / writing soundfiles

Project description

This package provides a simple and unified API to read and write sound-files to and from numpy arrays.




  • reads all the samples (or a fragment) from a soundfile and returns a tuplet (data, samplerate)

  • Data will always be as a numpy.float64, between -1 and 1, independently of bit-rate


  • reads chunks of frames, avoiding the allocation of all the samples in memory


  • returns SndInfo, a namedtuple with all the information of the sound-file


  • writes the samples.

  • samples need to be a numpy.float64 array with data between -1 and 1


  • allows you to write to the file as samples become available


Resample a numpy array to a new samplerate


# Normalize and save as flac
from sndfileio import sndread, sndwrite
samples, sr = sndread("in.wav")
maxvalue = max(samples.max(), -samples.min())
samples *= 1/maxvalue
sndwrite(samples, sr, "out.flac")
# Process a file in chunks
from sndfileio import *
from sndfileio.dsp import
with sndwrite_chunked(44100, "out.flac") as writer:
    for buf in sndread_chunked("in.flac"):
        # do some processing, like changing the gain
        buf *= 0.5


Make sure that you have libsamplerate installed.

pip install sndfileio


  • libsamplerate (apt install libsndfile1-dev)

All python dependencies are installed by pip


See the LICENSE file for license rights and limitations (MIT).

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sndfileio-1.4.0.tar.gz (19.3 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page