playSilence

View as Markdown

playSilence

Plays some silence.

Parameters

params
objectRequired

Object containing the parameters for playing silence.

duration
numberRequired

Seconds of silence to play.

listen
object

Callback to listen for events. List of playback events can be found here. Example event: onStarted.

Returns

Promise<CallPlayback>

A promise that resolves to a CallPlayback object that you can use to view the current state and results of the play session.

Example

1import { SignalWire } from "@signalwire/realtime-api";
2
3const client = await SignalWire({ project: "ProjectID Here", token: "Token Here" })
4
5const voiceClient = client.voice;
6
7// Listen for incoming calls
8await voiceClient.listen({
9 topics: ["office"],
10 onCallReceived: async (call) => {
11 console.log("Call received");
12 // Answer the call
13 call.answer();
14 // Play Silence on the call for a duration of 3 seconds. Listens for playback events. Ends the call after the silence is finished playing.
15 await call.playSilence({
16 duration: 3,
17 listen: {
18 onStarted: () => console.log("Silence started"),
19 onFailed: () => console.log("Silence failed"),
20 onUpdated: (event) => console.log("Silence updated", event.state),
21 onEnded: (event) => {
22 console.log("Silence ended", event.state);
23 call.hangup();
24 }
25 }
26 }).onStarted();
27 }
28});