Skip to content

Instantly share code, notes, and snippets.

@ClimenteA
Last active May 19, 2025 09:04
Show Gist options
  • Save ClimenteA/f081965893cd1eb4bb2ef8c8b42cab1c to your computer and use it in GitHub Desktop.
Save ClimenteA/f081965893cd1eb4bb2ef8c8b42cab1c to your computer and use it in GitHub Desktop.
Sony SRS-XB100 - Ubuntu Microphone Setup
#!/bin/bash

# systemctl --user restart wireplumber pipewire pipewire-pulse

# Change this to match your device alias (as shown in `pactl list cards`)
DEVICE_ALIAS="SRS-XB100"

# Get the card name for the device
CARD_NAME=$(pactl list cards | awk -v alias="$DEVICE_ALIAS" '
  /Name:/ {name=$2}
  /device.alias =/ {
    gsub(/"/, "", $3)
    if ($3 == alias) {
      print name
      exit
    }
  }
')

if [ -z "$CARD_NAME" ]; then
  echo "❌ Could not find Bluetooth device with alias '$DEVICE_ALIAS'"
  exit 1
fi

# Available profiles and their descriptions
declare -A PROFILES=(
  ["a2dp-sink"]="High Quality Audio (No Mic)"
  ["headset-head-unit-msbc"]="Medium Quality Audio + Mic (mSBC)"
)

# Display current profile
CURRENT_PROFILE=$(pactl list cards | awk -v card="$CARD_NAME" '
  $0 ~ "Name: "card {in_card=1}
  in_card && /Active Profile:/ {print $3; exit}
')

echo "🎧 Device: $DEVICE_ALIAS"
echo "πŸ“Œ Current Profile: $CURRENT_PROFILE (${PROFILES[$CURRENT_PROFILE]:-Unknown})"
echo
echo "πŸ”„ Select a profile to switch to:"

# Present profile options
PS3="Enter your choice: "
select profile_key in "${!PROFILES[@]}"; do
  if [[ -n "$profile_key" ]]; then
    echo "πŸ” Switching to: $profile_key (${PROFILES[$profile_key]})"
    pactl set-card-profile "$CARD_NAME" "$profile_key"
    echo "βœ… Switched."
    break
  else
    echo "❗ Invalid selection. Try again."
  fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment