Lua Automation IDE: Audio Playback Automation
Seamlessly Integrate Audio Playback into Your Automation Scripts
In the Lua Automation IDE, users can automate the playback of audio files within their scripts. This example demonstrates playing an MP3 file located on the local file system. To begin, the file path is assigned to a variable called 'mp3'. The script logs the start of the playback to the IDE’s console. Optionally, the playback can be confined to a specific segment by providing the start and end times in seconds. The ‘audio.Play’ function is used to play the entire file. Meanwhile, a while loop monitors the status of the audio playback, and the IDE's status bar is updated with the current playback time. This loop continues until the audio file finishes playing. Finally, the script logs that the playback is complete and the ‘audio.Stop’ function is invoked to release any resources associated with the audio file.
Lua
-- Playing audio example: You'll need to put the path to a valid audio file.
-- Where our mp3 is located on the file system.
local mp3 = "C:\\Music\\Margot and the Nuclear So and So's - Talking in Code.mp3"
ui.Log("Playing " .. mp3)
-- If you want to play audio for a specific part of a song you can pass in
-- the value in seconds you want it to start on and end on.
--audio.Play(mp3, 5, 10)
-- Play the entire file.
audio.Play(mp3)
-- If you want to keep the programming running while the audio plays.
while(audio.IsPlaying())
do
ui.StatusText = audio.AtTime() .. "s of " .. audio.TotalTime() .. "s."
ui.Sleep(10)
end
ui.Log("Done playing")
-- Stops and/or frees any associated memory with the audio file.
audio.Stop()