duplex-audio
Full-duplex audio front-end for Python: speaker/microphone I/O with acoustic echo cancellation (AEC) and noise suppression (NS).
duplex-audio は、スピーカーで音を再生しながらマイクで集音する Python library です。 マイク入力を AEC、NS の順に処理し、再生音のエコーと周囲の雑音を除いた クリーン音声を NumPy 配列で呼び出し側へ渡します。AEC の参照信号には、 duplex-audio が実際に再生した音を使います。
- 呼び出し側は、復号済みのモノラル PCM と sample rate を渡して音を再生できます。
- 呼び出し側は、AEC と NS の backend を選び、それぞれを有効・無効にできます。
- 呼び出し側は、再生 generation ごとに再生の保持停止、再開、無音化を要求できます。
Install
Python 3.12 以上の環境へ、PyPI からインストールします。
pip install duplex-audio
LocalVQE を AEC backend として使う場合は、次の extra を指定します。
pip install "duplex-audio[localvqe]"
localvqe extra は Linux x86_64 でのみ pylocalvqe をインストールします。
pylocalvqe の wheel は native library を同梱しますが、model weight は別途取得します。
オーディオ I/O は、pasimple を使って PipeWire / PulseAudio の Pulse 互換 Unix socket
へ接続します。実行環境には libpulse のランタイムと、接続可能な Pulse 互換の
録音・再生環境が必要です。pulse_server、source、sink を DuplexEngine に渡すと、
接続先とマイク入力・再生出力を指定できます。
Models
LocalVQE の model は、pylocalvqe の downloader で取得します。
downloader は固定した model repository revision から weight を取得し、
SHA-256 を検証します。戻り値は取得した model file の path です。
from pylocalvqe.assets import download_model
model = download_model("v1.4-aec-200k", "models")
呼び出し側は、この path を LocalVqeSettings.model_path へ渡します。
v1.4-aec-200k は AEC-only variant なので、独立した RNNoise の NS と組み合わせられます。
AEC と NS をまとめて行う v1.3 を使う場合は、独立 NS の二重掛けを避けるために
ns_backend="none" を指定します。
LocalVQE を使わない場合は、model の取得は不要です。
DuplexEngine の既定の AEC backend は、参考実装の NLMS です。
Python usage
次の例は Linux x86_64 で localvqe extra を導入した環境を使います。
1 秒のテスト音を再生しながら 3 秒間集音し、LocalVQE による AEC と
RNNoise による NS を通した音を受け取ります。AEC と NS は既定では無効なので、
例では両方を明示的に有効にしています。
import time
import numpy as np
from pylocalvqe.assets import download_model
from duplex_audio import DuplexEngine, LocalVqeSettings
model = download_model("v1.4-aec-200k", "models")
recorded = []
with DuplexEngine(
aec_backend="localvqe",
localvqe_settings=LocalVqeSettings(
model_path=model,
variant="v1.4-aec-200k",
threads=4,
),
aec_enabled=True,
ns_backend="rnnoise",
ns_enabled=True,
) as engine:
sample_rate = 24_000
t = np.arange(sample_rate) / sample_rate
reference = (0.05 * np.sin(2 * np.pi * 440 * t)).astype(np.float32)
generation = engine.create_playback_generation()
engine.enqueue_playback(generation, reference, sample_rate=sample_rate)
engine.finish_playback(generation)
deadline = time.monotonic() + 3.0
while time.monotonic() < deadline:
clean = engine.read_clean(timeout=0.1)
if clean is not None:
recorded.append(clean)
clean = np.concatenate(recorded) if recorded else np.empty(0, dtype=np.float32)
print(clean.shape, clean.dtype)
enqueue_playback() は、1 次元の浮動小数点 PCM とその sample rate を受け取ります。
再生 sample rate の変換は library が行います。finish_playback() は generation の
末尾を確定します。read_clean() はモノラル 16 kHz の float32 配列を
block ごとに返し、指定した待ち時間内に音が届かなければ None を返します。
context manager は録音・再生を開始し、終了時に停止します。
呼び出し側は、pause_playback() と resume_playback() で再生キューを保持したまま
再生を止めて再開し、quiesce_playback() で generation の無音化を要求できます。
継続的に再生する場合は、read_playback_event() から再生 event を読み出し、
terminal になった generation を release_playback_generation() で解放します。
stream_health と get_pipeline_stats() は stream の稼働状態と処理の統計を返します。
License
duplex-audio の license は MIT です。
全文は LICENSE を参照してください。
Metadata
Release files for duplex-audio 0.16.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| duplex_audio-0.16.0-py3-none-any.whl | Python 3 | none | any | Details for duplex_audio-0.16.0-py3-none-any.whl |
Release files / duplex_audio-0.16.0-py3-none-any.whl
| Download URL | duplex_audio-0.16.0-py3-none-any.whl |
|---|---|
| Size | 44.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3a16d9ecf5bc1811f44fdfa8835717d4cfdc4fb6fd86f13b35a026cdc905baf9
|
|
BLAKE2b-256 checksum How to use checksums |
98b7c159112e304c92b312f8d109440d73ddac2f56756ba8394f86c1f259839f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for duplex-audio 0.16.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.