Skip to main content

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

Documentation

https://sndfileio.readthedocs.io/en/latest/


API

sndread

  • 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

sndread_chunked

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

sndinfo

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

sndwrite

  • writes the samples.

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

sndwrite_chunked

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

resample

Resample a numpy array to a new samplerate

Examples

# 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
        writer.write(buf)

Installation

pip install sndfileio

External dependencies

  • libsndfile (Debian/Ubuntu: apt install libsndfile1-dev)

License

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

Download files

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

Source Distribution

sndfileio-2.1.0.tar.gz (1.9 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sndfileio-2.1.0-py3-none-any.whl (744.6 kB view details)

Uploaded Python 3

File details

Details for the file sndfileio-2.1.0.tar.gz.

File metadata

  • Download URL: sndfileio-2.1.0.tar.gz
  • Upload date:
  • Size: 1.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.2

File hashes

Hashes for sndfileio-2.1.0.tar.gz
Algorithm Hash digest
SHA256 148e7db224931a6ca3e1a76876ef5bc9f9e290ca3cefcc9ec13a3cd891671a55
MD5 6ddc675a880edbbf6f9376730de92dff
BLAKE2b-256 68b5e81c58a695fd47edf0d79dc4a990b6301a09955ab8b0dde93fa3def5f98d

See more details on using hashes here.

File details

Details for the file sndfileio-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: sndfileio-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 744.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.2

File hashes

Hashes for sndfileio-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e44d8689e4d66b6e882b0f05f01897ca6bb80029d5004eb2a19469968629f272
MD5 58995e57d5ad8071e0e5e0444f8f3556
BLAKE2b-256 9a6d6acfc6b48a07b08c78975d1433e0aadc7878a5152292789a5412455ddaa8

See more details on using hashes here.

Release history Release notifications | RSS feed

2.1.2

2 files

2.1.1

2 files

This release

2.1.0 This release

2 files

2.0.0

1 file

1.9.4

1 file

1.9.3

1 file

1.9.2

1 file

1.9.1

2 files

1.9.0

2 files

1.8.2

1 file

1.8.1

1 file

1.8.0

1 file

1.7.1

1 file

1.7.0

1 file

1.6.0

1 file

1.5.1

1 file

1.4.0

1 file

1.3.2

1 file

1.3.1

1 file

1.3.0

1 file

1.2.0

1 file

1.0.0

1 file

0.9.2

1 file

0.9.0

1 file

0.8.1

1 file

0.7.1

2 files

0.7

2 files

0.6

0.3.1

2 files

0.3

2 files

0.2

2 files

0.1

2 files

0.4-

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page