Read/write wave audio files to/from lists of native Python types.
Project description
wavfile
A lightweight library to read/write wave audio files to/from lists of native Python types.
The library is currently limited to PCM (integer) formats but supports arbitrary precision, including 16-, 24-, 32-, and 64-bit samples.
Usage: reading wave files
f = wavfile.open(file, 'r')
where file is either a path to a wave file or a pointer to an
open file. This returns a wavfile.wavread.WavRead object with
the following properties:
num_channels- The number of audio channels in the stream.sample_rate- The sampling rate/frequency of the audio stream.bits_per_sample- The number of bits per audio sample.num_frames- The total number of audio frames in the audio stream. A frame is a block of samples, one for each channel, corresponding to a single sampling point.
The object also has the following methods:
read_int([N])- Read, at most,Nframes from the audio stream in their unmodified integer format. The method returns a list of lists with size(N,C), whereCis the number of audio channels. ExcludingN, choosingN = NoneorN < 0will read all remaining samples.read_float([N])- This method is identical toread_int()except that it returns the samples as floats in the range [-1, 1).iter_int([N])- Similar toread_int()but used in iterator contexts to read successive groups of audio frames.iter_float([N])- Similar toread_float()but used in iterator contexts to read successive groups of audio frames.seek(N [, whence])- Move to theNth frame in the audio stream;whencesets the positioning: 0 (default) = absolute positioning, 1 = relative to current position, 2 = relative to end of last frame.tell()- Return the current frame in the audio stream.close()- Close the instance.
Alternatively, the following shortcut function is provided:
audio, sample_rate, bits_per_sample = wavfile.read(file, fmt='int')
where fmt is 'int' or 'float', and audio is the audio data. The
function reads all audio data in the file.
Usage: writing wave files
f = wavfile.open(file, 'w',
sample_rate=44100,
num_channels=None,
bits_per_sample=16)
where sample_rate is the sampling rate for the new file,
num_channels is the number of audio channels, and
bits_per_sample is the number of bits used to encode each
sample. If num_channels is unspecified it will be determined
automatically from the first block of samples that are written
(see below). This returns a wavfile.wavwrite.WavWrite object.
The object shares its properties with the
wavfile.wavread.WavRead class. The object also offers the same
seek(), tell(), and close() methods. In addition, the
following methods are provided for writing audio data:
write(audio)- Write frames of audio data to the audio file. The data should be contained in a list of lists with size(N,C), whereNis the number of frames andCis the number of audio channels. If the data are floats then they should be in the range [-1, 1). They will be converted automatically. Integers will be written directly.
Alternatively, the following shortcut function is provided:
wavfile.write(file, audio, sample_rate=44100, bits_per_sample=16)
where audio is the audio data to write to the file.
Installation
From source:
python -m pip install -e --user .
From PyPI:
python -m pip install --user wavfile
License
wavfile is available under the MIT license. See LICENSE.txt for
more information.
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 Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wavfile-2.0.0.tar.gz.
File metadata
- Download URL: wavfile-2.0.0.tar.gz
- Upload date:
- Size: 2.1 MB
- 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.3 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a3e00c37ea3f5aadce8830455ca32bcdcd8b48cacffdf3d2ee42e5142ff34f23
|
|
| MD5 |
3c62a0b37bea8816f4d3996890228714
|
|
| BLAKE2b-256 |
5e1cb991c024b56af2277f3b4f476263f4b14f23fead628bd3da9020c5695afb
|
File details
Details for the file wavfile-2.0.0-py3-none-any.whl.
File metadata
- Download URL: wavfile-2.0.0-py3-none-any.whl
- Upload date:
- Size: 12.4 kB
- Tags: Python 3
- 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.3 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ffb0a2afc466afc29434e44b381fc8d298cc69ce01a97dd6b2ca4956c91dd6ba
|
|
| MD5 |
a82dc6aff67c81fe27676f0651f21fee
|
|
| BLAKE2b-256 |
54b5af53b8929ec0e17371d946f861d0f9e0735039ce278a5b7e353e7eefab48
|