input_audio
Real-time mic recording to WAV with optional VAD segmentation and noise reduction.
Millisecond-based API; buffer_size / sample_rate must be an integer number of milliseconds. Audio is processed in float32, and written to 16‑bit PCM WAV.
Features
- Voice Activity Detection (VAD): Detect speech start/end and emit segments
- Noise Reduction (NR): Built-in denoiser for cleaner audio
- Streaming to File: Continuous WAV writing with periodic processing
- Millisecond-first API: Simple timing controls using milliseconds
- Observability: Uses
loggingfor friendly debug output when enabled
Installation
pip install input-audio
Or install from source:
git clone https://github.com/allen2c/input_audio.git
cd input_audio
pip install -e .
Quick Start
Record to a WAV file for 5 seconds:
from input_audio import input_audio
input_audio(
"./recordings/quick.wav",
max_recording_duration_ms=5000,
)
Enable noise reduction and verbose logging:
import logging
from input_audio import input_audio, NoiseReductionConfig
logging.basicConfig(level=logging.INFO)
input_audio(
"./recordings/nr.wav",
enable_noise_reduction=True,
noise_reduction_config=NoiseReductionConfig(prop_decrease=0.8),
max_recording_duration_ms=5000,
verbose=True,
)
Enable VAD, collect segments into a queue, and also save segments to a folder:
import queue
from input_audio import input_audio, VADConfig
segments_q: queue.Queue = queue.Queue()
input_audio(
"./recordings/full.wav",
enable_vad=True,
vad_config=VADConfig(pre_speech_padding_ms=300, post_speech_padding_ms=500),
vad_segments_queue=segments_q,
vad_dirpath="./tmp_vad", # optional: segment WAVs written here
max_recording_duration_ms=10000,
)
# Read emitted segments from the queue (each item has start_ms, end_ms, audio_url)
while not segments_q.empty():
seg = segments_q.get()
print(seg.start_ms, seg.end_ms, len(seg.audio_url.data))
Customize audio settings (16kHz mono, 512 buffer, batch processing every 320ms):
from input_audio import input_audio, AudioConfig
cfg = AudioConfig(
sample_rate=16000,
channels=1,
buffer_size=512,
batch_process_ms=320,
gain_db=20.0,
)
input_audio(
"./recordings/custom.wav",
audio_config=cfg,
max_recording_duration_ms=5000,
)
Notes:
input_audio(...)returnsb""; the primary outputs are the continuously written WAV file and (optionally) VAD segments.- Timing constraints are enforced and will raise
ValueErrorif violated. - NR order: noise reduction is applied before gain for consistent loudness.
API Reference (v0.2.0)
input_audio(
output_audio_filepath: str | Path,
*,
audio_config: Optional[AudioConfig] = None,
enable_vad: bool = False,
vad_config: Optional[VADConfig] = None,
vad_model: Optional[torch.nn.Module] = None,
vad_segments_queue: Optional[queue.Queue[VADSegment]] = None,
vad_dirpath: Optional[str | Path] = None,
enable_noise_reduction: bool = False,
noise_reduction_config: Optional[NoiseReductionConfig] = None,
stop_event: Optional[threading.Event] = None,
max_recording_duration_ms: int = 60000,
verbose: bool = False,
) -> bytes
Key models:
AudioConfig(
format=pyaudio.paInt16, # 16‑bit PCM
channels=1,
sample_rate=16000,
buffer_size=512,
rolling_working_audio_buffer_ms=5000,
batch_process_ms=320,
gain_db=20.0,
)
VADConfig(
threshold=0.5,
pre_speech_padding_ms=300,
post_speech_padding_ms=500,
)
NoiseReductionConfig(
sample_rate=16000,
stationary=True,
prop_decrease=0.8,
n_std_thresh_stationary=1.5,
n_fft=1024,
)
Constraints:
buffer_size * 1000 % sample_rate == 0(buffer duration must be whole ms)batch_process_msmust be a multiple of the buffer duration (ms)AudioConfig.sample_ratemust matchNoiseReductionConfig.sample_rate
Changelog — v0.2.0
Breaking changes:
- Renamed
VADConfig.keep_before_speech_ms→pre_speech_padding_ms - Renamed
VADConfig.keep_after_speech_ms→post_speech_padding_ms - Removed
VADConfig.sample_rateandVADConfig.buffer_size(VAD shares audio settings)
Behavioral and quality updates:
- Apply noise reduction before gain (consistent final loudness)
- Replace prints with
logging.getLogger(__name__) - Enforce timing constraints with clear error messages
- Integer-safe latency checks; fade-in/out uses float32 consistently
Requirements
- Python 3.11+
- PyAudio (microphone access)
- PyTorch and torchaudio (VAD model, WAV encoding)
- Numpy, noisereduce, silero_vad
- See
requirements.txtfor full list
License
MIT License — see LICENSE for details.
Metadata
Release files for input-audio 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| input_audio-0.2.0.tar.gz | 10.4 kB | Without provenance | Details for input_audio-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| input_audio-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for input_audio-0.2.0-py3-none-any.whl |
Total release size: 20.3 kB
Release files / input_audio-0.2.0.tar.gz
| Download URL | input_audio-0.2.0.tar.gz |
|---|---|
| Size | 10.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
79f7bb6af2ffe0307df74512984205a27174eee5cae5b086dbd087f7460a8dbf
|
|
BLAKE2b-256 checksum How to use checksums |
0bc9091b8c31876016e9fa38c1f1024082373b0a1f10004ac734d17f79c9f350
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.4 CPython/3.11.11 Darwin/24.6.0
|
Release files / input_audio-0.2.0-py3-none-any.whl
| Download URL | input_audio-0.2.0-py3-none-any.whl |
|---|---|
| Size | 10.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a0eb6926c06d7abf7c9884ce36b71da4745d6d8ad548fb64e0b448c8d0786532
|
|
BLAKE2b-256 checksum How to use checksums |
eb6aa67ae4f0fc9de2e797d5de681981038fa796dbd01e71feb77d3e73908882
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.4 CPython/3.11.11 Darwin/24.6.0
|
Security for input-audio 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.