# py-p-audio-native
**高性能な Python オーディオライブラリ - ネイティブ C++ コア搭載**
Windows 環境で WASAPI と ASIO をサポートした、pybind11 ベースの高性能オーディオ録音・再生ライブラリです。
[](https://pypi.org/project/py-p-audio-native/)
[](https://pypi.org/project/py-p-audio-native/)
[](https://github.com/hiroshi-tamura/py-p-audio-native/blob/main/LICENSE)
## 特徴
- ✅ **ネイティブ C++ パフォーマンス**: pybind11 による高速な音声処理
- ✅ **外部依存関係なし**: PyAudio, sounddevice など不要
- ✅ **WASAPI & ASIO 対応**: 低レイテンシ・高音質録音
- ✅ **マルチチャンネル対応**: ステレオ〜8ch+ の録音・再生
- ✅ **ループバック録音**: システム音声キャプチャ
- ✅ **リアルタイム監視**: ピークレベル、録音時間の取得
- ✅ **簡潔な API**: 初心者にも使いやすい Python インターフェース
## インストール
```bash
pip install py-p-audio-native
```
## クイックスタート
### デバイス一覧
```python
import py_p_audio_native as ppa
# 利用可能なオーディオデバイス表示
devices = ppa.list_devices()
for device in devices:
print(f"[{device.index}] {device.name} ({device.api_name})")
if device.max_input_channels > 0:
print(f" → 入力: {device.max_input_channels}ch")
if device.max_output_channels > 0:
print(f" → 出力: {device.max_output_channels}ch")
```
### シンプル録音
```python
# デフォルトマイクで 5秒録音
ppa.record(duration=5.0, output_file="recording.wav")
# 高音質・デバイス指定録音
ppa.record(
duration=10.0,
output_file="high_quality.wav",
device_index=1, # デバイス番号
sample_rate=48000, # 48kHz
channels=2, # ステレオ
bit_depth=24 # 24ビット
)
```
### システム音声録音
```python
# コンピュータの音声出力をそのまま録音
ppa.record_loopback(duration=10.0, output_file="system_audio.wav")
```
### 音声再生
```python
# ファイル再生
ppa.play("recording.wav")
# デバイス指定再生
ppa.play("music.wav", device_index=2)
```
## 詳細制御
### 高度な録音制御
```python
# Recorder クラスで詳細制御
recorder = ppa.Recorder(
device_index=0, # 入力デバイス
sample_rate=44100, # サンプリング周波数
channels=2, # チャンネル数
bit_depth=16, # ビット深度
buffer_size=1024 # バッファサイズ
)
recorder.setup()
recorder.start_recording("live.wav")
# リアルタイム監視
import time
while recorder.is_recording():
time_elapsed = recorder.get_recording_time()
peak_level = recorder.get_peak_level()
print(f"録音時間: {time_elapsed:.1f}s, レベル: {peak_level:.2f}")
if time_elapsed >= 10.0:
recorder.stop_recording()
break
time.sleep(0.5)
```
### ASIO デバイスで最高音質
```python
# ASIO デバイス検索
devices = ppa.list_devices()
asio_device = None
for device in devices:
if "ASIO" in device.api_name:
asio_device = device
break
if asio_device:
ppa.record(
duration=30.0,
output_file="studio_quality.wav",
device_index=asio_device.index,
sample_rate=96000, # 96kHz
channels=8, # 8ch
bit_depth=32 # 32ビット
)
```
### プログレスコールバック
```python
def progress_callback(progress, status):
print(f"進捗: {progress:.1f}%, ステータス: {status}")
recorder = ppa.Recorder()
recorder.set_progress_callback(progress_callback)
recorder.record(duration=5.0, output_file="with_callback.wav")
```
## API リファレンス
### 基本関数
- `list_devices()` - デバイス一覧取得
- `get_device_info(index)` - デバイス情報取得
- `find_device(name)` - デバイス名検索
- `record(duration, file, ...)` - シンプル録音
- `record_loopback(duration, file, ...)` - システム音声録音
- `play(file, device_index)` - 音声再生
### クラス
- `Recorder` - 詳細録音制御
- `LoopbackRecorder` - システム音声録音制御
- `Player` - 音声再生制御
- `AudioDevice` - デバイス情報
### 例外
- `DeviceError` - デバイス関連エラー
- `RecordingError` - 録音エラー
- `PlaybackError` - 再生エラー
- `FileError` - ファイル操作エラー
## 使用例
### USB マイク録音
```python
# USB マイクを見つけて録音
usb_mic = ppa.find_device("USB")
if usb_mic:
ppa.record(
duration=5.0,
output_file="usb_recording.wav",
device_index=usb_mic.index
)
```
### マルチチャンネル録音
```python
# 8チャンネル同時録音
ppa.record(
duration=60.0,
output_file="8ch_recording.wav",
device_index=2,
channels=8,
sample_rate=48000,
bit_depth=24
)
```
### 長時間録音監視
```python
recorder = ppa.Recorder(device_index=0)
recorder.setup()
recorder.start_recording("long_recording.wav")
try:
while recorder.is_recording():
level = recorder.get_peak_level()
time_elapsed = recorder.get_recording_time()
# ピークレベル可視化
bar_length = int(level * 50)
bar = "█" * bar_length + "░" * (50 - bar_length)
print(f"\r時間: {time_elapsed:6.1f}s |{bar}| {level:.2f}", end="")
time.sleep(0.1)
except KeyboardInterrupt:
recorder.stop_recording()
print("\n録音完了")
```
## 対応環境
- **OS**: Windows 10/11 (x64)
- **Python**: 3.8, 3.9, 3.10, 3.11, 3.12
- **アーキテクチャ**: x64
- **API**: WASAPI, ASIO
## ドキュメント
- [クイックスタートガイド](docs/quick_start.md)
- [詳細使用方法](docs/advanced_usage.md)
- [ビルドガイド](build_guide.md)
## ライセンス
MIT License - 詳細は [LICENSE](LICENSE) を参照
## 貢献
プルリクエストやイシュー報告を歓迎します。
## 作者
hiroshi-tamura
---
**高性能・低レイテンシな音声処理が必要なアプリケーション開発に最適です。**
Raw data
{
"_id": null,
"home_page": "https://github.com/hiroshi-tamura/py-p-audio-native",
"name": "py-p-audio-native",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "audio, recording, playback, WASAPI, ASIO, native, pybind11",
"author": "hiroshi-tamura",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/2f/b2/17b3a986127e88aacf1e49e4b993cfcdd0c429b330eca9f03bb100bbe443/py_p_audio_native-2.0.4.tar.gz",
"platform": null,
"description": "# py-p-audio-native\r\n\r\n**\u9ad8\u6027\u80fd\u306a Python \u30aa\u30fc\u30c7\u30a3\u30aa\u30e9\u30a4\u30d6\u30e9\u30ea - \u30cd\u30a4\u30c6\u30a3\u30d6 C++ \u30b3\u30a2\u642d\u8f09**\r\n\r\nWindows \u74b0\u5883\u3067 WASAPI \u3068 ASIO \u3092\u30b5\u30dd\u30fc\u30c8\u3057\u305f\u3001pybind11 \u30d9\u30fc\u30b9\u306e\u9ad8\u6027\u80fd\u30aa\u30fc\u30c7\u30a3\u30aa\u9332\u97f3\u30fb\u518d\u751f\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3059\u3002\r\n\r\n[](https://pypi.org/project/py-p-audio-native/)\r\n[](https://pypi.org/project/py-p-audio-native/)\r\n[](https://github.com/hiroshi-tamura/py-p-audio-native/blob/main/LICENSE)\r\n\r\n## \u7279\u5fb4\r\n\r\n- \u2705 **\u30cd\u30a4\u30c6\u30a3\u30d6 C++ \u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9**: pybind11 \u306b\u3088\u308b\u9ad8\u901f\u306a\u97f3\u58f0\u51e6\u7406\r\n- \u2705 **\u5916\u90e8\u4f9d\u5b58\u95a2\u4fc2\u306a\u3057**: PyAudio, sounddevice \u306a\u3069\u4e0d\u8981\r\n- \u2705 **WASAPI & ASIO \u5bfe\u5fdc**: \u4f4e\u30ec\u30a4\u30c6\u30f3\u30b7\u30fb\u9ad8\u97f3\u8cea\u9332\u97f3\r\n- \u2705 **\u30de\u30eb\u30c1\u30c1\u30e3\u30f3\u30cd\u30eb\u5bfe\u5fdc**: \u30b9\u30c6\u30ec\u30aa\u301c8ch+ \u306e\u9332\u97f3\u30fb\u518d\u751f\r\n- \u2705 **\u30eb\u30fc\u30d7\u30d0\u30c3\u30af\u9332\u97f3**: \u30b7\u30b9\u30c6\u30e0\u97f3\u58f0\u30ad\u30e3\u30d7\u30c1\u30e3\r\n- \u2705 **\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u76e3\u8996**: \u30d4\u30fc\u30af\u30ec\u30d9\u30eb\u3001\u9332\u97f3\u6642\u9593\u306e\u53d6\u5f97\r\n- \u2705 **\u7c21\u6f54\u306a API**: \u521d\u5fc3\u8005\u306b\u3082\u4f7f\u3044\u3084\u3059\u3044 Python \u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\r\n\r\n## \u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\r\n\r\n```bash\r\npip install py-p-audio-native\r\n```\r\n\r\n## \u30af\u30a4\u30c3\u30af\u30b9\u30bf\u30fc\u30c8\r\n\r\n### \u30c7\u30d0\u30a4\u30b9\u4e00\u89a7\r\n\r\n```python\r\nimport py_p_audio_native as ppa\r\n\r\n# \u5229\u7528\u53ef\u80fd\u306a\u30aa\u30fc\u30c7\u30a3\u30aa\u30c7\u30d0\u30a4\u30b9\u8868\u793a\r\ndevices = ppa.list_devices()\r\nfor device in devices:\r\n print(f\"[{device.index}] {device.name} ({device.api_name})\")\r\n if device.max_input_channels > 0:\r\n print(f\" \u2192 \u5165\u529b: {device.max_input_channels}ch\")\r\n if device.max_output_channels > 0:\r\n print(f\" \u2192 \u51fa\u529b: {device.max_output_channels}ch\")\r\n```\r\n\r\n### \u30b7\u30f3\u30d7\u30eb\u9332\u97f3\r\n\r\n```python\r\n# \u30c7\u30d5\u30a9\u30eb\u30c8\u30de\u30a4\u30af\u3067 5\u79d2\u9332\u97f3\r\nppa.record(duration=5.0, output_file=\"recording.wav\")\r\n\r\n# \u9ad8\u97f3\u8cea\u30fb\u30c7\u30d0\u30a4\u30b9\u6307\u5b9a\u9332\u97f3\r\nppa.record(\r\n duration=10.0,\r\n output_file=\"high_quality.wav\",\r\n device_index=1, # \u30c7\u30d0\u30a4\u30b9\u756a\u53f7\r\n sample_rate=48000, # 48kHz\r\n channels=2, # \u30b9\u30c6\u30ec\u30aa\r\n bit_depth=24 # 24\u30d3\u30c3\u30c8\r\n)\r\n```\r\n\r\n### \u30b7\u30b9\u30c6\u30e0\u97f3\u58f0\u9332\u97f3\r\n\r\n```python\r\n# \u30b3\u30f3\u30d4\u30e5\u30fc\u30bf\u306e\u97f3\u58f0\u51fa\u529b\u3092\u305d\u306e\u307e\u307e\u9332\u97f3\r\nppa.record_loopback(duration=10.0, output_file=\"system_audio.wav\")\r\n```\r\n\r\n### \u97f3\u58f0\u518d\u751f\r\n\r\n```python\r\n# \u30d5\u30a1\u30a4\u30eb\u518d\u751f\r\nppa.play(\"recording.wav\")\r\n\r\n# \u30c7\u30d0\u30a4\u30b9\u6307\u5b9a\u518d\u751f\r\nppa.play(\"music.wav\", device_index=2)\r\n```\r\n\r\n## \u8a73\u7d30\u5236\u5fa1\r\n\r\n### \u9ad8\u5ea6\u306a\u9332\u97f3\u5236\u5fa1\r\n\r\n```python\r\n# Recorder \u30af\u30e9\u30b9\u3067\u8a73\u7d30\u5236\u5fa1\r\nrecorder = ppa.Recorder(\r\n device_index=0, # \u5165\u529b\u30c7\u30d0\u30a4\u30b9\r\n sample_rate=44100, # \u30b5\u30f3\u30d7\u30ea\u30f3\u30b0\u5468\u6ce2\u6570\r\n channels=2, # \u30c1\u30e3\u30f3\u30cd\u30eb\u6570\r\n bit_depth=16, # \u30d3\u30c3\u30c8\u6df1\u5ea6\r\n buffer_size=1024 # \u30d0\u30c3\u30d5\u30a1\u30b5\u30a4\u30ba\r\n)\r\n\r\nrecorder.setup()\r\nrecorder.start_recording(\"live.wav\")\r\n\r\n# \u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u76e3\u8996\r\nimport time\r\nwhile recorder.is_recording():\r\n time_elapsed = recorder.get_recording_time()\r\n peak_level = recorder.get_peak_level()\r\n print(f\"\u9332\u97f3\u6642\u9593: {time_elapsed:.1f}s, \u30ec\u30d9\u30eb: {peak_level:.2f}\")\r\n \r\n if time_elapsed >= 10.0:\r\n recorder.stop_recording()\r\n break\r\n time.sleep(0.5)\r\n```\r\n\r\n### ASIO \u30c7\u30d0\u30a4\u30b9\u3067\u6700\u9ad8\u97f3\u8cea\r\n\r\n```python\r\n# ASIO \u30c7\u30d0\u30a4\u30b9\u691c\u7d22\r\ndevices = ppa.list_devices()\r\nasio_device = None\r\nfor device in devices:\r\n if \"ASIO\" in device.api_name:\r\n asio_device = device\r\n break\r\n\r\nif asio_device:\r\n ppa.record(\r\n duration=30.0,\r\n output_file=\"studio_quality.wav\",\r\n device_index=asio_device.index,\r\n sample_rate=96000, # 96kHz\r\n channels=8, # 8ch\r\n bit_depth=32 # 32\u30d3\u30c3\u30c8\r\n )\r\n```\r\n\r\n### \u30d7\u30ed\u30b0\u30ec\u30b9\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\r\n\r\n```python\r\ndef progress_callback(progress, status):\r\n print(f\"\u9032\u6357: {progress:.1f}%, \u30b9\u30c6\u30fc\u30bf\u30b9: {status}\")\r\n\r\nrecorder = ppa.Recorder()\r\nrecorder.set_progress_callback(progress_callback)\r\nrecorder.record(duration=5.0, output_file=\"with_callback.wav\")\r\n```\r\n\r\n## API \u30ea\u30d5\u30a1\u30ec\u30f3\u30b9\r\n\r\n### \u57fa\u672c\u95a2\u6570\r\n\r\n- `list_devices()` - \u30c7\u30d0\u30a4\u30b9\u4e00\u89a7\u53d6\u5f97\r\n- `get_device_info(index)` - \u30c7\u30d0\u30a4\u30b9\u60c5\u5831\u53d6\u5f97\r\n- `find_device(name)` - \u30c7\u30d0\u30a4\u30b9\u540d\u691c\u7d22\r\n- `record(duration, file, ...)` - \u30b7\u30f3\u30d7\u30eb\u9332\u97f3\r\n- `record_loopback(duration, file, ...)` - \u30b7\u30b9\u30c6\u30e0\u97f3\u58f0\u9332\u97f3\r\n- `play(file, device_index)` - \u97f3\u58f0\u518d\u751f\r\n\r\n### \u30af\u30e9\u30b9\r\n\r\n- `Recorder` - \u8a73\u7d30\u9332\u97f3\u5236\u5fa1\r\n- `LoopbackRecorder` - \u30b7\u30b9\u30c6\u30e0\u97f3\u58f0\u9332\u97f3\u5236\u5fa1 \r\n- `Player` - \u97f3\u58f0\u518d\u751f\u5236\u5fa1\r\n- `AudioDevice` - \u30c7\u30d0\u30a4\u30b9\u60c5\u5831\r\n\r\n### \u4f8b\u5916\r\n\r\n- `DeviceError` - \u30c7\u30d0\u30a4\u30b9\u95a2\u9023\u30a8\u30e9\u30fc\r\n- `RecordingError` - \u9332\u97f3\u30a8\u30e9\u30fc\r\n- `PlaybackError` - \u518d\u751f\u30a8\u30e9\u30fc\r\n- `FileError` - \u30d5\u30a1\u30a4\u30eb\u64cd\u4f5c\u30a8\u30e9\u30fc\r\n\r\n## \u4f7f\u7528\u4f8b\r\n\r\n### USB \u30de\u30a4\u30af\u9332\u97f3\r\n\r\n```python\r\n# USB \u30de\u30a4\u30af\u3092\u898b\u3064\u3051\u3066\u9332\u97f3\r\nusb_mic = ppa.find_device(\"USB\")\r\nif usb_mic:\r\n ppa.record(\r\n duration=5.0,\r\n output_file=\"usb_recording.wav\",\r\n device_index=usb_mic.index\r\n )\r\n```\r\n\r\n### \u30de\u30eb\u30c1\u30c1\u30e3\u30f3\u30cd\u30eb\u9332\u97f3\r\n\r\n```python\r\n# 8\u30c1\u30e3\u30f3\u30cd\u30eb\u540c\u6642\u9332\u97f3\r\nppa.record(\r\n duration=60.0,\r\n output_file=\"8ch_recording.wav\",\r\n device_index=2,\r\n channels=8,\r\n sample_rate=48000,\r\n bit_depth=24\r\n)\r\n```\r\n\r\n### \u9577\u6642\u9593\u9332\u97f3\u76e3\u8996\r\n\r\n```python\r\nrecorder = ppa.Recorder(device_index=0)\r\nrecorder.setup()\r\nrecorder.start_recording(\"long_recording.wav\")\r\n\r\ntry:\r\n while recorder.is_recording():\r\n level = recorder.get_peak_level()\r\n time_elapsed = recorder.get_recording_time()\r\n \r\n # \u30d4\u30fc\u30af\u30ec\u30d9\u30eb\u53ef\u8996\u5316\r\n bar_length = int(level * 50)\r\n bar = \"\u2588\" * bar_length + \"\u2591\" * (50 - bar_length)\r\n print(f\"\\r\u6642\u9593: {time_elapsed:6.1f}s |{bar}| {level:.2f}\", end=\"\")\r\n \r\n time.sleep(0.1)\r\nexcept KeyboardInterrupt:\r\n recorder.stop_recording()\r\n print(\"\\n\u9332\u97f3\u5b8c\u4e86\")\r\n```\r\n\r\n## \u5bfe\u5fdc\u74b0\u5883\r\n\r\n- **OS**: Windows 10/11 (x64)\r\n- **Python**: 3.8, 3.9, 3.10, 3.11, 3.12\r\n- **\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3**: x64\r\n- **API**: WASAPI, ASIO\r\n\r\n## \u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\r\n\r\n- [\u30af\u30a4\u30c3\u30af\u30b9\u30bf\u30fc\u30c8\u30ac\u30a4\u30c9](docs/quick_start.md)\r\n- [\u8a73\u7d30\u4f7f\u7528\u65b9\u6cd5](docs/advanced_usage.md)\r\n- [\u30d3\u30eb\u30c9\u30ac\u30a4\u30c9](build_guide.md)\r\n\r\n## \u30e9\u30a4\u30bb\u30f3\u30b9\r\n\r\nMIT License - \u8a73\u7d30\u306f [LICENSE](LICENSE) \u3092\u53c2\u7167\r\n\r\n## \u8ca2\u732e\r\n\r\n\u30d7\u30eb\u30ea\u30af\u30a8\u30b9\u30c8\u3084\u30a4\u30b7\u30e5\u30fc\u5831\u544a\u3092\u6b53\u8fce\u3057\u307e\u3059\u3002\r\n\r\n## \u4f5c\u8005\r\n\r\nhiroshi-tamura\r\n\r\n---\r\n\r\n**\u9ad8\u6027\u80fd\u30fb\u4f4e\u30ec\u30a4\u30c6\u30f3\u30b7\u306a\u97f3\u58f0\u51e6\u7406\u304c\u5fc5\u8981\u306a\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u958b\u767a\u306b\u6700\u9069\u3067\u3059\u3002**\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "\u9ad8\u6027\u80fd\u306a Python \u30aa\u30fc\u30c7\u30a3\u30aa\u30e9\u30a4\u30d6\u30e9\u30ea - \u30cd\u30a4\u30c6\u30a3\u30d6 C++ \u30b3\u30a2\u642d\u8f09",
"version": "2.0.4",
"project_urls": {
"Homepage": "https://github.com/hiroshi-tamura/py-p-audio-native",
"Issues": "https://github.com/hiroshi-tamura/py-p-audio-native/issues",
"Repository": "https://github.com/hiroshi-tamura/py-p-audio-native.git"
},
"split_keywords": [
"audio",
" recording",
" playback",
" wasapi",
" asio",
" native",
" pybind11"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "86675f4b15618db64105e4fdbf1a6fdd17df2ccbf95439af1aa024b1266cb56d",
"md5": "9aade43e918b6d30fc64d469cc368618",
"sha256": "4ab521223b4c96f3d36c1694c4c2c05c66bf6c2e21cb165f0ea7a3f939189dd1"
},
"downloads": -1,
"filename": "py_p_audio_native-2.0.4-cp311-cp311-win_amd64.whl",
"has_sig": false,
"md5_digest": "9aade43e918b6d30fc64d469cc368618",
"packagetype": "bdist_wheel",
"python_version": "cp311",
"requires_python": ">=3.8",
"size": 440190,
"upload_time": "2025-08-22T10:37:13",
"upload_time_iso_8601": "2025-08-22T10:37:13.385403Z",
"url": "https://files.pythonhosted.org/packages/86/67/5f4b15618db64105e4fdbf1a6fdd17df2ccbf95439af1aa024b1266cb56d/py_p_audio_native-2.0.4-cp311-cp311-win_amd64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "2fb217b3a986127e88aacf1e49e4b993cfcdd0c429b330eca9f03bb100bbe443",
"md5": "3698cedcc6fb9d708f73b3767ed49d39",
"sha256": "4f884f33da0e997b1414e301bbcbfc0656058fe6294cbc489a6174bb202dca69"
},
"downloads": -1,
"filename": "py_p_audio_native-2.0.4.tar.gz",
"has_sig": false,
"md5_digest": "3698cedcc6fb9d708f73b3767ed49d39",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 92850,
"upload_time": "2025-08-22T10:37:14",
"upload_time_iso_8601": "2025-08-22T10:37:14.858891Z",
"url": "https://files.pythonhosted.org/packages/2f/b2/17b3a986127e88aacf1e49e4b993cfcdd0c429b330eca9f03bb100bbe443/py_p_audio_native-2.0.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-22 10:37:14",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "hiroshi-tamura",
"github_project": "py-p-audio-native",
"github_not_found": true,
"lcname": "py-p-audio-native"
}