https://github.com/spotlightkid/pydrlibs
Python bindings for the dr_libs audio decoding libraries
https://github.com/spotlightkid/pydrlibs
audio cython dr-libs python wav
Last synced: 10 months ago
JSON representation
Python bindings for the dr_libs audio decoding libraries
- Host: GitHub
- URL: https://github.com/spotlightkid/pydrlibs
- Owner: SpotlightKid
- License: mit
- Created: 2021-01-25T06:36:31.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-02-15T01:07:36.000Z (almost 5 years ago)
- Last Synced: 2025-01-25T12:41:50.812Z (12 months ago)
- Topics: audio, cython, dr-libs, python, wav
- Language: Python
- Homepage:
- Size: 122 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pydrlibs
Python bindings for the [dr_libs] audio file decoding libraries
**Note:** *This project is in very early stages of development and probably
not very useful yet and may even simply not work.*
## Installation
Make sure you have installed the requirements listed below.
```console
$ git clone https://github.com/SpotlightKid/pydrlibs
$ cd pydrlibs
$ git submodule update --init
$ python setup.py install --user # or: sudo python setup.py install
```
## Usage examples:
### Reading a WAV file
```python
from dr_libs import dr_wav
wav = dr_wav.DrWav('/path/to/audio.wav')
print(wav.sample_rate)
print(wav.channels)
print(wav.bits_per_sample)
print(wav.nframes)
# Read sample data as single-precision floats.
# Returns array.array('f') instance.
# Channels are interleaved.
data = wav.read(fmt=dr_wav.sample_format.F32)
print(len(data)) # Should return (wav.nframes * wav.channels)
```
### Writing a WAV file
```python
import array
from random import randrange
from dr_libs import dr_wav
wav = dr_wav.DrWav(
'sine.wav',
mode='w',
channels=1,
sample_rate=48000,
bits_per_sample=16,
format_tag=dr_wav.PCM)
# The default sample rate is 44100 Hz.
# For channels, bits_per_sample and format_tag the values used above are the defaults.
with wav:
# Generate 1 second of full-scale white noise at 48 kHz.
data = array.array('h', (randrange(-32768, 32768) for i in range(48000)))
# write to file
wav.write(data)
# Exiting the context calls wav.close() implicitly.
```
## Requirements
To get the source code:
* Git
For building:
* [Python] 3.6+
* [setuptools]
* [Cython]
At run-time:
* [Python] 3.6+
For running the unit tests:
* [pytest] >= 3.0
## Unit tests
To run the unit tests against the source directory, either:
* Create a Python virtual environment and activate it.
* Install the package into the virtualenv with `pip install -e .`.
* Install `pytest` into the virtualenv with `pip install pytest`.
* Run `pytest`.
or, without a virtualenv, install `pytest` globally or for your user and then
simply run `make test`. This will:
* Build the extension module "in-place", i.e. will put it in the `dr_libs`
package directory.
* Run `python -m pytest -v tests/`, which adds the current working dir to the
Python module search, so the tests will find the `dr_libs` package.
## License
This software is released under the [MIT License](./LICENSE).
## Authors
This software was written by *Christopher Arndt*.
[cython]: https://cython.org/
[dr_libs]: https://github.com/mackron/dr_libs
[pytest]: https://pypi.org/project/pytest/
[python]: https://www.python.org/downloads/
[setuptools]: https://pypi.org/project/setuptools/