mk-fg / python-pulse-control

Python high-level interface and ctypes-based bindings for PulseAudio (libpulse)
https://pypi.org/project/pulsectl/
MIT License
170 stars 36 forks source link

set-card-profile feature request #14

Closed leifliddy closed 7 years ago

leifliddy commented 7 years ago

I found your project extremely helpful --thank you!!! I'd like to request that a set-card-profile feature be implemented that would allow you to change the audio profile on a bluetooth device {headset_head_unit, a2dp_sink, off}

https://github.com/GeorgeFilipkin/pulsemixer/ pulsemixer allows you to change the card-profile within the curses interface. Since this project is forked from pulsemixer, perhaps it would be possible to port that feature over?

I'd like to use this feature in an AlexaPI fork I'm working on --so that the audio profile can change based on whether Alexa is speaking or listening.

mk-fg commented 7 years ago

Thanks. Yeah, should be easy to add a wrapper for it, will do in a bit.

mk-fg commented 7 years ago

Added PulseCardProfileInfo objects, PulseCardInfo profile_list/profile_active attributes and pulse.card_profile_set(card, profile) wrapper to easily change these in aaafb10 (17.1.3).

You can use it like this (example from the README):

>>> from pulsectl import Pulse
>>> pulse = Pulse('profile-changer')

>>> card = pulse.card_list()[0]
>>> card.profile_list
[<PulseCardProfileInfo at 7f02e7e88ac8 - description='Analog Stereo Input', n_sinks=0, n_sources=1, name='input:analog-stereo', priority=60>,
 <PulseCardProfileInfo at 7f02e7e88b70 - description='Analog Stereo Output', n_sinks=1, n_sources=0, name='output:analog-stereo', priority=6000>,
 ...
 <PulseCardProfileInfo at 7f02e7e9a4e0 - description='Off', n_sinks=0, n_sources=0, name='off', priority=0>]

>>> pulse.card_profile_set(card, 'output:hdmi-stereo')

pulse.card_profile_set can be passed either PulseCardProfileInfo object or just profile name string (as per example above).

ctypes wrapper was indeed already there, copied from pulsemixer code, just needed to add high-level objects/methods to call it.

Please reopen if there'll be any issue there. Thanks!

mk-fg commented 7 years ago

I'd like to use this feature in an AlexaPI fork I'm working on --so that the audio profile can change based on whether Alexa is speaking or listening.

Don't know what you're doing there of course, but looking at how AlexaPI works, don't really see why you'd need to be changing card profiles there.

On a generic system, default profile should be something like "output:analog-stereo+input:analog-stereo" or "output:hdmi-stereo+input:analog-stereo" depending on plugged cables, which should allow both sound input (to e.g. record and send to Alexa API) and sound output (any playback), creating both pulse sink and source for the card.

Not sure if analog-jack/hdmi detection and profile picking in pulse works well on RPi, but if it picks some "output only" profile by default, you can probably change it once to input+output and leave it at that.