+def info_audio(
+ ) -> str:
+ "Produce audio devices' volume, muteness."
+ def pactl_json(
+ *args: str
+ ) -> Any:
+ return json_loads(subprocess_run(
+ ('pactl', '-f', 'json', *args),
+ check=True, capture_output=True, text=True
+ ).stdout)
+ defaults = pactl_json('info')
+ texts = []
+ for dev_type, label in AUDIO_DEVS_LABELS:
+ dev = next(dev for dev in pactl_json('list', f'{dev_type}s')
+ if dev['name'] == defaults[f'default_{dev_type}_name'])
+ items_pc = {item['value_percent'] for item in dev['volume'].values()}
+ assert len(items_pc) == 1
+ texts += [f'{label} {items_pc.pop()}' + 'M' * int(dev['mute'])]
+ return ' '.join(texts)
+
+