See Switch Audio Source, which uses the command-line program SwitchAudioSource.
For more information, see the wiki Searching the Forum for Answers section.