Skip to main content

Open and read Wave files

Project description

PyWave

Open and read 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 bit waves).

Tiny documentation

About PyWave

PyWave is supposed to replace the builtin Python extension wave, which doesn't support 32-bit wave.

Using PyWave

To install PyWave you can use the PyPI:

pip install PyWave

To use PyWave in a script, you have to import the package PyWave using

import PyWave

or a wildcard import:

from PyWave import *

The Wave class

You can use the Wave class to open and read a wave file:

Wave(path[, auto_read = False])
    path       - File path to a wave file
    auto_read  - (optional) Can be set to True to read the data automatically

If auto_read is enabled, the data will be stored in Wave.data

The following methods are provided by the Wave class:

Wave.read([max_bytes = 4096]) -> <bytes> data
    Reads and returns at most <max_bytes> bytes of data.

Wave.read_samples(number_of_samples) -> <bytes> data
    Reads and returns at most <number_of_samples> samples of data.

Wave.seek(offset[, whence = 0]) -> None
    Sets the current position in the data stream.
    If <whence> is 0, <offset> is the absolute position of the
    data stream in bytes.
    If <whence> is 1, <offset> is added to the current position
    in the data stream in bytes.
    If <whence> is 2, the position will be set to the end of
    the file plus <offset>.

Wave.tell() -> <int> position
    Returns the current position in the data stream.

Wave.close() -> None
    Closes the file handle.

And it has the following members:

Wave.format <int>
    Format of the audio data. Can be any of:
    - WAVE_FORMAT_PCM
    - WAVE_FORMAT_IEEE_FLOAT
    - WAVE_FORMAT_ALAW
    - WAVE_FORMAT_MULAW
    - WAVE_FORMAT_EXTENSIBLE

Wave.channels <int>
    The number of audio channels present in the audio stream

Wave.frequency <int>
    Sample rate of the audio stream

Wave.bitrate <int>
    Number of bits per second

Wave.bits_per_sample <int>
    Number of bits per sample (usually 8, 16 or 32)

Wave.samples <int>
    Total number of samples in the audio data

Wave.data <bytes>
    (only if <auto_read> was set to True)
    Audio data as bytes

Example

from PyWave import *

PATH = "path/to/a/wave/file.wav"

wf = Wave(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")

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

PyWave-0.2.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

PyWave-0.2.0-py2.py3-none-any.whl (5.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file PyWave-0.2.0.tar.gz.

File metadata

  • Download URL: PyWave-0.2.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for PyWave-0.2.0.tar.gz
Algorithm Hash digest
SHA256 60f173426d3b4066b6e41dada14023e724b3ab927cafc583e02eadc6a64263a6
MD5 ceccc2fe2757571d148d91f900e8e325
BLAKE2b-256 e1c631a4b68c2022781925263858f2acdd63ecf486a438721cac59468baf58d5

See more details on using hashes here.

File details

Details for the file PyWave-0.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: PyWave-0.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for PyWave-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 53d0f3b284ea330b88ae7a3d55c39315f580800e25fbfd32580ab00695a47efd
MD5 f561441d0f49a90bdb3039e5d760c9bf
BLAKE2b-256 8b0919dd13dde33b362210f7e839c990f9402edc92b91c626c93d2c4ed5870c2

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