Thanks for your reply!
But for now, i dont play the sound from my application, (I have not specify it in my first post: my mistake)
So let say that another external application is playing something on the speaker, and i want to programmatically invert sound output polarity on raspberry pi 3 board, is there an easy way to do this?
(Actually the way i found to invert my polarity is to use a relay and turn the relay on to invert the polarity, this work great, but i wanna know if i can do it from my code to save space in my project box, and to use less hardware as possible...)