Button Script to Switch Jack to Output via Headphone Jack

I searched for this topic and have found a few that had a similar experience to mine: when I plug my headphones into the output jack of pisound I really have to crank up the output gain on pisound to hear anything and even then it’s pretty quiet.

What I would like to do is to create a button script that will switch the jack output to the headphone jack and then another script to switch jack output back to pisound. That way when I practice I can hear myself well without having to turn up the output gain all the way.

Is this possible?

By headphone jack you mean the 3.5mm audio port on the Pi itself?

@Giedrius yes, the port on the pi.

You’d have to restart the Jack server with different audio card selected. This probably requires restarting all of the audio software too, which might be inconvenient. An alternative to that might be to use some jack → ALSA bridge client to forward the output into the headphone jack. It may be running all the time, so you don’t have to use the button at all, unless to trigger some jack connection scripts.