I found an app on F-droid that does exactly this, but when the phone goes into idle mode (screen off for more than 1 minute) it stops sending sound through the headphone output.
Can I make an app that does not stop capturing sound (and send it through the headphone output) even if the phone screen is not on and goes into idle mode?
Sorry, I misspoke!
I meant to make an app that uses the phone's microphone to output audio through the headphone output (I found such an app in F-droid), and also that does not stop when the phone goes into locked screen mode for more than a few minutes (the F-droid app stops when the phone has been in locked screen for a minute).
Because the app I downloaded from F-droid stops capturing the sound when the phone screen is locked for more than a minute and stops sending it through the headphone output to the computer.