It's possible to use third-party Lua modules (from, e.g.,
LuaRocks) from within the BizHawk Lua console. If you can find a module that plays sound in a non-blocking way, it might work for your purpose. (You may have to tinker with
package.path /
package.cpath, depending on where LuaRocks installs things.)
I tried something with the
Lua-SDL2 module (
luarocks install lua-sdl2):
Language: lua
local SDL = require("SDL")
SDL.mixer = require("SDL.mixer")
assert(SDL.mixer.openAudio(48000, SDL.audioFormat.S16, 2, 2048))
local beep = assert(SDL.mixer.loadWAV("beep.wav"))
assert(beep:playChannel(-1, 0, 0))
However, it doesn't quite work, because BizHawk includes
its own copy of libSDL2, which shadows the system libSDL2, and which isn't compiled with support for audio. It gives the error "SDL not built with audio support" in the Lua console. If you can find a module that doesn't conflict with one of BizHawk's included libraries, or if you can find a way to make the Lua script use the system libSDL2 rather than the BizHawk one, it may work.
I tried the
ao module and it does work, in the sense that it plays audio from within the BizHawk Lua console, but it has the same problem as your
os.execute idea, namely that it blocks until the sound is finished playing.