Skip to main content

Cross-platform audio playback/recording (C++/PortAudio/ASIO/WASAPI) with Python bindings

Project description

py-p-audio - Windows audio playback/recording with PortAudio/ASIO/WASAPI and Python bindings

概要 Windows上でオーディオのデバイス列挙・再生・録音(ASIO、WASAPIループバック)を提供するC++実装と、そのPythonバインディングです。CLI実行とPython APIの両方が利用できます。

インストール pipでインストール可能:

pip install py-p-audio

Pythonの使い方 デバイス一覧(標準出力へ表示)

import paudio
paudio.list_devices()

再生(非ブロッキング制御)

import time, paudio

p = paudio.Player()
p.load("C:/music/test.wav")
p.start()
while p.is_playing():
    time.sleep(0.1)
p.stop()

録音(非ブロッキング制御)

import time, paudio

r = paudio.Recorder()
# デフォルトデバイスへ録音
r.setup("C:/recordings/out.wav")
r.start()
time.sleep(5)
r.stop()

# ASIOでチャンネル範囲(1ベース)。例: 44-54 は11ch(10chなら 44-53)
# r.setup("C:/recordings/out.wav", device_index=5, channels=(44, 54))

APIリファレンス最新版

- モジュール関数ブロッキング
  - list_devices() -> None
    - このPCのデバイス一覧を標準出力に表示
    - 出力形式: `index,deviceType,inputOutput,deviceName,totalChannels[,LOOPBACK]`
      - deviceType: W=WASAPI, A=ASIO / inputOutput: I=入力, O=出力
  - play(file_path: str) -> None
    - WAVファイルを最後まで再生戻りは完了後
  - record(output_path: str, deviceIndex: int = -1, channels: tuple[int,int] = (-1,-1)) -> None
    - 録音を開始し停止までブロッキング
    - `channels` は1ベースの範囲ASIOのみ有効)。: `(44,54)` は11ch

- クラス非ブロッキング制御
  - Player
    - load(file_path: str) -> bool
    - start() -> None / stop() -> None
    - is_playing() -> bool
    - current_time() -> float
    - total_time() -> float
    - format_time(seconds: float) -> strHH:MM:SS
  - Recorder
    - setup(output_path: str) -> bool
    - setup(output_path: str, device_index: int, channels: tuple[int,int]) -> bool
      - `channels` は1ベースの範囲指定ASIOのみ有効)。: `(44,54)` は11ch10chなら `(44,53)`
    - start() / stop() -> None
    - is_recording() -> bool
    - current_time() -> float

主な機能

  • デバイス列挙(WASAPI/ASIO、WASAPIループバックの表示)
  • WAV再生(16/24/32bit PCM、簡易リサンプル)
  • 録音:
    • WASAPIループバック(システム音、2ch)
    • ASIO(チャンネル範囲指定対応、1ベース)

注意

  • WASAPIループバックは2ch固定です。
  • 通常WASAPI入力は先頭Nchの取得のみで、中腹からのチャンネル範囲指定は未対応です。

デバイス一覧の例

1,W,I,Microphone (Realtek Audio),2
2,A,I,ASIO4ALL v2,8
3,A,O,ASIO4ALL v2,8
4,W,O,Speakers (Realtek Audio) (WASAPI-Loopback),2,LOOPBACK

ライセンス MIT(本プロジェクト)。PortAudioおよびASIO SDKの各ライセンスに従います。

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

py_p_audio-0.1.3.tar.gz (5.6 MB view details)

Uploaded Source

Built Distribution

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

py_p_audio-0.1.3-cp311-cp311-win_amd64.whl (207.8 kB view details)

Uploaded CPython 3.11Windows x86-64

File details

Details for the file py_p_audio-0.1.3.tar.gz.

File metadata

  • Download URL: py_p_audio-0.1.3.tar.gz
  • Upload date:
  • Size: 5.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for py_p_audio-0.1.3.tar.gz
Algorithm Hash digest
SHA256 3e8cb11e0c020a9d39a16fae55fec79bd7047869ae81275809a4f5e29077dc1f
MD5 3f6cc86cebc200defbc487e65d82cf4a
BLAKE2b-256 a8761550686285d8920b86fa8a790224309dae4085f9e356f121aa0533d90330

See more details on using hashes here.

File details

Details for the file py_p_audio-0.1.3-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: py_p_audio-0.1.3-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 207.8 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for py_p_audio-0.1.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 ad4be193fad60dd3a5a22e3901f85c1ca4ec1315e1ad5f6a39c103338d244570
MD5 a78024766c589157e182957782f3fc8d
BLAKE2b-256 ead281093b3fc39dbabf2e5c1260a6cbd7267dd29f0b3fdc32f135dd181d5954

See more details on using hashes here.

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