comparison volume_linux.py @ 1:04c8a1b3976b

volume r/w on linux+osx
author drewp@bigasterisk.com
date Fri, 03 Mar 2023 21:24:53 -0800
parents
children
comparison
equal deleted inserted replaced
0:05bdded21d38 1:04c8a1b3976b
1 from pulsectl_asyncio import PulseAsync
2
3 _pulse = None
4
5
6 async def _init():
7 global _pulse
8 if _pulse is not None:
9 return
10 _pulse = PulseAsync('racc')
11 await _pulse.connect()
12
13
14 async def _get_sink():
15 [sink] = [
16 s for s in (await _pulse.sink_list())
17 if s.description == 'Built-in Audio Analog Stereo'
18 ]
19 return sink
20
21
22 async def get_volume():
23 await _init()
24 return (await _get_sink()).volume.value_flat
25
26
27 async def set_volume(v: float):
28 await _init()
29 sync = await _get_sink()
30 await _pulse.volume_set_all_chans(sink, v)