On Windows, there is a Secure Audio Path API to prevent interception of the audio signal. Not sure if macOS has something similar, though it can prevent screenshotting of DRMed video. On Linux, any such protection is probably impossible unless Spotify requires a kernel module.
Note that the audio quality on Spotify is not very high (256kbps .ogg, I think), so anything thus recorded is going to sound lossy, especially after you recompress it a second time.