Skip to main content

Python ctypes bindings for pulseaudio (libpulse).

Project description

Python 2.X ctypes bindings for PulseAudio (libpulse), forked from pulsemixer project (which had this code bundled) to re-use this awesome stuff in other projects.


Usage

Simple example:

from pulsectl import Pulse

with Pulse('volume-increaser') as pulse:
  for sink in pulse.sink_list():
    pulse.volume_change_all_chans(sink, 10)

Listening for server state change events:

from pulsectl import Pulse, PulseLoopStop

with Pulse('event-printer') as pulse:
  # print 'Event types:', ', '.join(pulse.event_types)
  # print 'Event facilities:', ', '.join(pulse.event_facilities)
  # print 'Event masks:', ', '.join(pulse.event_masks)

  def print_events(ev):
    print 'Pulse event:', ev
    ### Raise PulseLoopStop for event_listen() to return before timeout (if any)
    # raise PulseLoopStop

  pulse.event_mask_set('all')
  pulse.event_callback_set(print_events)
  pulse.event_listen(timeout=10)

Misc other tinkering:

>>> from pulsectl import Pulse
>>> pulse = Pulse('my-client-name')

>>> pulse.sink_list()
[<PulseSinkInfo at 7f85cfd053d0 - desc='Built-in Audio', index=0L, mute=0, name='alsa-speakers', channels=2, volumes='44.0%, 44.0%'>]

>>> pulse.sink_input_list()
[<PulseSinkInputInfo at 7fa06562d3d0 - index=181L, mute=0, name='mpv Media Player', channels=2, volumes='25.0%, 25.0%'>]

>>> pulse.sink_input_list()[0].proplist
{'application.icon_name': 'mpv',
 'application.language': 'C',
 'application.name': 'mpv Media Player',
 ...
 'native-protocol.version': '30',
 'window.x11.display': ':1.0'}

>>> pulse.source_list()
[<PulseSourceInfo at 7fcb0615d8d0 - desc='Monitor of Built-in Audio', index=0L, mute=0, name='alsa-speakers.monitor', channels=2, volumes='100.0%, 100.0%'>,
 <PulseSourceInfo at 7fcb0615da10 - desc='Built-in Audio', index=1L, mute=0, name='alsa-mic', channels=2, volumes='100.0%, 100.0%'>]

>>> sink = pulse.sink_list()[0]
>>> pulse.volume_change_all_chans(sink, -10)
>>> pulse.volume_set_all_chans(sink, 50)

>>> help(pulse)
...

Current code logic is that all methods are invoked through the Pulse instance, and everything returned from these are “Pulse-Something-Info” objects - thin wrappers around C structs that describe the thing, without any methods attached.

Module is relatively new and these high-level interfaces might change in the future.

Installation

It’s a regular package for Python 2.7 (not 3.X).

Using pip is the best way:

% pip install pulsectl

If you don’t have it, use:

% easy_install pip
% pip install pulsectl

Alternatively (see also pip2014.com and pip install guide):

% curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python2
% pip install pulsectl

Or, if you absolutely must:

% easy_install pulsectl

But, you really shouldn’t do that.

Current-git version can be installed like this:

% pip install 'git+https://github.com/mk-fg/python-pulse-control.git#egg=pulsectl'

Note that to install stuff in system-wide PATH and site-packages, elevated privileges are often required. Use “install –user”, ~/.pydistutils.cfg or virtualenv to do unprivileged installs into custom paths.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

pulsectl-16.1.31.tar.gz (12.3 kB view details)

Uploaded Source

File details

Details for the file pulsectl-16.1.31.tar.gz.

File metadata

  • Download URL: pulsectl-16.1.31.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pulsectl-16.1.31.tar.gz
Algorithm Hash digest
SHA256 0ab4d32f34ae8826d3f2f0cefa1de3f7492524862192856dc905b2062cfb3fd6
MD5 cc38655a755f178d74552dbabf2aa760
BLAKE2b-256 d48ee6c224542ea2790a1083865fc1b0ccc3097e985698a2acd6499b98d28bf7

See more details on using hashes here.

Provenance

Supported by

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