play

View as MarkdownOpen in Claude

Play audio or text-to-speech on an active call. Returns a control_id that can be used with playPause(), playResume(), playStop(), and playVolume() to manage the playback.

Request

idstringRequiredformat: "uuid"
The unique identifying ID of a existing call.
paramsobjectRequired
An object of parameters that will be utilized by the active command.

Response

Call LegobjectRequired
Returned when the call is a standard PSTN, SIP, or WebRTC call.
OR
Fabric Subscriber Device LegobjectRequired

Returned when the call is a Fabric subscriber device leg. The status field is always null for this type.

Examples

Play TTS

1import { RestClient } from "@signalwire/sdk";
2
3const client = new RestClient({
4 project: "your-project-id",
5 token: "your-api-token",
6 host: "your-space.signalwire.com"
7});
8
9// Play TTS
10const result = await client.calling.play("call-id-xxx", {
11 play: [{ type: "tts", text: "Hello from the REST API!" }]
12});
13const controlId = result.control_id;

Play Audio File

1import { RestClient } from "@signalwire/sdk";
2
3const client = new RestClient({
4 project: "your-project-id",
5 token: "your-api-token",
6 host: "your-space.signalwire.com"
7});
8
9await client.calling.play("call-id-xxx", {
10 play: [{ type: "audio", url: "https://example.com/greeting.mp3" }]
11});

Play Multiple Items

1import { RestClient } from "@signalwire/sdk";
2
3const client = new RestClient({
4 project: "your-project-id",
5 token: "your-api-token",
6 host: "your-space.signalwire.com"
7});
8
9await client.calling.play("call-id-xxx", {
10 play: [
11 { type: "tts", text: "Please hold while we connect you." },
12 { type: "silence", duration: 1 },
13 { type: "audio", url: "https://example.com/hold-music.mp3" },
14 ]
15});