GIL-less Portaudio Streams for Python
Project description
pastream - GIL-less Portaudio Streams for Python
pastream builds on top of portaudio and the excellent sounddevice python bindings to provide some more advanced functionality right out of the box. Note that in addition to the pastream library, pastream includes a command line application for playing and recording audio files.
Features
- GIL-less Audio Callbacks
Having the portaudio callback implemented in C means audio interrupts can be serviced quickly and reliably without ever needing to acquire the Python Global Interpreter Lock (GIL). This is crucial when working with libraries like Pillow which may greedily grab and hold the GIL subsequently causing audio overruns/underruns.
- Input Stream iterators
Efficiently retrieve live audio capture data through an iterable. As simple as:
import pastream as ps for chunk in ps.chunks(): # do stuff with chunked audio
See pastream.chunks and pastream.*Stream.chunks method.
- Reader/Writer Threads
pastream simplifies the process of implementing stream reader and writer threads to manipulate and/or generate data in the background while leaving the main thread free for higher level management tasks.
Dependencies
sounddevice (depends on PortAudio)
soundfile (depends on libsndfile)
(Optional) numpy
Installation
For linux platforms a recent version of the PortAudio and libsndfile C libraries are required. (For Windows and OSX, the sounddevice and soundfile packages include prebuilt versions for you). You can either install the latest available from your package manager (e.g. apt-get install libportaudio2 libsndfile for debian/raspbian) or install the latest stable build from the package website (Recommended); see links in Dependencies.
pastream is now available on PyPI. Installation is as easy as:
$ pip install pastream
Building From Source
To compile from source under unix platforms, libffi is required. (For Windows, this is already included with cffi). libffi is available through most package managers (e.g., yum install libffi-devel, apt-get install libffi-dev, brew install libffi). More information on installing libffi is available here.
If doing a fresh checkout:
$ git clone --recursive http://github.com/tgarc/pastream
If you already have a checkout:
$ git submodule update --init
Then do a pip install from your working copy:
$ pip install <path/to/checkout>
Examples
Record to file:
import pastream as ps
with ps.SoundFileInputStream('recording.wav', device='my-device') as stream:
stream.start()
stream.wait()
Grab (real) frequency transformed live audio stream with 50% overlap:
import pastream as ps, numpy as np
chunksize = 1024
window = np.hanning(chunksize)
for l, x_l in enumerate(ps.chunks(chunksize, overlap=chunksize//2, channels=1)):
X_l = np.fft.rfft(x_l * window)
See also the included examples under pastream/examples.
Command Line Application
Once installed, the pastream application should be callable from your command line. If you’re familiar with sox you’ll notice that some of the command line syntax is quite similar. Here are a few examples to help get you started.
Display the help file:
$ pastream -h
List available audio devices:
$ pastream -l
Simultaneous play and record from the default audio device:
$ pastream input.wav output.wav
Pipe input from sox using the AU format:
$ sox -n -t au - synth sine 440 | pastream - output.wav
Play a RAW file:
$ pastream -c1 -r48k -e=pcm_16 -o output.raw
Record 10 seconds of audio at 48kHz:
$ pastream null output.wav -r48k -n=480k
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 Distributions
Hashes for pastream-0.0.7-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e8daca7cb744b0a1476fe94e4e07d6ada098f94a66292b4204c9764c79c42e1 |
|
MD5 | 1c15f0df528ad608c66b0ff187be55de |
|
BLAKE2b-256 | 13f4d83952f33330a4f6b91e312f165a055f2b8e7295b6d0cf514aa9e0096c88 |
Hashes for pastream-0.0.7-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91808ea8576c957c3e8bcffe89e72f538813b40596194378d6eab90bff085c57 |
|
MD5 | d0307d17eedc2044b4a4077361a911c6 |
|
BLAKE2b-256 | df35f83b1b3e3f6dddd1c36dd09389c6b91f196f5ff556585827146e0489d66e |
Hashes for pastream-0.0.7-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 020b57feec2305e4986905911394470255a1d8e02e277e427be2a749822d8760 |
|
MD5 | 2441edbf32d050b0d49689e68b174c74 |
|
BLAKE2b-256 | 88ab0acb1b88d70a3211c6605ad981ae3754b9b2a621f835fa8cc0310baa222d |
Hashes for pastream-0.0.7-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ffddba1e8fd5b61317a1a59b5b2b39901c756039409cb176c931c84c9ca6f407 |
|
MD5 | 725687bb4ba1b51138382beec8f9a213 |
|
BLAKE2b-256 | 3742e2ebdae0c12489fa54a487d552019812a7dad705aefa6613e159782f558c |
Hashes for pastream-0.0.7-cp36-cp36m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b88706008fb97b86a0951652d77169ac764af8079afb64ec6ba9a7b520e6021b |
|
MD5 | 365e8d424e2e611d8f1db51c12cfce35 |
|
BLAKE2b-256 | 4dea435fa3502bb10c7d9881cd3de2d0e5ecdffe74b7fec7d8718dac6b3799bb |
Hashes for pastream-0.0.7-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 505f570d86b1cf66d0b8b07ca7c315ca2b7270bbde839386072e96926878902e |
|
MD5 | ca5bfe82406b470fe041a07eb20d9117 |
|
BLAKE2b-256 | dbf5739012a824f6d917a35c26300cdba71f293bc3e257352be4b12a044fe888 |
Hashes for pastream-0.0.7-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 082242a278db3ea794ad8afa5d0ebf4ed615954515cbbe28fc060fdb2132742e |
|
MD5 | 6754eec867e932dc555d128c5a7dfa0c |
|
BLAKE2b-256 | de87d319da0536a2f31141557082a419dd626d12389b85d2983f99b38f5d2e9b |
Hashes for pastream-0.0.7-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79dd975da7a4033bf152dd39885ebef18961684db3258e34141417c44cf6fdd1 |
|
MD5 | a06fded133199f9aa4d8df05402d34c6 |
|
BLAKE2b-256 | e4b61e8d078eec2fbf5c6ded5e59fe5512a51358ff737052186619eccebdc97a |
Hashes for pastream-0.0.7-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b6d32d8a732cdb96e312f8eb6971c013e60439239f2944abd0ce3444e0749fb |
|
MD5 | 7054a78558fd3d095802f2bf58db228e |
|
BLAKE2b-256 | 8137c31e1c97f2b48ddd48eb65db90a4c4edbd524e92f30836f15dc48ee58e83 |
Hashes for pastream-0.0.7-cp35-cp35m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 910e2a66e11a067305227cb4927e256196e9d09207dadfe783f4fcc8493e5677 |
|
MD5 | 88250359320d8a901fa68c1c58dc94b2 |
|
BLAKE2b-256 | e70897d95cd7be9284239bceea4e317dde12798e3ad7abd8f7e5c43ca890b101 |
Hashes for pastream-0.0.7-cp34-cp34m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 599e9a478b384d31b2a6db420a2b9f640284717216f76314c32c24423601500f |
|
MD5 | 34e814784212dd1d230827f7d91eea33 |
|
BLAKE2b-256 | e497c7598aa9e7fa6467070eb33b045197ac667a3d59b3dd8a424e2fc6f8d2f1 |
Hashes for pastream-0.0.7-cp34-cp34m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8853babb4fe14be8b29b0a388e3f46598ff626284d39f0e821099dbbc789b917 |
|
MD5 | e96b5c063030194aa0fb762b5c02ca57 |
|
BLAKE2b-256 | a43a61e9df4846d1a2c148475ae1ce3d47cd25fb6f25a1e1d8561c094ae84007 |
Hashes for pastream-0.0.7-cp34-cp34m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 797be7bcf84a15331001dc8e42d24ec544d917589f2cc0fa107958c8cecc957c |
|
MD5 | 8ac0626d0872dab90c16c7009496a09c |
|
BLAKE2b-256 | 2cdeb96e03a5721f714108ebe3a5de4852418f078138b25f2db4f34bb345b401 |
Hashes for pastream-0.0.7-cp34-cp34m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7a2703d6d5bd2682f45b3a9da5c81b93be2588e8bae6678de5917de94a559c3 |
|
MD5 | b9871b859c746ef080cd4e173ad96bc0 |
|
BLAKE2b-256 | e4647e78228eb8315d8fcad8c11dd2bc98166123c7e5f5ee239d377d247cf04f |
Hashes for pastream-0.0.7-cp34-cp34m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb5b36701a81019ebe9e732bd244a34b764447329378c84133d2ff7ac3d4cdea |
|
MD5 | 9a00b211687aec5720326f8f87c0e8a5 |
|
BLAKE2b-256 | 9e2618f0086d77d645c7e1ce08f7e933151da28e094e33cac53da9e1475091d7 |
Hashes for pastream-0.0.7-cp33-cp33m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ac099b7fe87684899b38e33a7341e1d28003361ba63b765d7f5571d482397d9 |
|
MD5 | 10613539542303dd1ea5d7448f66e8f0 |
|
BLAKE2b-256 | 7098e20062bd3c56d4a06768982af7d5c9f954662e103518aaa8f415e73fab19 |
Hashes for pastream-0.0.7-cp33-cp33m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12a2775d0d1ebc33d6162e97e9eb8d10f7da42b43b4e19760efd64e8c93e769f |
|
MD5 | e4cbf5523a496b2ed511b265837c25aa |
|
BLAKE2b-256 | 5bfb4474cef86f6d87d04fde5a68b66526f192b8415827fbc5929dd0bb5cea73 |
Hashes for pastream-0.0.7-cp33-cp33m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd8badaf87813b5680babc8912068350e5400e4c95243386ff3910c12055b51c |
|
MD5 | 09e4af548e50475a7617b401de9a34ca |
|
BLAKE2b-256 | d7e24aa009d17174aaba0e168dbc9026299f5a41db50cbddf6730b2cdd761257 |
Hashes for pastream-0.0.7-cp33-cp33m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d70fa079676578fc20c6ea74f09b67e4991cda0c0ede7582c06a1dd631b2ef88 |
|
MD5 | 2e5886691aae26773cd29ef4f15bc22c |
|
BLAKE2b-256 | 5c87b0e8b86d407e38231d03f97449c4bd8d47518a0563b1bb634f9e0d2a692d |
Hashes for pastream-0.0.7-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eea0873bccff391aa11c7e1ad66f74646d96bf1e7e5e1841a66d4f7cdbddf5dc |
|
MD5 | 0d65b559f98189a508d56e97c24fa177 |
|
BLAKE2b-256 | 85823071be67db90e1d0d95859b297874c67470bdb83f5cec2166f9565063eaa |
Hashes for pastream-0.0.7-cp27-cp27mu-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1340ba57210579ec321520d41bc2e7143e9fd20103fb0b8eac6c2e9744ea2f3a |
|
MD5 | 8b95b09937626d607b5e5b440139baea |
|
BLAKE2b-256 | 5c4162dd4c7319e653143647b90885b17c8ac6db377d79add4cafe2162ee0c27 |
Hashes for pastream-0.0.7-cp27-cp27m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ffec675eddd34ac971950d05edf0b292f0676c33cc30552a08032271553f380f |
|
MD5 | 2abe28aca655b3f859d01621b35be819 |
|
BLAKE2b-256 | 586a8d48fdbf8962cbb6da4155d9a0d30055be398c5df6acf094b121ff628630 |
Hashes for pastream-0.0.7-cp27-cp27m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dee17a5b6c420638e0e324471674f5605b715ebe58154296da9b0054ade2d467 |
|
MD5 | 0dc9905175402a3df0c86c10a9261d58 |
|
BLAKE2b-256 | a83d3c7b5e2688e8e747103e3d38e8ea0348482627e1d104767db7a9d398a78d |
Hashes for pastream-0.0.7-cp27-cp27m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea30dc40f1e536479a1bd84f275d3e9e539def2fa51b809bad705b4dcb331433 |
|
MD5 | 2e0c5990aa4517e367c5f0bce4f115cc |
|
BLAKE2b-256 | 578fec9356fc7766a47c9973adbb0286fa9e81f9293bad0988c86732d46b9b39 |
Hashes for pastream-0.0.7-cp27-cp27m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 938396d205cb203944f896a093dfc032d2d28591e4508817a452bdc6c5546148 |
|
MD5 | 7f193fc9393e2b1a35d5b81329563bf5 |
|
BLAKE2b-256 | 27de4d34d73382bdd8c0e9435836b286d71ac5a2f4bf42315a2dea5f49bb4ec6 |
Hashes for pastream-0.0.7-cp27-cp27m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ed190acd137f263c87bb98f958958e4668a7c1c8a1a85529c11854d320bb14e |
|
MD5 | 2ba0299c581d3b3b76e643aa26e7ad26 |
|
BLAKE2b-256 | b00dd3548ed5c5db504973ce5bab977b9010c2ac0ec5305f304d6baf4fb517ff |