CallPlayback

View as Markdown

Represents a current or past playback in a call. You can obtain instances of this class by starting a Playback with one of the following methods:

Example

Playing a text-to-speech message and waiting for it to end before proceeding to the next instructions.

1import { Voice } from "@signalwire/realtime-api";
2
3const client = new Voice.Client({
4 project: "<project-id>",
5 token: "<api-token>",
6 topics: ["office"],
7});
8
9const call = await client.dialPhone({
10 from: "+YYYYYYYYYY",
11 to: "+XXXXXXXXXX",
12});
13
14const playback = await call.playTTS({ text: "Welcome to SignalWire!" });
15await playback.ended();

Properties

id

The unique id for this playback.

Syntax: CallPlayback.id()

Returns: string

Methods

pause

  • pause(): Promise<CallPlayback> - See CallPlayback for more details.

Pauses the playback.

Returns

Promise<CallPlayback> - See CallPlayback for more details.

Example

1const playback = await call.playAudio({
2 url: "https://cdn.signalwire.com/default-music/welcome.mp3",
3});
4await playback.pause();

ended

  • ended(): Promise<CallPlayback> - See CallPlayback for more details.

Returns a promise that is resolved only after this playback finishes playing (or is stopped).

Returns

Promise<CallPlayback> - See CallPlayback for more details.

Example

1const playback = await call.playAudio({
2 url: "https://cdn.signalwire.com/default-music/welcome.mp3",
3});
4await playback.ended();

resume

  • resume(): Promise<CallPlayback> - See CallPlayback for more details.

Resumes the playback if it was paused.

Returns

Promise<CallPlayback> - See CallPlayback for more details.

Example

1const playback = await call.playAudio({
2 url: "https://cdn.signalwire.com/default-music/welcome.mp3",
3});
4await playback.resume();

setVolume

  • setVolume(volume): Promise<CallPlayback> - See CallPlayback for more details.

Changes the volume of the playback.

Parameters

NameTypeDescription
volumenumberVolume value between -40dB and +40dB.

Returns

Promise<CallPlayback> - See CallPlayback for more details.

Example

1const playback = await call.playAudio({
2 url: "https://cdn.signalwire.com/default-music/welcome.mp3",
3});
4await playback.setVolume(-20);

stop

  • stop(): Promise<CallPlayback> - See CallPlayback for more details.

Stops the playback.

Returns

Promise<CallPlayback> - See CallPlayback for more details.

Example

1const playback = await call.playAudio({
2 url: "https://cdn.signalwire.com/default-music/welcome.mp3",
3});
4await playback.stop();

waitForEnded

  • waitForEnded(): Promise<CallPlayback> - See CallPlayback for more details.

Returns a promise that is resolved only after this playback finishes playing (or is stopped).

This method is deprecated. See ended instead.