Namespace: utils

utils

Utilities that work with sounds.

Members

extensions readonly

The list of extensions that can be played.

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) BaseTexture

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
BaseTexture Result texture

resolveUrl (source) string

Resolve a URL with different formats in glob pattern to a path based on the supported browser format. For instance: "sounds/music.{ogg,mp3}", would resolve to "sounds/music.ogg" if "ogg" support is found, otherwise, fallback to "sounds.music.mp3"

Name Type Description
source string | PIXI.LoaderResource
  • Path to resolve or Resource, if a Resource object is provided, automatically updates the extension and url of that object.
Returns:
Type Description
string The format to resolve to

sineTone (hertz, seconds) Sound

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

Name Type Default Description
hertz 200

Frequency of sound.

seconds 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.