Frage

Ich möchte das Volumen des im Moment gespielten Audios für die mehreren Kunden von Pulsaudio auslesen.

Das Problem, das ich gerne lösen möchte, ist folgender: Ich höre Musik in XMMs, dann lege ich es auf Pause, um einem Song zu hören, ein Freund hat mich auf YouTube geschickt. Nach einer Stunde entdecke ich plötzlich, dass ich keine Musik höre!

Die (sehr basische) Lösung, an die ich nachgedacht habe, ist ein Bash-Skripts, das das Volumen aller anderen Apps als XMMS jeglicher Sekunde überprüft, wenn irgendwelche Anwendung Sound erstellt, wird XMMS angehalten, wenn kein Ton und XMMs vorhanden ist ist Silent, XMMs ist aktiviert. (Ich möchte dieses App-weise tun können, zum Beispiel sollte Pidgin ignoriert werden)

Ich konnte nur grafische Werkzeuge finden, um das Volumen auszulehnen, wie Pavucontrol, der es schön anzeigt. Ich möchte wirklich nicht alle Arten von C-Programmen codieren, um so ein einfaches Ding zu tun, also:

    .
  1. denke ich in die richtige Richtung, oder gibt es eine einfachere Lösung
  2. Wenn es nicht gibt, wies ich den aktuellen Level des Volumens für die separaten Apps aus?
War es hilfreich?

Lösung

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.

Andere Tipps

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top