Using the output from speakers as a virtual microphone input on the same device

Totally do-able. The idea is you create a virtual speaker device, and have it connected to a virtual microphone device. On Windows, one could use a virtual audio cable. But on Ubuntu, that app doesn't exist. But we can still create a virtual audio cable using something like PulseAudio as described in this Stack Overflow post. Here's the part of the post that answers your question:

Create a virtual output device, and a virtual source from it's monitor.

pactl load-module module-null-sink sink_name="virtual_speaker" sink_properties=device.description="virtual_speaker"
pactl load-module module-remap-source master="virtual_speaker.monitor" source_name="virtual_mic" source_properties=device.description="virtual_mic"

Any sound played to "virtual_speaker" will be sent to "virtual_mic". (the rest of the linked answer is specific to doing it with FFmpeg)