/dev/posts/

Push-to-talk in any application

Published:

Updated:

Some scripts I wrote to enable system-wide push-to-talk (for X11 and PulseAudio). Some people might find it useful for the ongoing lockdown.

Some Voice over IP (VoIP) software have builtin support for push-to-talk. In this mode, a global keyboard hotkey must be be held while speaking. This is quite useful when in a noisy environment and/or with suboptimal mics.

Some programs with support for this:

Most programs don't support this. This is especially true for browser-based VoIP software because as there is currently not web API to register a global keyboard hotkey[1] as far as I know.

So I wrote two Python scripts for PulseAudio.

Push-to-talk

The first one implements push-to-talk based on some keyboard key. (i.e. you have to hold the key while you are talking):

pushtotalk --key "F1"

It is intended for PulseAudio and X11 but it should be quite easy to adapt this to other sound and GUI systems.

Tip: you can se xev to find the key symbol name.

Toggle audio source

The second one just toggles the mute state of the default PulseAudio source and provides a visual feedback (notification). It is intended to be bound to some global keyboard hotkey.

For example using a script based on keybinder:

keybinder "<Control>m" pulse-mute-toggle

Simply toggling the audio source can be done with:

pactl set-sink-mute @DEFAULT_SOURCE@ toggle

Getting the notification of the state is important because otherwise you might end being in the wrong state. There is no pactl get-sink-mute @DEFAULT_SOURCE@ command which is why it is not an absolutely straightforward shell script[2].


  1. This is why this feature is apparently available on the native Discord application but not on the web one. ↩︎

  2. It can be done by:

    • parsing the output of pacmd list-sources or similar (which is cumbersome);
    • relying on the native protocol;
    • use the PulseAudio D-Bus interface.

    I decided to use the D-Bus interface (which is sadly not enabled by default). ↩︎