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.
| Function | What 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
filestringvolumenumberoptionaloptionstableoptionalpan (-1 left to 1 right), loop (boolean).Returns
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
#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
sound.tone(880, 0.08)#sound.stop
sound.stop(id)Stops one of this script's sounds.
Returns
#sound.stop_all
sound.stop_all()Stops all of this script's sounds.
#sound.playing
sound.playing(id)True while that sound plays.
Returns
#sound.list
sound.list()WAV files in the data folder.
Returns
#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
- Uses the voices installed in Windows; there may be no voice for every language.
sound.speak("Bomb planted")#sound.speak_stop
sound.speak_stop()Stops speaking and clears the queue.