Playlist

View as Markdown

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.

1import { Voice } from "@signalwire/realtime-api";
2
3const playlist = new Voice.Playlist({ volume: 1.0 })
4 .add(
5 Voice.Playlist.TTS({
6 text: "Welcome to SignalWire!",
7 })
8 )
9 .add(Voice.Playlist.Silence({ duration: 1 }))
10 .add(
11 Voice.Playlist.Audio({
12 url: "https://cdn.signalwire.com/default-music/welcome.mp3",
13 })
14 );

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

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

Properties

media

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

Syntax: Playlist.media()

Returns: NestedArray<Object>


volume

Default volume for the audio in the playlist.

Syntax: Playlist.volume()

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.

1const playlist = new Voice.DeviceBuilder()
2 .add(
3 Voice.Playlist.Audio({
4 url: "https://cdn.signalwire.com/default-music/welcome.mp3",
5 })
6 )
7 .add(Voice.Playlist.Silence({ duration: 1 }))
8 .add(Voice.Playlist.Ringtone({ name: "it", duration: 5 }));
9
10call.play(playlist);

Audio

Static Audio(params): Object

An audio media.

Parameters

NameTypeDescription
paramsobject-
params.urlstringURL of media to play.

Returns

Object

Example

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

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

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

Silence

Static Silence(params): Object

A silence interval.

Parameters

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

Returns

Object

Example

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

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 in ISO 639-1 (language name) + ISO 3166 (country code). Defaults to en-US.
Supported languages can be found here
params.textstringText to play. SSML may be entered as a string wrapped in <speak> tags.
See our supported voices and languages documentation for usage and supported tags.
params.voice?stringVoice to use (takes precedence on gender).
Supported voices can be found here

Returns

Object

Examples

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

Using SSML:

1Voice.Playlist.TTS({
2 text: `<speak>
3 Here are <say-as interpret-as="characters">SSML</say-as> samples.
4 I can pause <break time="3s"/>.
5 I can speak in cardinals. Your number is <say-as interpret-as="cardinal">10</say-as>.
6 Or I can speak in ordinals. You are <say-as interpret-as="ordinal">10</say-as> in line.
7 Or I can even speak in digits. The digits for ten are <say-as interpret-as="characters">10</say-as>.
8 I can also substitute phrases, like the <sub alias="World Wide Web Consortium">W3C</sub>.
9 Finally, I can speak a paragraph with two sentences.
10 <p><s>This is sentence one.</s><s>This is sentence two.</s></p>
11 </speak>
12 `,
13 voice: "polly.Joey-Neural",
14});