Listen for changes in variable (alsaaudio.Mixer(x,x).getvolume(x)

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed Oct 24 18:58:46 EDT 2012


On Wed, 24 Oct 2012 20:55:35 +0200, Muffinman wrote:

> Hello all,
> 
> I'm new to Python (running 2.6.6 but if necessary 3.x should also be
> fine). I have a little idea I hope to accomplish with Python. I want to
> listen for changes in Alsa sound volume level and base some actions on
> that. With the few lines below I can check the current volume level. Can
> I extend this so that the script listens for changes in the volume level
> and I can base some actions on it? As speed is quite important it's not
> an option to poll every second or so for changes, it has to be close to
> instantaneous.

Then poll every millisecond or so.

I don't believe it is possible to listen for changes in an arbitrary 
variable. But if you check the alsaaudio module, or ask on a dedicated 
alsa mailing list, you may be able to find out how alsa records the 
volume in the first place. If it is written to a file, you can listen for 
changes to the file without polling on Linux systems.

> If this is not possible with Python, any suggestions on what else are
> also welcome of course.

That's not a Python question, it's an Alsa question. Who knows how the 
sound volume is stored?


-- 
Steven



More information about the Python-list mailing list