Skip to main content

Low-latency macOS audio capture and processing (AEC/NS) powered by Rust

Project description

macloop

Low-latency macOS audio capture and processing for Python, powered by Rust.

  • System audio and microphone capture via ScreenCaptureKit
  • WebRTC-based AEC (echo cancellation) and NS (noise suppression)
  • Sync and async streaming APIs

Requirements

  • macOS (Apple Silicon or Intel)
  • Python 3.9+

Installation

pip install macloop

Quick Start (sync)

import macloop

sources = macloop.list_audio_sources()
display = next(s for s in sources if s["type"] == "display")

cfg = macloop.AudioProcessingConfig(
    sample_rate=16000,
    channels=1,
    sample_format="i16",
    enable_aec=True,
    enable_ns=False,
)

with macloop.Capture(
    display_id=display["display_id"],
    config=cfg,
    capture_system=True,
    capture_mic=True,
) as stream:
    for chunk in stream:
        print(chunk.source, len(chunk.samples))
        # chunk.samples is numpy.ndarray (int16 or float32)

Quick Start (asyncio)

import asyncio
import macloop

async def main():
    sources = macloop.list_audio_sources()
    display = next(s for s in sources if s["type"] == "display")
    cfg = macloop.AudioProcessingConfig()

    async with macloop.Capture(
        display_id=display["display_id"],
        config=cfg,
        capture_system=True,
        capture_mic=True,
    ) as stream:
        async for chunk in stream:
            print(chunk.source, len(chunk.samples))

asyncio.run(main())

Data Format

AudioChunk.samples is a numpy.ndarray:

  • np.int16 when sample_format="i16"
  • np.float32 when sample_format="f32"

This makes it convenient to pass chunks directly to model inference pipelines without extra conversion.

# Example: direct handoff to inference-friendly float32
import numpy as np
import macloop

sources = macloop.list_audio_sources()
display = next(s for s in sources if s["type"] == "display")
cfg = macloop.AudioProcessingConfig(sample_format="f32", sample_rate=16000, channels=1)

with macloop.Capture(display_id=display["display_id"], config=cfg) as stream:
    for chunk in stream:
        x = chunk.samples.astype(np.float32, copy=False)
        # model(x)

Sherpa ASR Demo

For speech-to-text (ASR), use this short example:

uv run --with sherpa-onnx --with huggingface_hub --reinstall-package macloop \
  python examples/sherpa_asr_demo.py --seconds 5

It captures microphone audio with macloop, downloads a Sherpa model from Hugging Face (or uses --model-dir), and prints transcript text.

Notes

  • One capture target per stream: either display_id or pid.
  • For app capture use pid=....

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

macloop-0.1.0.tar.gz (32.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

macloop-0.1.0-cp314-cp314-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

File details

Details for the file macloop-0.1.0.tar.gz.

File metadata

  • Download URL: macloop-0.1.0.tar.gz
  • Upload date:
  • Size: 32.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for macloop-0.1.0.tar.gz
Algorithm Hash digest
SHA256 30dd2844dcb57533fff979eccc15a7450f2cefa009354b0ec3dd9a27e631392b
MD5 3a598f689678e0b81a6a66663fcab8c3
BLAKE2b-256 e39e25591713e5405cf8e42913efab662fca6d25740b1573a5d4a6acb9f813c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for macloop-0.1.0.tar.gz:

Publisher: publish.yml on kemsta/macloop

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file macloop-0.1.0-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for macloop-0.1.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3b59e3f1ac10dfac0ce3bc09968289aadae577b482491c324350325a27b1e016
MD5 590cac9b8deae5a764222c6c5b82da34
BLAKE2b-256 815e6f5ee9cc98863c2f2e9167f34bb8b7af577044a5d407fb7696e3f94fe0e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for macloop-0.1.0-cp314-cp314-macosx_11_0_arm64.whl:

Publisher: publish.yml on kemsta/macloop

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page