Skip to main content

PyALSoft

CI status PyPI version Supported Python versions

OpenAL Soft 1.25.2

PyALSoft provides function-oriented managed playback and capture APIs, plus typed bindings for OpenAL Soft, including core OpenAL, ALC, EFX, and supported extensions. The managed API lives at the package root; the complete low-level interface remains available through pyalsoft.bindings.

PyALSoft is an independent project and is not affiliated with or endorsed by the OpenAL Soft project.

Installation

PyALSoft requires Python 3.12 or later.

python3 -m pip install pyalsoft

Quick start

play starts a WAV file immediately and returns an optional control handle:

import time

from pyalsoft import play

sound = play("sound.wav")
while sound.playing:
    time.sleep(0.1)

Playback is asynchronous. If no control is needed, the return value can be ignored without stopping the sound:

play("notification.wav")

The returned PlayingSound has transport, timeline, gain, pitch, looping, and spatial controls. The convenience API supports uncompressed mono or stereo WAV files containing 8-bit unsigned or 16-bit signed PCM. It opens its default audio session lazily, reuses clips loaded from the same resolved path, and releases it automatically at process exit. Applications can call shutdown() to close it earlier.

Controlling one sound

Every VoiceConfig field can also be passed directly to play. Direct keywords override the corresponding field when both forms are used:

sound = play(
    "engine.wav",
    gain=0.7,
    pitch=1.1,
    looping=True,
    relative=True,
    position=(-2.0, 0.0, -4.0),
    reference_distance=1.0,
    max_distance=20.0,
    rolloff_factor=1.0,
)

sound.position = (2.0, 0.0, -4.0)
sound.pitch = 1.25
sound.seek(3.0)

# Group changes made in the same application update. Only changed OpenAL
# properties are sent to the backend.
sound.update(
    position=(3.0, 0.0, -2.0),
    velocity=(1.0, 0.0, 0.0),
    gain=0.6,
)

offset_seconds is the playhead position on the original source-audio timeline. It is not elapsed wall-clock time. For example, at pitch=2.0 the offset advances two source seconds per wall-clock second, while duration_seconds remains unchanged. remaining_seconds and progress use the same source timeline. For sample-accurate work, use offset_frames, remaining_frames, frame_count, and seek_frames(). rewind() follows OpenAL behavior by moving to the beginning and entering the INITIAL state; restart() moves to the beginning and immediately plays.

Format and length information is available without opening an audio device:

from pyalsoft import get_sound_info

info = get_sound_info("engine.wav")
print(info.duration_seconds, info.frame_count)
print(info.channels, info.sample_rate, info.bit_depth)

The same immutable SoundInfo is available as clip.info and sound.info. PlayingSound also exposes path, channels, sample_rate, and sample_type. When a sound ends, end_reason distinguishes natural completion, an explicit stop(), runtime shutdown, and a disconnected device when the backend supports connection reporting. Stopped sounds retain their configuration, so controls can be changed before rewind() or restart() creates another native source.

The spatial controls describe a sound relative to the playback listener:

Control Meaning
position The sound's (x, y, z) location. By default, +X is right, +Y is up, and -Z is forward.
velocity Motion, in coordinate units per second, used for Doppler shift. It does not automatically update position.
direction The vector the sound's directional cone points along. (0, 0, 0) makes it omnidirectional.
relative When true, position, velocity, and direction use listener-local coordinates; otherwise they use world coordinates.
reference_distance The reference point where distance attenuation has unity gain. Clamped models keep unity distance gain at closer distances.
max_distance The outer distance used by clamped distance models; attenuation no longer changes beyond it.
rolloff_factor Scales distance attenuation. 0 disables distance rolloff; larger values attenuate more rapidly.
min_gain, max_gain Lower and upper clamps applied after distance and cone attenuation.
cone_inner_angle Full angle, in degrees, inside which direction causes no cone attenuation.
cone_outer_angle Full angle beyond which the outer-cone gain is used; OpenAL interpolates between the two angles.
cone_outer_gain Gain multiplier used when the listener is outside the outer cone.

Gain is a linear amplitude multiplier: 1.0 is unchanged, 0.5 is about -6 dB, and 0.0 is silent. Pitch changes playback rate and audible pitch together; OpenAL does not perform independent time stretching.

For conventional positional audio, use a mono sound. OpenAL normally plays stereo sources without applying 3D position or direction.

