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.

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).

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-2.1.2.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.2-py3-none-any.whl (744.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sndfileio-2.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 659c5ab4ce094375bfddb51a7aef82de480c8356fe7ab02349de6e0ceade9ac6
MD5 e3704f31e0fccc79859ee4d90c20a5c8
BLAKE2b-256 addfde22355942ac1b2e20bf5e520e33465b48d4b425d9b28497b00cb9da1c88

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for sndfileio-2.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 58f5a4fad5d4c0e4c99a64ff2bbdedb9081a2060fc6b1d51fcf2d6461d36f415
MD5 a39eaef94d7be0786f337c32274eb9ce
BLAKE2b-256 0425885edfa8881bfd67373639b3b543b2d6502643f6602a43992e35d7e8d679

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page