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

Metadata

Release files for sndfileio 2.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sndfileio 2.1.2
File Size Uploaded
sndfileio-2.1.2.tar.gz 1.9 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for sndfileio 2.1.2
File Interpreter ABI Platform
sndfileio-2.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 2.7 MB

Release files / sndfileio-2.1.2.tar.gz

Download URL sndfileio-2.1.2.tar.gz
Size 1.9 MB
Tags Source
SHA-256 checksum
How to use checksums
659c5ab4ce094375bfddb51a7aef82de480c8356fe7ab02349de6e0ceade9ac6
BLAKE2b-256 checksum
How to use checksums
addfde22355942ac1b2e20bf5e520e33465b48d4b425d9b28497b00cb9da1c88
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.2

Release files / sndfileio-2.1.2-py3-none-any.whl

Download URL sndfileio-2.1.2-py3-none-any.whl
Size 744.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
58f5a4fad5d4c0e4c99a64ff2bbdedb9081a2060fc6b1d51fcf2d6461d36f415
BLAKE2b-256 checksum
How to use checksums
0425885edfa8881bfd67373639b3b543b2d6502643f6602a43992e35d7e8d679
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.2

Release history Release notifications | RSS feed

This release

2.1.2 This release

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.0

1 release file

1.9.4

1 release file

1.9.3

1 release file

1.9.2

1 release file

1.9.1

2 release files

1.9.0

2 release files

1.8.2

1 release file

1.8.1

1 release file

1.8.0

1 release file

1.7.1

1 release file

1.7.0

1 release file

1.6.0

1 release file

1.5.1

1 release file

1.4.0

1 release file

1.3.2

1 release file

1.3.1

1 release file

1.3.0

1 release file

1.2.0

1 release file

1.0.0

1 release file

0.9.2

1 release file

0.9.0

1 release file

0.8.1

1 release file

0.7.1

2 release files

0.7

2 release files

0.6

0.3.1

2 release files

0.3

2 release files

0.2

2 release files

0.1

2 release files

0.4-

1 release 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