Open, read and write Wave files
Project description
PyWave
Open, read and write Wave files
PyWave is a small extension that enables you to open and read the data of any WAVE-RIFF file.
It supports PCM, IEEE-FLOAT, EXTENSIBLE and a few other wave formats (including 32 and 64 bit waves).
It can also create and write wave files, but it's currently limited to PCM-Waves and pure data (no metadata).
Tiny documentation
About PyWave
PyWave is supposed to replace the builtin Python extension
wave, which doesn't support >16-bit wave files.
open(path) to open and read a wave file.
Or you can use
open(path[, mode = 'r', channels = 2, frequency = 48000, bits_per_sample = 16, format = WAVE_FORMAT_PCM])
with <mode> set to
'w' to open and create a writable wave file.
Both will return an instance of the
Wave class.
The following methods are provided by the
Wave class:
Wave.read([max_bytes = None]) -> <bytes> data Reads and returns at most <max_bytes> bytes of data. If <max_bytes> is None, reads until the end. Wave.read_samples(number_of_samples) -> <bytes> data Reads and returns at most <number_of_samples> samples of data. Wave.write(data) -> None Writes <data> to the data chunk of the wave file. Before write can be called, the following members have to be set: - Wave.channels - Wave.frequency - Wave.bits_per_sample This function can only append to the end of the data chunk, thus it is not effected by 'seek()'. Otherwise the format is unknown> [Deprecated] (only exists if <auto_read> was set to True) Audio data as bytes Wave.metadata <dict> A dictionary containing metadata specified in the wave file
Example
import PyWave PATH = "path/to/a/wave/file.wav" wf = PyWave.open(PATH) print("This WAVE file has the following properties:") print(wf.channels, "channels") print(wf.frequency, "Hz sample rate") print(wf.bitrate, "bits per second") print(wf.samples, "total samples") wf_copy = PyWave.open("path/to/a/wave/file_copy.wav", mode = "w", channels = wf.channels, frequency = wf.frequency, bits_per_sample = wf.bits_per_sample, format = wf.format) wf_copy.write(wf.read()) wf.close() wf_copy.close()
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.