The convenience runtime's listener and global distance/Doppler behavior can be configured without opening an explicit Playback:

from pyalsoft import (
    Acoustics,
    DistanceModel,
    Listener,
    set_acoustics,
    set_listener,
    update_listener,
)

set_listener(Listener(position=(0.0, 1.7, 0.0)))
set_acoustics(
    Acoustics(
        distance_model=DistanceModel.INVERSE_CLAMPED,
        doppler_factor=1.0,
        speed_of_sound=343.3,
    )
)
update_listener(position=(2.0, 1.7, 0.0))

get_listener(), get_acoustics(), update_listener(), and update_acoustics() operate on the convenience runtime by default. Pass an explicit Playback as the first argument to use that session instead.

The complete example is available as examples/play_file.py and can be run from a source checkout with:

uv run python examples/play_file.py

Recording

The managed capture API collects audio in memory while your application does other work. Native capture buffers are drained on a background thread, so the common API returns one PCM value instead of exposing chunks:

from pyalsoft import start_recording, stop_recording

recording = start_recording()
input("Speak now, then press Enter to stop... ")
captured = stop_recording(recording)

start_recording uses the default input device and records 48 kHz, mono, 16-bit PCM unless told otherwise. Use list_capture_devices() to select a specific input. For a known duration, record(3.0) is the blocking equivalent. Captured and generated PCM values can be passed directly to play:

sound = play(captured)

examples/record_and_play.py records until Enter is pressed and then plays the complete recording:

uv run python examples/record_and_play.py

Explicit playback sessions

Applications that generate audio, stream it, select a device, or require fully explicit resource lifetimes can use the underlying managed API directly:

from pyalsoft import PCM, open_playback, play, release, upload

pcm = PCM(
    # Half a second of mono silence; replace with your application's PCM bytes.
    samples=b"\0\0" * 22_050,
    channels=1,
    sample_rate=44_100,
)

with open_playback() as playback:
    clip = upload(playback, pcm)
    voice = play(playback, clip)
    # Query or control the voice here.
    release(playback, voice)
    release(playback, clip)

Device selection and HRTF

Playback devices can be enumerated and passed to open_playback. Context preferences such as HRTF are requested with PlaybackConfig; query PlaybackInfo to see what the audio backend actually enabled:

from pyalsoft import (
    PlaybackConfig,
    get_playback_info,
    list_playback_devices,
    open_playback,
)

devices = list_playback_devices()
selected = next((device for device in devices if device.is_default), None)

with open_playback(selected, config=PlaybackConfig(hrtf=True)) as playback:
    info = get_playback_info(playback)
    print(info.device_name, info.hrtf_status.value, info.hrtf_name)

See examples/play_sine.py, examples/move_sine.py, and examples/stream_sine.py for complete explicit API examples. Device selection and HRTF are demonstrated in examples/select_device_hrtf.py.

API layers

Automatically generated ctypes bindings for OpenAL live at pyalsoft.bindings. The same namespace also provides owned playback, capture, loopback, and context handles for deterministic native resource lifetimes. See the owned backend handle guide and the generated bindings reference.

pyalsoft holds the hand authored Python API, intended to make working with the library more Pythonic and manageable.

Contributing

Direct development occurs on development, the base branch of the repository. Pull requests from there to master represent official releases, signified by a version increase in pyproject.toml. Version increases should only be done from development. If implementing your own feature, it is requested that you fork this repository and make your own feature branch, and then merge into development.

Create the locked development environment with uv:

uv sync --python 3.12

Before submitting a change, run the same core checks as CI:

uv run pytest
uv run ruff check .
uv run ruff format --check .
uv run mypy
uv run python tools/generate_bindings.py --check
uv run python tools/sync_openal_soft.py --check

Bindings and docs/reference.md are generated from the vendored OpenAL registry plus reviewed corrections in tools/semantic_overrides.toml. After changing the generator, registry, or overrides, regenerate them with:

uv run python tools/generate_bindings.py

See the repository tool guide for the purpose and structure of each development and release command.

License

PyALSoft's original Python code is available under the MIT License. Bundled OpenAL Soft and other third-party components remain under their respective licenses. The distribution includes the complete license texts and a third-party notice.

Download files

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

Source Distribution

pyalsoft-0.8.0.tar.gz (3.0 MB view details)

Uploaded Source

Built Distributions

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

