PyAudio, mentioned by user3222184 is just a python wrapper for PortAudio (http://portaudio.com/), which can definitely be used to do what you want. It's a cross-platform C / C++ library.
I've use PyAudio with PortAudio on a Raspberry Pi, so I know that it works. It can be tricky if you're trying to do any audio processing to ensure that the processing runs ...
if you use ALSA then this command should help you:
when nothing is playing the output is "closed"
but when something is played it shows i.e. like this:
22:21:52 pi@sabaj-d5:~ $ cat /proc/asound/card*/pcm*p/sub*/hw_params
rate: 44100 (...
APTX is a proprietary codec so I think it is unlikely. I would just mention that unless you are using it as a source for bluetooth headphones you would be much better off using it as a wifi/ethernet streamer as opposed to bluetooth. Even the best bluetooth codecs are extremely lossy, whereas LAN based transports like DLNA/RAAT/Squeezelite/chromecast/airplay ...
The answer to this issue can be found here:
The solution presented worked for me to get sound while running a python program from system.
What one has to do is to add defaults to the asound.conf file at /etc/asound.conf. I did sudo nano on file and found nothing in it, so I added
The sound is produced by the initial configuration manager. And I assume you don't use a monitor and don't see it. Therefore it is so mysterious.
For this case, you can disable "Desktop Login". By choosing System Options -> Boot Autologin -> Console.