Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] mute/unmute with a command #887

Closed
3 tasks done
ilobilo opened this issue Oct 2, 2024 · 7 comments
Closed
3 tasks done

[Feature Request] mute/unmute with a command #887

ilobilo opened this issue Oct 2, 2024 · 7 comments
Labels
enhancement New feature or request

Comments

@ilobilo
Copy link

ilobilo commented Oct 2, 2024

Discord Account

No response

Motivation

I would like to use a specific media key on my keyboard to mute and unmute.

Solution

Provide a way to mute/unmute with a command so I can execute it when the key is pressed.

Alternatives

global keybinds

Additional context

No response

Request Agreement

  • I have searched the existing issues and found no similar issue
  • This is not a plugin request
  • This is not a Vencord feature request
@ilobilo ilobilo added the enhancement New feature or request label Oct 2, 2024
@CookieUniverse
Copy link

isn't this what you are asking for? #609

@ilobilo
Copy link
Author

ilobilo commented Oct 6, 2024

yep, hope it gets merged soon!

@sr-tream
Copy link

sr-tream commented Oct 14, 2024

Workaround for any Discord client to toggle micro on Linux with PipeWire

Launch Vesktop with custom property to filter input recorder:

PULSE_PROP="discord.id=vesktop" vesktop

For now, we can find the ID of input recorder, used by vesktop:

pw-dump | jq ".[] | select(.info.props.\"discord.id\" == \"vesktop\" and .info.props.\"media.name\" == \"RecordStream\") | .id"

And we can change mute param:

pw-cli set-param STREAM_ID Props "{mute: STATE}"

Ready to use script:

#!/bin/bash

: ${DISCORD_ID:=vesktop}

# Optional true/false value to enforce specific state (Useful for keybinds on hold key state)
WANT_MUTE=$1

STREAM_IDS=(`pw-dump | jq ".[] | select(.info.props.\"discord.id\" == \"${DISCORD_ID}\"and .info.props.\"media.name\" == \"RecordStream\") | .id"`)

if [[ -z "${STREAM_IDS[@]}" ]]; then
  if [[ -z "$WANT_MUTE" ]]; then
    notify-send -i error -a "$DISCORD_ID" "Discord microphone" "Status not changed: cannot find the micro.\nPossible reasons:\n - The field 'discord.id' missmatch\n - You not connect to voice channel"
  fi
  exit 0
fi

# For mutiple same inputs sync on first
STATE=`pw-cli enum-params ${STREAM_IDS[0]} Props | awk '/Prop: key.*mute/{getline; print $2}'`

for STREAM_ID in "${STREAM_IDS[@]}"; do
  LOCAL_STATE=`pw-cli enum-params $STREAM_ID Props | awk '/Prop: key.*mute/{getline; print $2}'`
  if [[ "$LOCAL_STATE" == "$WANT_MUTE" ]]; then
    continue
  fi

  if [[ "$STATE" == "true" ]]; then
    pw-cli set-param $STREAM_ID Props "{mute: false}" > /dev/null
  else
    pw-cli set-param $STREAM_ID Props "{mute: true}" > /dev/null
  fi
done

if [[ "$STATE" == "$WANT_MUTE" ]]; then
  exit 0
fi

if [[ "$STATE" == "true" ]]; then
  notify-send -i microphone-sensitivity-high -a "$DISCORD_ID" "Discord microphone" "Enabled"
else
  notify-send -i microphone-sensitivity-muted -a "$DISCORD_ID" "Discord microphone" "Muted"
fi

Don't forget set env PULSE_PROP="discord.id=vesktop" for Vesktop launch!

@ilobilo
Copy link
Author

ilobilo commented Oct 14, 2024

thank you very much! I made my own script but it was very janky. I'll definitely use that

@ilobilo ilobilo closed this as completed Oct 14, 2024
@ilobilo
Copy link
Author

ilobilo commented Oct 14, 2024

I modified it a bit

#!/bin/bash

: ${DISCORD_ID:=vesktop}

WANT_MUTE=$1
DEFAULT_SOURCE=$(pactl get-default-source)

STREAM_ID=`pw-dump | jq ".[] | select(.info.props.\"discord.id\" == \"${DISCORD_ID}\"and .info.props.\"media.name\" == \"RecordStream\") | .id"`

if [[ -z "$STREAM_ID" ]]; then
    pactl set-source-mute $DEFAULT_SOURCE toggle
    exit 0
fi

STATE=`pw-cli enum-params $STREAM_ID Props | awk '/Prop: key.*mute/{getline; print $2}'`
if [[ "$STATE" == "$WANT_MUTE" ]]; then
    exit 0
fi

if [[ "$STATE" == "true" ]]; then
    pw-cli set-param $STREAM_ID Props "{mute: false}" > /dev/null
    pactl set-source-mute $DEFAULT_SOURCE 0
else
    pw-cli set-param $STREAM_ID Props "{mute: true}" > /dev/null
    pactl set-source-mute $DEFAULT_SOURCE 1
fi

if [ -e "$XDG_RUNTIME_DIR/vesktop-ipc" ]; then
    echo "VCD_TOGGLE_SELF_MUTE" >> $XDG_RUNTIME_DIR/vesktop-ipc
fi

@sr-tream
Copy link

if [[ "$STATE" == "$WANT_MUTE" ]]; then
    pactl set-source-mute $DEFAULT_SOURCE toggle
    exit 0
fi

Why you toggle device micro here? In original script this condition prevent any changes for hold-key bindings, like that:

modmap:
  - name: In game
  application:
    only: [cs2, other-game.exe]
  remap:
    ALT_L:
      skip_key_event: true
      press: { launch: ["bash", "-c", "/path/to/script.sh", "false"] } # Enable micro
      release: { launch: ["bash", "-c", "/path/to/script.sh", "true"] } # Mute micro

@ilobilo
Copy link
Author

ilobilo commented Oct 14, 2024

yeah I realised that after sending it. I'll edit the message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants