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
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file sndfileio-2.0.0-py3-none-any.whl
.
File metadata
- Download URL: sndfileio-2.0.0-py3-none-any.whl
- Upload date:
- Size: 744.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 445f06157a0da347a35b7984e01adfb175187b791a9e97b38d714b054864a8e4 |
|
MD5 | 3ffede9531612df849429ad145230457 |
|
BLAKE2b-256 | 38a33615994198696d12870c5e48ca67ef76133cd87a5f9dc597dd8cfdd6653f |