I worked with this script to basically toggle between airplay speaker and MacBook internal speaker. Its a stand alone (switch speakers) button on my media control menus in BTT.
-- Applescript to toggle between two sound outputs by Line number, as they appear in the Sound Control Panel.
set outputA to 1 --change this to the actual 'line number' of your first desired output
set outputB to 2 --change this to the actual 'line number' of your second desired output
--the rest of the script will use these vales as a switch
tell application "System Preferences"
reveal anchor "output" of pane id "com.apple.preference.sound"
tell application "System Events"
tell application process "System Preferences"
repeat until exists tab group 1 of window "Sound"
tell tab group 1 of window "Sound"
-- click radio button "Output"
if (selected of row outputA of table 1 of scroll area 1) then
set selected of row outputB of table 1 of scroll area 1 to true
set selected of row outputA of table 1 of scroll area 1 to true
quit application "System Preferences"