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 an 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

import { RestClient } from "@signalwire/sdk";
const client = new RestClient({
project: "your-project-id",
token: "your-api-token",
host: "your-space.signalwire.com"
});
// Play TTS
const result = await client.calling.play("call-id-xxx", {
play: [{ type: "tts", text: "Hello from the REST API!" }]
});
const controlId = result.control_id;

Play Audio File

import { RestClient } from "@signalwire/sdk";
const client = new RestClient({
project: "your-project-id",
token: "your-api-token",
host: "your-space.signalwire.com"
});
await client.calling.play("call-id-xxx", {
play: [{ type: "audio", url: "https://example.com/greeting.mp3" }]
});

Play Multiple Items

import { RestClient } from "@signalwire/sdk";
const client = new RestClient({
project: "your-project-id",
token: "your-api-token",
host: "your-space.signalwire.com"
});
await client.calling.play("call-id-xxx", {
play: [
{ type: "tts", text: "Please hold while we connect you." },
{ type: "silence", duration: 1 },
{ type: "audio", url: "https://example.com/hold-music.mp3" },
]
});