This is apparently possible and not that complex.
This repo has a lot of efi utils, including a beep.efi (and its source code). By examining the source, it seems it produces sound the old way with a square wave through the speaker.
I have not tried the utility myself yet.
https://github.com/fpmurphy/UEFI-Utilities-2018/tree/master/MyApps