I constantly switch between speakers and headset.. like 5-6 times per day for conference calls and such…. and changing the audio source was super annoying.. SO THIS BECAME A THING.
Install switchaudio-osx from brew
# brew install switchaudio-osx
Then you can list the audio devices available on your system to edit the code in the next step.
# /opt/homebrew/Cellar/switchaudio-osx/*/SwitchAudioSource -a
G533 Gaming Headset
Logitech Webcam C930e
DELL U2713HM
HP Z38c
HP Z38c
G533 Gaming Headset
External Headphones
Mac Studio Speakers
Open automator and create a a new quick action. Automator:

Using MacOS “Automator” and “switchaudio-osx” from Brew I was able to automate switching to my logitech 533 headset automagically. I have this setup on a key binding for control+F13

The code:
on run {input, parameters}
set theSwitch to "/usr/local/Cellar/switchaudio-osx/EDIT-ME/SwitchAudioSource"
set theSource to do shell script theSwitch & " -c"
try
if theSource = "Built-in Output" then
do shell script theSwitch & " -t output -s \"G533 Gaming Headset\""
do shell script theSwitch & " -t input -s \"G533 Gaming Headset\""
display notification "Audio switched to G533 Headset." with title " Audio Input/Output Switcher"
else
do shell script theSwitch & " -t output -s \"Built-in Output\""
do shell script theSwitch & " -t input -s \"Built-in Microphone\""
display notification "Audio switched to Internal iMac Devices." with title " Audio Input/Output Switcher"
end if
end try
return input
end run