Control Volume of Piezo Speaker using variable resistor?

Interesting. My Googling has yielded similar results: volume on piezo can only be changed by current change to the speaker (though PLEASE correct me if there is any other way).
I guess my follow up question would be, is there any way to restrict current flow through software?
So I could say,

if (current flow through penny circuit does not reach threshold) {
restrict current to speaker
}

That kind of thing? Or would it forcefully require a (physical) variable resistor of its own?