pyalsoft-0.8.0-py3-none-win_amd64.whl (1.7 MB view details)

Uploaded Python 3Windows x86-64

pyalsoft-0.8.0-py3-none-manylinux_2_28_x86_64.whl (1.8 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ x86-64

pyalsoft-0.8.0-py3-none-manylinux_2_28_aarch64.whl (1.7 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARM64

pyalsoft-0.8.0-py3-none-macosx_11_0_arm64.whl (863.9 kB view details)

Uploaded Python 3macOS 11.0+ ARM64

pyalsoft-0.8.0-py3-none-macosx_10_13_x86_64.whl (948.3 kB view details)

Uploaded Python 3macOS 10.13+ x86-64

File details

Details for the file pyalsoft-0.8.0.tar.gz.

File metadata

  • Download URL: pyalsoft-0.8.0.tar.gz
  • Upload date:
  • Size: 3.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pyalsoft-0.8.0.tar.gz
Algorithm Hash digest
SHA256 1a23889a84e0789eda3eea97bf717d7bb4f6f909e154a3645797cb919bb61f9c
MD5 d65d130d19800ac85ac0e17412dc2528
BLAKE2b-256 b5b0bcef076f79506719d545cf8cf984e29a3045f78b39af7895a3c417b3fa83

See more details on using hashes here.

File details

Details for the file pyalsoft-0.8.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: pyalsoft-0.8.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pyalsoft-0.8.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 ae4151eeb4143ffe6f1ed9a09099fd95518cfc58b470253eeac16e7cab59769f
MD5 2df522a213faa667cf137b011190e445
BLAKE2b-256 b71c69db11ba85a4dc2b79013bb2904dfc46bb8ea15055836921412fb6dc4a13

See more details on using hashes here.

File details

Details for the file pyalsoft-0.8.0-py3-none-manylinux_2_28_x86_64.whl.

File metadata

  • Download URL: pyalsoft-0.8.0-py3-none-manylinux_2_28_x86_64.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: Python 3, manylinux: glibc 2.28+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pyalsoft-0.8.0-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 61a77fd4ba4bcebd4a07828d61b5bd052fe0b9a1900d273e769c235a1341717c
MD5 fd4e375af5acc4832a31bfd45e5cf6df
BLAKE2b-256 8819e9c732e998bc195a84639b79f4fa5411f85687251816038663e82a5f591b

See more details on using hashes here.

File details

Details for the file pyalsoft-0.8.0-py3-none-manylinux_2_28_aarch64.whl.

File metadata

  • Download URL: pyalsoft-0.8.0-py3-none-manylinux_2_28_aarch64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: Python 3, manylinux: glibc 2.28+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pyalsoft-0.8.0-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 bcf170db158f0f5a31bd91613dae4f0329cd466bdf1ae3d3d637d0094ed3043f
MD5 b406f0ae371dfbe2ffca48e5d85472a4
BLAKE2b-256 024b64e2c83081c11422b31539eb92bbb6d32642fd3d9d6ae4a655ab08edea14

See more details on using hashes here.

File details

Details for the file pyalsoft-0.8.0-py3-none-macosx_11_0_arm64.whl.

File metadata

  • Download URL: pyalsoft-0.8.0-py3-none-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 863.9 kB
  • Tags: Python 3, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pyalsoft-0.8.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f856f683c31a9a893daa4f708143ff937fce98d53042bd31700dc59068d1535a
MD5 daacb4a0c9f1314c57e1d48d55f986b4
BLAKE2b-256 e8447239939f9db326cb96d234f981fd5983df5d645d71912e76d649efa18d30

See more details on using hashes here.

File details

Details for the file pyalsoft-0.8.0-py3-none-macosx_10_13_x86_64.whl.

File metadata

  • Download URL: pyalsoft-0.8.0-py3-none-macosx_10_13_x86_64.whl
  • Upload date:
  • Size: 948.3 kB
  • Tags: Python 3, macOS 10.13+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pyalsoft-0.8.0-py3-none-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 95d20b97e7f0dc0b9ce456a7409a58126fbe6655e19551188e6e68e3f34e2326
MD5 419bf9b34cbd70fe0e44ab912205fa3b
BLAKE2b-256 8c8b030279b5fd85e36929fc4fce35317242531bf091cb0e3c1f9624142fbcf9

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 Sentry Error logging StatusPage Status page