Skip to main content

Playlist

A Playlist object allows you to specify a series of media which should be played in sequence. You can then pass the playlist to the methods that support it, for example Call.play.

Example

Creates a playlist for playing, in sequence, a TTS message, 1 second of silence, and an mp3 file.

import { Voice } from "@signalwire/realtime-api";

const playlist = new Voice.Playlist({ volume: 1.0 })
.add(
Voice.Playlist.TTS({
text: "Welcome to SignalWire!",
})
)
.add(Voice.Playlist.Silence({ duration: 1 }))
.add(
Voice.Playlist.Audio({
url: "https://cdn.signalwire.com/default-music/welcome.mp3",
})
);

Constructors

constructor

new Playlist(params?)

Instantiates an empty Playlist. Use the add method to add media to this Playlist.

Parameters

NameTypeDescription
params?Object-
params.volume?numberDefault volume to apply to the media in the playlist, between -40dB and +40dB. Default is 0.

Example

const playlist = new Voice.Playlist({ volume: 1.0 });

Accessors

media

get media(): NestedArray<Object>

Get the list of media that have been added to this Playlist.

Returns

NestedArray<Object>


volume

get volume(): undefined | number

Default volume for the audio in the playlist.

Returns

undefined | number

Methods

add

add(params): Playlist

Adds the speecified media in series to the Playlist.

Parameters

NameTypeDescription
paramsObjectA media object. See Audio, Ringtone, Silence, and TTS.

Returns

Playlist

Example

A playlist to play some audio, then a short silence, and finally a ringtone.

const playlist = new Voice.DeviceBuilder()
.add(
Voice.Playlist.Audio({
url: "https://cdn.signalwire.com/default-music/welcome.mp3",
})
)
.add(Voice.Playlist.Silence({ duration: 1 }))
.add(Voice.Playlist.Ringtone({ name: "it", duration: 5 }));

call.play(playlist);

Audio

Static Audio(params): Object

An audio media.

Parameters

NameTypeDescription
paramsobject-
params.urlstringURL of media to play.

Returns

Object

Example

Voice.Playlist.Audio({
url: "https://cdn.signalwire.com/default-music/welcome.mp3",
});

Ringtone

Static Ringtone(params): Object

A ringtone media.

Parameters

NameTypeDescription
paramsobject-
params.duration?numberHow long to play ringtone, in seconds.
params.nameRingtoneNameName of the ringtone to play.

Returns

Object

Example

Voice.Playlist.Ringtone({
name: "it",
duration: 30,
});

Silence

Static Silence(params): Object

A silence interval.

Parameters

NameTypeDescription
paramsobject-
params.durationnumberHow long to play silence, in seconds.

Returns

Object

Example

Voice.Playlist.Silence({
duration: 2,
});

TTS

Static TTS(params): Object

A TTS media.

Parameters

NameTypeDescription
paramsobject-
params.gender?'female' | 'male'Gender of the voice. Defaults to female.
params.language?stringLanguage of the text. Defaults to en-US.
params.textstringText to be converted to speech.
params.voice?stringVoice to use (takes precedence on gender). Use "polly.<name>" for Amazon Polly voices, or "gcloud.<name>" for Google Cloud voices.

Returns

Object

Example

Voice.Playlist.TTS({
text: "Welcome to SignalWire!",
gender: "male",
language: "en-US",
});