Play a sound
PlaySound(fileName as String, volume as Float, fadeInLength as Float) as NodeRef
Plays the specified sound at the specified volume. The filename must be a valid FQN (full path and filename). Volume is a float from 1.0 (full volume) to 0.0 (inaudible). FadeInLength is the time in seconds that the sound should fade in from inaudible to the specified volume.
Sounds played with PlaySound are played on a stereo channel. Thus stereo wavs will be properly channeled to left and right speakers. Mono wavs are played equally on both left and right channels.
var mySound = PlaySound("world/livecontent/audio/boom.wav", 1.0, 0.0)
Play a 3D sound space
Play3DSound(fileName as String, volume as Float, fadeInLength as Float, whereAt as Vector3) as NodeRef
Plays the specified sound at the specified volume and positioned at the specified vector in 3d space. A fadeInLength (in seconds) may be specified to have the sound fade in from inaudible to the specified volume.
var location = "(1.5, 0.0, 0.5)" var my3DSound = Play3DSound("world/livecontent/audio/boom.wav", 1.0, 0.0, location)
Stopping a looping sound
StopSound(handle as NodeRef)
The StopSound command can be used to stop any sound that is playing. You must pass in the noderef of the playing sound, which is given to you by the PlaySound or Play3DSound function.
function PlayRainSound() as noderef // play the sound var myRainSound = PlaySound("world/livecontent/audio/rain.sgt", 1.0, 0,0) // return the sound noderef so we know what sound to stop later return myRainSound . function StopRainSound(myRainSound as noderef) // stop the sound StopSound(myRainSound) .
Manipulating Sound Volumes
Occasionally, you may need to change the volume of a sound. The following functions support this.
GetSoundVolume(sound as NodeRef) as Float
GetSoundVolume returns the current volume of the specified sound node.
SetSoundVolume(sound as NodeRef, volume as Float, fadeLength as Float) as Boolean
SetSoundVolume changes the volume of the current sound. With this, you can have existing sounds fade out smoothly.
function FadeOutSound(theSound as noderef) // fade sound to inaudible over 3 seconds SetSoundVolume(theSound, 0.0, 3.0) .