Python audio coding classes - for dsp and sonification
Project description
pyA
What is pyA?
pyA is a package to support creation and manipulation of audio signals with Python. It uses numpy arrays to store and compute audio signals.
- Website: --
- Documentation: see examples/pya-examples.ipynb and help(pya)
- Source code: https://github.com/thomas-hermann/pya
It provides:
- Asig - a versatile audio signal class
- Ugen - a subclass of Asig, which offers unit generators such as sine, square, swatooth, noise
- Aserver - an audio server class for queuing and playing Asigs
- Aspec - an audio spectrum class, using rfft as real-valued signals are always implied
- Astft - an audio STFT (short-term Fourier transform) class
pyA can be used for
- multi-channel audio processing
- auditory display and sonification
- sound synthesis experiment
- audio applications in general such as games or GUI-enhancements
- signal analysis and plotting
- at this time more suitable for offline rendering than realtime.
Authors and Contributors
- Thomas Hermann, Ambient Intelligence Group, Faculty of Technology, Bielefeld University (author and maintainer)
- Jiajun Yang, Ambient Intelligence Group, Faculty of Technology, Bielefeld University (co-author)
- Contributors will be acknowledged here, contributions are welcome.
Installation
Disclaimer: We are currently making sure that pyA can be uploaded to PyPI, until then clone the master branch and from inside the pya directory install via pip install -e .
Use pip to install pya via
pip install pya
Besides numpy, scipy and matplotlib, pyA requires pyaudio which in turn requires portaudio. Note that Linux/Windows users should make sure that the corresponding binary packages are installed.
See pyaudio installation http://people.csail.mit.edu/hubert/pyaudio/#downloads
Anaconda can install non-python packages, so that the easiest way (if applicable) would be to
conda install pyaudio
A simple example
Startup:
from pya import *
s = Aserver(bs=1024)
Aserver.default = s # to set as default server
s.boot()
Create an Asig signal:
A 1s / 440 Hz sine tone at sampling rate 44100 as channel name 'left':
import numpy as np
signal_array = np.sin(2 * np.pi * 440 * np.linspace(0, 1, 44100))
atone = Asig(signal_array, sr=44100, label='1s sine tone', cn=['left'])
In addition to passing numpy.ndarray as argument for Asig, it is also for possible to pass int as samples or float as seconds to create an Asig obj with silence audio.
Audio files are also possible using the file path. WAV
should work without issues. MP3
is supported but may raise error under Windows and Linux if FFmpeg is not installed. MacOS should be fine thanks to CoreAudio.
- On Linux
- Install FFmpeg via apt-get:
sudo apt install ffmpeg
- Install FFmpeg via apt-get:
- On Windows
- Download the latest distribution from https://ffmpeg.zeranoe.com/builds/
- Unzip the folder, preferably to
C:\
- Append the FFmpeg binary folder (e.g.
C:\ffmpeg\bin
) to the PATH system variable (How do I set or change the PATH system variable?)
Key attributes
atone.sig
--> The numpy array containing the signal isatone.sr
--> the sampling rateatone.cn
--> the list of custom defined channel namesatone.label
--> a custom set identifier string
Play signals
atone.play(server=s)
play() uses Aserver.default if server is not specified
Plotting signals
to plot the first 1000 samples:
atone[:1000].plot()
to plot the magnitude and phase spectrum:
atone.plot_spectrum()
to plot the spectrum via the Aspec class
atone.to_spec().plot()
to plot the spectrogram via the Astft class
atone.to_stft().plot(ampdb)
Selection of subsets
- Asigs support multi-channel audio (as columns of the signal array)
a1[:100, :3]
would select the first 100 samples and the first 3 channels,a1[{1.2:2}, ['left']]
would select the channel named 'left' using a time slice from 1
Method chaining
Asig methods usually return an Asig, so methods can be chained, e.g
atone[{0:1.5}].fade_in(0.1).fade_out(0.8).gain(db=-6).plot(lw=0.1).play(rate=0.4, onset=1)
Learning more
- Please check the examples/pya-examples.ipynb for more examples and details.
Contributing
- Please get in touch with us if you wish to contribute. We are happy to be involved in the discussion of new features and to receive pull requests.
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
File details
Details for the file pya-0.2rc3.tar.gz
.
File metadata
- Download URL: pya-0.2rc3.tar.gz
- Upload date:
- Size: 1.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.19.1 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c12c1b60eba8d4a583a329d995a397a0034caa2a49f76e623865d957d61d2fe9 |
|
MD5 | 493954d92876d38fab50055bb09133e6 |
|
BLAKE2b-256 | 377766f6b79339fb0494d6a666e27262d39467356d50950820d5061a87468d72 |
File details
Details for the file pya-0.2rc3-py3-none-any.whl
.
File metadata
- Download URL: pya-0.2rc3-py3-none-any.whl
- Upload date:
- Size: 29.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.19.1 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9eebd7d22670004a1bf475f772e615938a661f8e15473782a1497d946dc0b58b |
|
MD5 | 734549ccfd5b8ee9a9b67bbad13547e5 |
|
BLAKE2b-256 | dfdb1c92d4e1706cbc0cda7cdce54409e0d1fdad32626ef83f8763025b1195d0 |