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 (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-1.7.1.tar.gz (21.7 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: sndfileio-1.7.1.tar.gz
  • Upload date:
  • Size: 21.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.5

File hashes

Hashes for sndfileio-1.7.1.tar.gz
Algorithm Hash digest
SHA256 6f14cfde755669a1fd4a6ff184af5d66e8971fba5359516fc94af2ffbcd95a07
MD5 e2530388989f326ce20bbc45497a2e5a
BLAKE2b-256 c680da96488120fc127616c81c5456040fff60831c34fe8b06ee07fff5a88b47

See more details on using hashes here.

Supported by

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