Lua · Variables · Sound

sound

Play WAV files, tones and spoken text.

Files come from the script's data folder (8, 16, 24 or 32-bit WAV, or float). Up to 8 sounds play at once for everyone together; a script keeps at most 8 of its own and the oldest stops. One start per 0.05 s per script. Sounds stop when the script is turned off.

FunctionWhat it does
sound.play(file[, volume][, options])Plays a WAV.
sound.play_at(file, pos[, volume][, range])Plays a WAV as if it came from a point: quieter with distance, panned left or right from where you look. Silent past range (default 2000).
sound.tone(hz[, seconds][, volume][, pan])A beep without any file. 20 to 12000 Hz, 0.02 to 5 s (default 0.15), volume default 0.6.
sound.stop(id)Stops one of this script's sounds.
sound.stop_all()Stops all of this script's sounds.
sound.playing(id)True while that sound plays.
sound.list()WAV files in the data folder.
sound.speak(text[, rate])Reads text aloud with a Windows voice. Queued, up to 8 lines of 240 characters. Rate -10 to 10.
sound.speak_stop()Stops speaking and clears the queue.

#sound.play

sound.play(file[, volume][, options])

Plays a WAV.

Arguments

filestring
Name in the data folder.
volumenumberoptional
0 to 1, default 1.
optionstableoptional
pan (-1 left to 1 right), loop (boolean).

Returns

integer
Sound id, 0 when it did not start.
Example
local id = sound.play("alarm.wav", 0.7, { loop = true })

#sound.play_at

sound.play_at(file, pos[, volume][, range])

Plays a WAV as if it came from a point: quieter with distance, panned left or right from where you look. Silent past range (default 2000).

Returns

integer
Sound id or 0.

#sound.tone

sound.tone(hz[, seconds][, volume][, pan])

A beep without any file. 20 to 12000 Hz, 0.02 to 5 s (default 0.15), volume default 0.6.

Returns

integer
Sound id or 0.
Example
sound.tone(880, 0.08)

#sound.stop

sound.stop(id)

Stops one of this script's sounds.

Returns

boolean
-

#sound.stop_all

sound.stop_all()

Stops all of this script's sounds.

#sound.playing

sound.playing(id)

True while that sound plays.

Returns

boolean
-

#sound.list

sound.list()

WAV files in the data folder.

Returns

string[]
-

#sound.speak

sound.speak(text[, rate])

Reads text aloud with a Windows voice. Queued, up to 8 lines of 240 characters. Rate -10 to 10.

Returns

boolean
false when the queue is full.
  • Uses the voices installed in Windows; there may be no voice for every language.
Example
sound.speak("Bomb planted")

#sound.speak_stop

sound.speak_stop()

Stops speaking and clears the queue.