First of all, install the two programs
pavucontrol (PulseAudio volume control) and
paman (PulseAudio manager). You can use your Linux distribution's package manager for that.
Now, launch the PulseAudio manager from your menu or a terminal. The very first screen will show the Default Sink value. Copy that to the clipboard.
You can now run the following program on your terminal:
sink=<paste your Default Sink value here> pactl load-module module-remap-sink \ sink_name=remapper \ master=$sink channels=2 \ master_channel_map=front-left,front-right \ channel_map=front-right,front-left
This loads a module into your current session that creates a new, "fake" sink to play audio into. Only this sink inverts left and right, transparently, for your benefit.
Now launch the PulseAudio volume control. You will see a list of current programs playing audio streams, with one slider each, and a button right above the slider that mentions the name of the current sink for the stream.
Begin playing the audio that you wanted to hear over the speakers / headphones. You should see the stream appear and a VU meter bar move.
Now invert it! Click on the button holding the current sink for the stream, and select the Remapper sink. You should hear left and right switching, instantaneously. Using the exact same technique, you can now flip back and forth between the original sink and the remapper, which should flip left and right channels for you. No delays, no having to reconnect any cables, no extra hardware.
Similar tricks can be played by piping audio to all sorts of virtual sinks, including sinks that equalize audio, or sinks that impart audio effects to the streams being played through them. To learn more, visit the PulseAudio modules page.