Sound files in Lua

I'm telling you how easy it is to make a function for playing sound in various formats in Lua scripts.

It is necessary to make a dll for Lua with such a function in SI.

Code C:

static int mciSS(lua_State*L){  mciSendString((char*)lua_tostring(L,1),0,0,0); }

If someone can’t do it, write me and I’ll post the finished dll. Further in my article the dll is called nks. Calling a function in the nks.mciss script.

I’ll explain how to use this function in lua scripts:

To play a WAV file you need to open the device with this file like this:

Lua code

local file="C:/Windows/Media/Alarm10.wav" -- звуковой файл

nks.mciss("open "..file.."  alias MediaFile wait"); -- открыть устройство

To play the contents of the file, write where you want:

Lua code

nks.mciss("play MediaFile FROM 0 wait");

To play an MP3 file you need to do the same thing, but for this file. For example, for me this is the file “D:/nks/test.mp3”

Lua code

local file="D:/nks/test.mp3" -- звуковой файл

nks.mciss("open "..file.."  alias MediaFile wait"); -- открыть устройство

To play the contents of the file, write where you want:

Lua code

nks.mciss("play MediaFile FROM 0 wait");

Options: If you want to start the sound and not wait for it to end, then remove “wait” from the last command.

If you want to play many different sounds in different places in the script, then at the beginning of the script, open all the sound files and make a unique device name for each of them.

It should be written instead of “MediaFile”.

To play a specific file, you must specify its device name in the playback command instead of “MediaFile”.

I wish you success in listening to sound files in Lua scripts.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *