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

Uploaded Source

Built Distribution

sndfileio-1.9.1-py3-none-any.whl (25.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sndfileio-1.9.1.tar.gz
  • Upload date:
  • Size: 22.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.7

File hashes

Hashes for sndfileio-1.9.1.tar.gz
Algorithm Hash digest
SHA256 77292b8cd959bbf7caac8c293192ca437c3832c360839669e40fa685a604d78b
MD5 ec51728b623055c96a96251c9ebaaa0a
BLAKE2b-256 21d96987d81e5d8034af478b54e486b446f61f67656e8565efe77ebaf7baa04b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sndfileio-1.9.1-py3-none-any.whl
  • Upload date:
  • Size: 25.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.7

File hashes

Hashes for sndfileio-1.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 eef8856e0ca026763ba73bdc8a53e28afd13e1e41ce054638f263cd19cc436f0
MD5 fd187b862fcbccde5f3d9ae1ecab1604
BLAKE2b-256 0781e8d9d72c8daa87b388cc0ee3fed3318b0aa250b3cfe2d419536789a49c0d

See more details on using hashes here.

Supported by

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