Flexible cross-platform audio capture (microphone, system loopback, per-process) for Python, via native bindings to the flexaudio Rust library.
Project description
flexaudio (Python)
Python bindings for flexaudio, a cross-platform audio capture library (microphone, system loopback, and per-process loopback) written in Rust. Built with PyO3 and maturin.
Install
pip install flexaudio
Usage
import flexaudio
import numpy as np
# List available devices (empty list on a headless machine, never raises).
for d in flexaudio.devices():
print(d.id, d.name, d.source_kind, d.is_default)
# Open a microphone stream. open() starts capture before returning.
with flexaudio.open("mic") as stream:
chunk = stream.poll_chunk() # None if nothing is ready yet
if chunk is not None:
# data is interleaved little-endian f32 bytes.
samples = np.frombuffer(chunk.data, dtype=np.float32)
print(chunk.frames, chunk.peak, chunk.rms, samples.shape)
event = stream.poll_event() # None if no event is pending
if event is not None:
print(event.type, event.count, event.message)
# leaving the `with` block stops the stream
Sources
flexaudio.open("mic")— microphone input.flexaudio.open("system")— full system output loopback. Passexclude_self=Trueto drop this process's own playback.flexaudio.open("process", process_id=<pid>)— a single process's output. Passmode="exclude"to capture everything except that process.
Optional keyword arguments: device_id, output_rate (default 48000),
output_channels (default 2), chunk_ms (default 20), plus the integrated
add-ons vad and denoise (see below).
Stream.switch_source(...) hot-swaps the input source without stopping the
stream. pause() / resume() / is_paused() control delivery.
Stream.native_format() returns the source's native (sample_rate, channels)
and Stream.dropped_chunks() returns the cumulative number of dropped chunks.
Integrated denoise and VAD
open() (and switch_source()) accept denoise=True and vad={...} to run
noise suppression and voice-activity detection inside poll_chunk(). The
processing order is denoise -> VAD.
with flexaudio.open("mic", denoise=True, vad={"threshold": 0.5}) as stream:
chunk = stream.poll_chunk()
if chunk is not None:
samples = np.frombuffer(chunk.data, dtype=np.float32) # denoised audio
for ev in chunk.vad_events: # speech boundaries
print(ev.type, ev.at_sample) # "speech_start"/"speech_end"
denoise requires a 48000 Hz output (denoise=True with any other
output_rate raises ValueError); the first 480 samples/channel are silence
from the denoiser's fixed delay. vad is a dict with the same keys as the
standalone Vad (below). at_sample is measured at the VAD's internal rate
(16000 or 8000 Hz), not the input rate.
Standalone add-ons
The same building blocks are available as independent classes.
# Voice activity detection over arbitrary-format PCM (mono/stereo, any rate).
vad = flexaudio.Vad(threshold=0.5, min_silence_ms=100) # silero defaults
for ev in vad.process(samples, input_sample_rate=48000, input_channels=2):
print(ev.type, ev.at_sample)
# Noise suppression (48 kHz, +/-1.0 normalized interleaved f32).
den = flexaudio.Denoiser(channels=1)
clean = den.process(samples) # returns a same-length list
tail = den.flush() # trailing 480 samples/channel
# Streaming FLAC encoding, optionally rotating into rec-001.flac, rec-002.flac...
with flexaudio.FlacEncoder("rec.flac", sample_rate=48000, channels=2,
split_seconds=60) as enc:
enc.write_chunk(samples) # interleaved f32; finalize() runs on exit
# Device hot-plug monitoring (poll-based, like poll_chunk / poll_event).
with flexaudio.watch_devices() as watcher:
ev = watcher.poll_event() # None when nothing is pending
if ev is not None:
print(ev.type, ev.id, ev.device, ev.source_kind)
samples may be a Python list, an array.array, or a NumPy ndarray.
License
MIT.
This binding statically links the following flexaudio add-ons, which embed their models/tables and require no runtime files or network access:
- flexaudio-vad — uses ONNX Runtime (MIT) and the embedded Silero VAD model (MIT).
- flexaudio-encode — uses flacenc (Apache-2.0) for pure-Rust FLAC encoding.
- flexaudio-denoise — uses nnnoiseless (BSD-3-Clause), a Rust port of RNNoise with embedded model weights.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flexaudio-0.2.0.tar.gz.
File metadata
- Download URL: flexaudio-0.2.0.tar.gz
- Upload date:
- Size: 2.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13729b88702021182651bbf8a197834fbc0435a1f5e072c6a41756f0ab7c01ac
|
|
| MD5 |
207909a948a5988d32d318a2a765c2dd
|
|
| BLAKE2b-256 |
35a1777ed7a25a8ce92d774b77fa5ebd0c1413d2bef8086d83743e56774721af
|
Provenance
The following attestation bundles were made for flexaudio-0.2.0.tar.gz:
Publisher:
release-pypi.yml on Studio-Sadola/flexaudio
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
flexaudio-0.2.0.tar.gz -
Subject digest:
13729b88702021182651bbf8a197834fbc0435a1f5e072c6a41756f0ab7c01ac - Sigstore transparency entry: 2071962401
- Sigstore integration time:
-
Permalink:
Studio-Sadola/flexaudio@d9f057864da469c2567aeb9451979d0c0cdb8f5d -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Studio-Sadola
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-pypi.yml@d9f057864da469c2567aeb9451979d0c0cdb8f5d -
Trigger Event:
push
-
Statement type:
File details
Details for the file flexaudio-0.2.0-cp38-abi3-win_amd64.whl.
File metadata
- Download URL: flexaudio-0.2.0-cp38-abi3-win_amd64.whl
- Upload date:
- Size: 9.5 MB
- Tags: CPython 3.8+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
395bee4cb91d5f82aafafd18190d5745584fd869e54dab7066891b0201175575
|
|
| MD5 |
8e7a4dc0590c0f21b1ddad6b5afa0ff2
|
|
| BLAKE2b-256 |
b5899106b559667f8e5d50c06011e1459b87954bf399dcd0c2f51a6b90922049
|
Provenance
The following attestation bundles were made for flexaudio-0.2.0-cp38-abi3-win_amd64.whl:
Publisher:
release-pypi.yml on Studio-Sadola/flexaudio
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
flexaudio-0.2.0-cp38-abi3-win_amd64.whl -
Subject digest:
395bee4cb91d5f82aafafd18190d5745584fd869e54dab7066891b0201175575 - Sigstore transparency entry: 2071962446
- Sigstore integration time:
-
Permalink:
Studio-Sadola/flexaudio@d9f057864da469c2567aeb9451979d0c0cdb8f5d -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Studio-Sadola
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-pypi.yml@d9f057864da469c2567aeb9451979d0c0cdb8f5d -
Trigger Event:
push
-
Statement type:
File details
Details for the file flexaudio-0.2.0-cp38-abi3-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: flexaudio-0.2.0-cp38-abi3-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 11.1 MB
- Tags: CPython 3.8+, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ec762ff33f0ade612f478d4b8a5291e60f2da2074f08dc544841a222512024e
|
|
| MD5 |
f457bf2d87474052a9a38adf1d422c10
|
|
| BLAKE2b-256 |
bd21f7c258539ce4d8ca7012573d2e1a376dbd0b087c31009623802330390412
|
Provenance
The following attestation bundles were made for flexaudio-0.2.0-cp38-abi3-manylinux_2_34_x86_64.whl:
Publisher:
release-pypi.yml on Studio-Sadola/flexaudio
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
flexaudio-0.2.0-cp38-abi3-manylinux_2_34_x86_64.whl -
Subject digest:
2ec762ff33f0ade612f478d4b8a5291e60f2da2074f08dc544841a222512024e - Sigstore transparency entry: 2071962478
- Sigstore integration time:
-
Permalink:
Studio-Sadola/flexaudio@d9f057864da469c2567aeb9451979d0c0cdb8f5d -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Studio-Sadola
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-pypi.yml@d9f057864da469c2567aeb9451979d0c0cdb8f5d -
Trigger Event:
push
-
Statement type:
File details
Details for the file flexaudio-0.2.0-cp38-abi3-manylinux_2_34_aarch64.whl.
File metadata
- Download URL: flexaudio-0.2.0-cp38-abi3-manylinux_2_34_aarch64.whl
- Upload date:
- Size: 12.1 MB
- Tags: CPython 3.8+, manylinux: glibc 2.34+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c20eb6725b6b6bd9e8233d33e074f0d3b6694c567a8727ebfe7be78c44e4f8e
|
|
| MD5 |
97100a0f9d5a35547c07a72184d79a3a
|
|
| BLAKE2b-256 |
8ca45f06bd8efb227b5e97e8686ffbc52d5f64f58fa966ddcc6f1cdf6124901d
|
Provenance
The following attestation bundles were made for flexaudio-0.2.0-cp38-abi3-manylinux_2_34_aarch64.whl:
Publisher:
release-pypi.yml on Studio-Sadola/flexaudio
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
flexaudio-0.2.0-cp38-abi3-manylinux_2_34_aarch64.whl -
Subject digest:
3c20eb6725b6b6bd9e8233d33e074f0d3b6694c567a8727ebfe7be78c44e4f8e - Sigstore transparency entry: 2071962503
- Sigstore integration time:
-
Permalink:
Studio-Sadola/flexaudio@d9f057864da469c2567aeb9451979d0c0cdb8f5d -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Studio-Sadola
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-pypi.yml@d9f057864da469c2567aeb9451979d0c0cdb8f5d -
Trigger Event:
push
-
Statement type:
File details
Details for the file flexaudio-0.2.0-cp38-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: flexaudio-0.2.0-cp38-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 10.3 MB
- Tags: CPython 3.8+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2fe810231037ad868cf6a743a3ab2cb566edce0f0d98d501d72b5acf467a9278
|
|
| MD5 |
9f897bc6b4a3545aa6688ebfd06b414c
|
|
| BLAKE2b-256 |
a198884e24f4a5d8b3b2e2b8286f612f652c37e239243c9b762bce3d122b7072
|
Provenance
The following attestation bundles were made for flexaudio-0.2.0-cp38-abi3-macosx_11_0_arm64.whl:
Publisher:
release-pypi.yml on Studio-Sadola/flexaudio
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
flexaudio-0.2.0-cp38-abi3-macosx_11_0_arm64.whl -
Subject digest:
2fe810231037ad868cf6a743a3ab2cb566edce0f0d98d501d72b5acf467a9278 - Sigstore transparency entry: 2071962423
- Sigstore integration time:
-
Permalink:
Studio-Sadola/flexaudio@d9f057864da469c2567aeb9451979d0c0cdb8f5d -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Studio-Sadola
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-pypi.yml@d9f057864da469c2567aeb9451979d0c0cdb8f5d -
Trigger Event:
push
-
Statement type: