コンソールのPulseAudioのクライアントのボリュームレベルを読み出す方法
-
15-11-2019 - |
質問
Pulseaudioのいくつかのクライアントのために演奏された音声の音量を読みたいです。
解決するのが好きな問題は次のとおりです。 私はXMMSで音楽を聴いています、それから私はそれを一時停止して、友達がYouTubeで私に送った曲を聴く。 1時間後、突然私はどんな音楽に耳を傾けていません!
(非常に基本的な)解決策私は、毎秒xmms以外のすべてのアプリの音量をチェックするだけであるBashスクリプトが、任意のアプリケーションがサウンドを作っている場合はXMMSが一時停止し、XMMSがない場合サイレントです、XMMSが有効になっています。 (たとえば、このアプリケーションを実行できるようにしたいのですが、PIDGINは無視されるべきです)
Pavucontrolのように、音量を読み取るためのグラフィカルツールを見つけることができます。私は本当にこのような簡単なことをするためにすべての種類のCプログラムをコーディングしたいと思うでしょう、そう:
- 私は正しい方向を考えていますか、それともより単純な解決策
- がない場合は、Seperateアプリのボリュームの現在のレベルを読み取る方法
解決
Perhaps you can record one sample of audio from the output stream and see if it is (close to) 0. This pipeline gives you a single sample, in the form of a number between -32768 and 32767 (inclusive):
parec --raw --channels=1 --latency=2 2>/dev/null | od -N2 -td2 | head -n1 | cut -d' ' -f2- | tr -d ' '
You'll need to adjust the parec
arguments, and possibly the PulseAudio configuration, to tap into the output stream and record from that.
他のヒント
pactl list
dumps a list of... well, it seems pretty much everything. With a running mplayer -ao pulse
instance, I get the following among the output:
Sink Input #2
Driver: protocol-native.c
Owner Module: 8
Client: 10
Sink: 0
Sample Specification: s16le 2ch 44100Hz
Channel Map: front-left,front-right
Mute: no
Volume: 0: 100% 1: 100%
0: 0.00 dB 1: 0.00 dB
balance 0.00
...
Properties:
media.name = "audio stream"
application.name = "MPlayer"
native-protocol.peer = "UNIX socket client"
....
application.process.binary = "mplayer"
...
It doesn't give you the current monitor levels (volume of currently playing audio), though, but maybe it's sufficient?
I wouldn't even bother reading the volumes. I'd write a module which contains a sink which detects the volume of apps connected to it and can perform actions based on that as well as a virtual application that you can direct to an existing sink for eventual audio output.