Adjust Sample Type Function

I’d like the ability to adjust a samples sample rate, bit depth, stereo/mono, etc from a function like we can in the GUI with a API function for scripting.
I don’t see a current way of doing this within a script.

This might be possible already. if it is does anybody know how ?

The only way i currently see is creating a new sample with those properties and copy the contents of the source sample into it.
At least that is how i did it when creating the stereo to mono tool.