GIL-less Portaudio Streams for Python
Project description
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(): process(chunk)
See pastream.chunks and pastream.InputStream.chunks method.
- Built-in support for working with SoundFiles and numpy ndarrays
Seamless support for playback/recording of numpy ndarrays, generic buffer types, and SoundFiles.
- 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>
Building Documentation
Documentation for pastream can be easily generated in a wide variety of formats using Sphinx. Just follow the steps below.
Checkout the repository:
$ git clone --recursive http://github.com/tgarc/pastream
Then use the included makefile/make.bat to generate documentation. (Here we output to the html format):
$ cd pastream/docs $ make html
Examples
Record one second of audio to memory, then play it back:
import pastream as ps
# Use *with* statements to auto-close the stream
with ps.DuplexStream() as stream:
out = stream.record(int(stream.samplerate), blocking=True)
stream.play(out, blocking=True)
Playback 10 seconds of a file, adding zero padding if the file is shorter, and record the result to memory:
import pastream as ps, soundfile as sf
with sf.SoundFile('my-file.wav') as infile, ps.DuplexStream.from_file(infile) as stream:
out = stream.playrec(infile, frames=10 * int(stream.samplerate), pad=-1, blocking=True)
Grab (real) frequency transformed live audio stream with 50% overlap:
import pastream as ps, numpy as np
chunksize = 1024
window = np.hanning(chunksize)
for x_l in ps.chunks(chunksize, overlap=chunksize//2, channels=1):
X_l = np.fft.rfft(x_l * window)
See also the included examples under /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 and record the playback:
$ sox -n -t au - synth sine 440 | pastream - output.wav
Play a RAW file:
$ pastream -c1 -r48k -e=pcm_16 output.raw
Record 10 minutes of audio at 48kHz:
$ pastream null output.wav -r48k -d10:00
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.1.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1a246c38c5a05ee12f212754d869717deeb5df6068c5ab4b7df08dec970c19e |
|
MD5 | acb7e7e869a5110c8e98376510a79687 |
|
BLAKE2b-256 | 8bc193f0abfe57568fcdd037db1f43f944b2066aa5b698c42b1adba102aee864 |
Hashes for pastream-0.1.0-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4884bedc67e4536a68031d069d532293404165c711855e9e006b8780aa47cf2a |
|
MD5 | 9773df297bc66b1469660b41342debc0 |
|
BLAKE2b-256 | 84edd2292a69ac893dc510a47a33e32b3a74f02c0ad27e90c64bf942301ed90e |
Hashes for pastream-0.1.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40897a2230c941b120ec6a82a68b4e326faf03af384334c4fc369997956991a3 |
|
MD5 | 9a26ea4d7a9cb5696076a37eb9c039a8 |
|
BLAKE2b-256 | bd5b2cee2b20dbc9151aefcf7ac6431b05e185565f7bcc8c3e8886e19158f453 |
Hashes for pastream-0.1.0-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4582cb8eac52a9a0372da17247a90f79d5489ac21a65d35aa0ab117977a12c0 |
|
MD5 | 19c8100746ccba7f563f9f85ebcaeb55 |
|
BLAKE2b-256 | fd3711fed29dd4e7a30dbd41c0cafc37c04ccd6598ac05e551ca6f60aee533cc |
Hashes for pastream-0.1.0-cp36-cp36m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c79d7b5c39112dbbedd799a15faa6bf0e47b00c8bb1f66dfbdbe1d334f6d36bf |
|
MD5 | 14f0f580179830c93eb39ed33de17776 |
|
BLAKE2b-256 | 358b5ce2a0042aa997000697d052f1918960a74899119aec7f1384640f41fd8c |
Hashes for pastream-0.1.0-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7a223e061369e6867e96110db66b9eab93c185db1c5d2d2ee3253979d671221 |
|
MD5 | fe1ecec4f2e25509c97a515957bb1356 |
|
BLAKE2b-256 | a85a722026221bd28d4c9a5fd8d16bef88555b3a48079cba801de8b804045499 |
Hashes for pastream-0.1.0-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f02d43d54f9fa62c55e7f2e53a973620ea83099daaab58ef2fb61637fadd110a |
|
MD5 | 90e93d72de2154daee96d3e30fb8adfc |
|
BLAKE2b-256 | ac56590c6b58a00bfa4308904d3918ed3366023b4e9e9c8a9b4bf9f1b8621ae7 |
Hashes for pastream-0.1.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e53b590db1ea3b073bfdb50cfa2d27120716ffaee36f1cee04a2779c1ad913bc |
|
MD5 | 843f0a7d29ca1319bb87e239fb8d0ccf |
|
BLAKE2b-256 | 85dfdba88dec1c016f33ba88387013bdb79b4da02d65b66aeb04a983e0346227 |
Hashes for pastream-0.1.0-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae43bf727116e4a7e7ccacc2aa8fe932b0f7da2625eeec663f4ce9348f220c1b |
|
MD5 | 92be64d52d8d0ff315c5bb514b580de7 |
|
BLAKE2b-256 | 78e91a345294de251c0ef6593d887901d332a3a788c7ba9e531caae72a9bc3af |
Hashes for pastream-0.1.0-cp35-cp35m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c576c90fbf8abc5dd9cef19c77faa884ca999d9806b12b1384588fe31a7ac925 |
|
MD5 | 685e5f0c520322a038b2dcc5515ed80e |
|
BLAKE2b-256 | ef3af77bd9ade36f71e13f74782b2d9366b77c4115a2f8fb39d84d15344da71b |
Hashes for pastream-0.1.0-cp34-cp34m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ddcf86a0c86b3d5c5639d84cd1d9295f7173d5ef08025996fb5c1acf3f2fc8c7 |
|
MD5 | 7d3d76048edca6ee858ffaf1c0b527cf |
|
BLAKE2b-256 | 007b0044ca5dbc1c39463cfcdd9bc9684747a375bae220800c7ced46dafae923 |
Hashes for pastream-0.1.0-cp34-cp34m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7329206715446d4ba181e5eb903fe03d3180c347ffb01ef1d24bacc7b29b32ac |
|
MD5 | d63aeda123593fe8e23589ac9a2b11af |
|
BLAKE2b-256 | 1b94c6cc8501949e7e192b2d942406336c64078705582b4f88a005152d2c0144 |
Hashes for pastream-0.1.0-cp34-cp34m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce6af48123b372ca1b280262bf1a7a09af9dd0c83137995e36fa39bf726de095 |
|
MD5 | e087515695042d009a670845addf5692 |
|
BLAKE2b-256 | ef23d973f4d14d89347f60bf749dac1362e621c7b0e4eecfea819154cd84df0d |
Hashes for pastream-0.1.0-cp34-cp34m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a3f81f52422132d0e16393e14d02a5e8e1e1b76e27d3c4ede7135af22a0346e |
|
MD5 | 706f7d335c6900ff5d2170196282b0c5 |
|
BLAKE2b-256 | bfcbad1bca19f9d6cb88af477730259082205ae2055617a266594f6497960730 |
Hashes for pastream-0.1.0-cp34-cp34m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71d26e8376fa687224650ebcd43a0e9a5828d696a9689bc375039a135429dfd4 |
|
MD5 | 33ba49bba86cee06c2f9765f94261df6 |
|
BLAKE2b-256 | 17aaafb0c259125d22e1a626e76eb983b4927602ac6f011e2f74166399de5415 |
Hashes for pastream-0.1.0-cp33-cp33m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26b5a7632750359f48d90d83fde62b3e6241fffd5e9b868e7cc28957d5d4ca71 |
|
MD5 | d6c83e6e44865a85ee71e9b54fc8f3a7 |
|
BLAKE2b-256 | 9b6c378efbd24564475f49fd80afcf735ca951ad36b11ec4613411faf5c5505c |
Hashes for pastream-0.1.0-cp33-cp33m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9574d28714ec2d41f715cb05b443a71001202f789ad94547d27113f7630c86a4 |
|
MD5 | 656500592b8231550b7f0f9f6cc574fb |
|
BLAKE2b-256 | 162df2ec5a14e046a632c9991468086737f31c2f8d06f41f8c0e671ffdbdad35 |
Hashes for pastream-0.1.0-cp33-cp33m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 047b2ee54a893e3261886cda630149e575098f71634212102648895222d2f2b2 |
|
MD5 | 3c179894b950d4ba7b73a87efa3b2a54 |
|
BLAKE2b-256 | ce1d7c7a4ce9c3f6ede937070b2e7acef09966631057cdf273e38b96832a5dbc |
Hashes for pastream-0.1.0-cp33-cp33m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dbd6b1b29dd35cc9492c60b1de55eaee10edc571f742bab7eab8ca2b2af3e944 |
|
MD5 | 5002fee5ec49fda79da19f2365670d70 |
|
BLAKE2b-256 | f385d1a52d1a84391e5734de98d09f41bf3b2505e23ecf0c4c3cce5141221bac |
Hashes for pastream-0.1.0-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43c92009c248512e6818050da77ada0a397cd9c841a3ef8fc50695037b96fc81 |
|
MD5 | 948f1f3836e931b170100eb349bf34a7 |
|
BLAKE2b-256 | a3066414ed57d507045d8ba232fc2aba064cb6d1a986b3c4bbb15acabfc77381 |
Hashes for pastream-0.1.0-cp27-cp27mu-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9d27155d045d89a2f3334c4badcac981ed8ac31a0ec326abdc1a742d774a82d |
|
MD5 | e6dcd00bac7cd41752b1816f33539880 |
|
BLAKE2b-256 | 511914aee02ef133cd82363832eb8ba37176354181ee0c8fedd378e7e7969237 |
Hashes for pastream-0.1.0-cp27-cp27m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b576eff89b19bf206a5d1afd09456faf82bea5a5467e07202cad0bb56743a463 |
|
MD5 | 422355fb8d3af6f277a2839119bd28f3 |
|
BLAKE2b-256 | 960630e6ac2c63ade17c5172974a754dc3f343589801c765c92c6163f1698839 |
Hashes for pastream-0.1.0-cp27-cp27m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 035d5b3fdaa2c7a347ceaab8b6b05e6749f5f43054f329dd593fc245c93d5252 |
|
MD5 | 9a9c6bd103acff9710c94227d61824f2 |
|
BLAKE2b-256 | ad2a9f85bb0d70b97578c697bd2f5d100924733ad84a0f188ecd34840135427c |
Hashes for pastream-0.1.0-cp27-cp27m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9e603c495bff546961c0fa8bbe6d23c9cf71c3442d2d10b8109735d667ae7e8 |
|
MD5 | ed163c701d257989aeacba3ac7c28274 |
|
BLAKE2b-256 | 5bda5b3ebc4c3d112d57ee27dfb8d0c9121f3106f661bfd360cd2a7e383787d0 |
Hashes for pastream-0.1.0-cp27-cp27m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ffe6d4fe4ee7022941f14d07c8f1968131b7df54b06ca9df4fc60753d1bec823 |
|
MD5 | 5437b897ba8772dd4f06e7b7812681c9 |
|
BLAKE2b-256 | eff05e634865b0a8f3cdd57139058d85e8a4cf47304c2fb9fcc2da002e4ad8cd |
Hashes for pastream-0.1.0-cp27-cp27m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f20358b3d2860e6d730a496a4875a9c5bd48ec2c792a36e055e2eff73ceb0f4a |
|
MD5 | 40456cc0d8bf12e0d5620d2b256eb83d |
|
BLAKE2b-256 | bb86268fa6797e1b5c9aa0b48bcd545ac06f5f258f75ce150eb0a63e7fc553c7 |