Type audiodevice help
to print this usage message.
audiodevice
list devices for input, output, and system audio
audiodevice <port>
display the audio device for the selected port
audiodevice <port> list
list available audio devices for the selected port
audiodevice <port> <device>
set the selected port to use the designated device ("internal" will select Internal Speakers or Headphones, whichever is active)
This is not my work. Just uploading it to Github to share with others.
Original author is here: http://whoshacks.blogspot.com/2009/01/change-audio-devices-via-shell-script.html