Skip to content

Instantly share code, notes, and snippets.

@zouppen
Last active September 13, 2024 09:35
Show Gist options
  • Save zouppen/bdd40a42c77ca387fae8bace0f2ed3e0 to your computer and use it in GitHub Desktop.
Save zouppen/bdd40a42c77ca387fae8bace0f2ed3e0 to your computer and use it in GitHub Desktop.
Push to talk microphone with Pulseaudio

Microphone PTT for Pulseaudio

This tool helps you with many absolutely proprietary software which doesn't include proper push-to-talk key. I wrote this with Google Meet in mind but is also useful for many other browser based apps as well.

It works so that when Caps Lock is held down, the microphone is unmuted. If you want to toggle it (for example during a demonstration), just press Ctrl + Caps Lock.

In this example we use Caps Lock, but you can set your favourite key.

Like this? Support me at Github!

Installation

First, install requirements and symlink the configuration file.

sudo apt install xbindkeys
ln -s `readlink -f xbindkeysrc` ~/.xbindkeysrc

If you already have xbindkeys setup, just concatenate the contents to your main config.

Then make xbindkeys to autostart on login:

mkdir -p ~/.config/autostart-scripts/
ln -s /usr/bin/xbindkeys ~/.config/autostart-scripts

The script dedicates Caps Lock key for PTT, so you need to disable regular Caps Lock behaviour. You can find it from keyboard settings. In KDE just edit the file ~.config/kxkbrc and add caps:none to the end of Options of block [Layout], like in this example:

[Layout]
Options=terminate:ctrl_alt_bksp,nbsp:level3,caps:none

To set it temporarily for the current session, run setxkbmap -option ctrl:nocaps.

Customization

Edit attached xbindkeysrc file to match your needs:

PTT button

Default: Caps lock

Change c:66 to the key name you want to use as PTT key. To get name of your key, run:

xbindkeys -k -f /dev/null

Microphone

If you want to control a specific mic instead of default one, replace @DEFAULT_SOURCE@ with Pulseaudio sink name. To get list input device names, run:

pactl list short sources | cut -f 2
# -*- shell-script -*-
#
# To use this, make xbindkeys start on login and symlink this file to
# ~/.xbindkeysrc
"pactl set-source-mute @DEFAULT_SOURCE@ 0"
c:66
"pactl set-source-mute @DEFAULT_SOURCE@ 1"
release+c:66
"pactl set-source-mute @DEFAULT_SOURCE@ toggle"
control+c:66
@zouppen
Copy link
Author

zouppen commented Apr 27, 2022

Hi @fmayer @zouppen, sometimes i want to open my mic to talk for a while in PairProgramming, but in general i want to use PushToTalk. Do you know a nice Config solution for that purpose ?

Interesting suggestion. I updated .xbindkeysrc above and added control + caps lock to the configuration which toggles the microphone muting.

@azuline
Copy link

azuline commented Aug 30, 2023

thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment