Namespace: utils

utils

Utilities that work with sounds.

Members

extensions readonly

The list of extensions that can be played. This is the preferred order of playback. If you want to priority the order of playback, you can use this array to do so.

supported readonly

The list of browser supported audio formats.

Properties:
Name Type Description
aiff boolean

true if file-type is supported

caf boolean

true if file-type is supported. Note that for this we check if the 'opus' codec is supported inside the caf container.

mid boolean

true if file-type is supported

mp3 boolean

true if file-type is supported

mpeg boolean

true if file-type is supported

oga boolean

true if file-type is supported

ogg boolean

true if file-type is supported

opus boolean

true if file-type is supported

wav boolean

true if file-type is supported

wma boolean

true if file-type is supported

Methods

playOnce (url, callback) string

Create a new "Audio" stream based on given audio path and project uri; returns the audio object.

Name Type Attributes Description
url string

Full path of the file to play.

callback Function <optional>

Callback when complete.

Returns:
Type Description
string New audio element alias.

render (sound, options) TextureSource

Render image as Texture. Only supported with WebAudio

Name Type Attributes Description
sound Sound

Instance of sound to render

options RenderOptions <optional>

Custom rendering options

Returns:
Type Description
TextureSource Result texture

sineTone (hertz, seconds) Sound

Create a new sound for a sine wave-based tone. Only supported with WebAudio

Name Type Default Description
hertz number 200

Frequency of sound.

seconds number 1

Duration of sound in seconds.

Returns:
Type Description
Sound New sound.

validateFormats (typeOverrides) void

Function to validate file type formats. This is called when the library initializes, but can be called again if you need to recognize a format not listed in utils.extensions at initialization.

Name Type Attributes Description
typeOverrides Record<string, string> <optional>
  • Dictionary of type overrides (inputs for AudioElement.canPlayType()), keyed by extension from the utils.extensions array.