CallRecording

View as Markdown

Represents a recording of a call.

Obtain instances of this class by starting a Recording with one of the following methods:

Example

Record the audio of the call as soon as the other party answers the phone. We also print the ID of the recording and, when the call ends, the URL (which can be used to download the recording).

1import { SignalWire, Voice } from "@signalwire/realtime-api";
2
3const client = await SignalWire({ project: "ProjectID Here", token: "Token Here" })
4
5const call = await client.voice.dialPhone({
6 from: "+YYYYYYYYYY",
7 to: "+XXXXXXXXXX",
8});
9
10await call.playTTS({ text: "This call will be recorded." });
11
12// Start recording
13await call.recordAudio({
14 direction: "both",
15 endSilenceTimeout: 0,
16 terminators: "",
17 listen: {
18 onStarted: async (recording) => {
19 console.log("Recording started", recording.state);
20 call.playTTS({
21 text: "This is a recording test."
22 });
23
24 // Wait 5 seconds
25 setTimeout(async () => {
26 // Stop recording
27 await recording.stop();
28 }, 5000);
29
30 },
31 onEnded: async (recording) => {
32 console.log("Recording ended", recording.state);
33 call.hangup();
34 }
35 }
36}).onStarted();

Properties

id
string

The unique ID for this recording.

state
"recording" | "paused" | "finished" | "no_input"

The current state of the recording.

url
string | undefined

The URL to download the recording. Available after the recording has ended.

size
number | undefined

The size of the recording file in bytes. Available after the recording has ended.

duration
number | undefined

The duration of the recording in seconds. Available after the recording has ended.

hasEnded
boolean

Whether the recording has ended. Returns true if the state is "finished" or "no_input".

Methods

pause

Pauses the recording.

Parameters

behavior
"skip" | "silence"Defaults to "silence"

skip: Does not record during the pause period. silence: Replaces the actual audio of the call with silence during the pause period.

Returns

Promise<CallRecording>

A promise that resolves to the CallRecording when the recording is paused.

Example

1import { SignalWire } from "@signalwire/realtime-api";
2
3const client = await SignalWire({ project: "your-project-id", token: "your-api-token" });
4
5const call = await client.voice.dialPhone({
6 from: "+1xxxxxxxxxx",
7 to: "+1yyyyyyyyyy",
8 timeout: 30
9});
10
11const recording = await call.recordAudio({ direction: "both" }).onStarted();
12// Pause recording (e.g., during sensitive information)
13await recording.pause("skip");

resume

Resumes the recording.

Returns

Promise<CallRecording>

A promise that resolves to the CallRecording when the recording is resumed.

Example

1import { SignalWire } from "@signalwire/realtime-api";
2
3const client = await SignalWire({ project: "your-project-id", token: "your-api-token" });
4
5const call = await client.voice.dialPhone({
6 from: "+1xxxxxxxxxx",
7 to: "+1yyyyyyyyyy",
8 timeout: 30
9});
10
11const recording = await call.recordAudio({ direction: "both" }).onStarted();
12await recording.pause();
13// Resume recording after sensitive information is done
14await recording.resume();

stop

Stops the recording.

Returns

Promise<CallRecording>

A promise that resolves to the CallRecording when the recording is stopped.

Example

1import { SignalWire } from "@signalwire/realtime-api";
2
3const client = await SignalWire({ project: "your-project-id", token: "your-api-token" });
4
5const call = await client.voice.dialPhone({
6 from: "+1xxxxxxxxxx",
7 to: "+1yyyyyyyyyy",
8 timeout: 30
9});
10
11const recording = await call.recordAudio({ direction: "both" }).onStarted();
12console.log("Recording started with ID:", recording.id);
13
14// Stop recording after some time
15await recording.stop();
16console.log("Recording URL:", recording.url);

Events

onStarted

  • CallRecording.listen({ onStarted: Callback }})

Emitted when the recording starts. Your event handler will receive the instance of CallRecording.

Parameters

recording
CallRecordingRequired

The instance of CallRecording that started.

onUpdated

CallRecording.listen({ onUpdated: Callback }})

Emitted when the recording is updated. Your event handler will receive the instance of CallRecording.

Parameters

recording
CallRecordingRequired

The instance of CallRecording that was updated.

onFailed

  • CallRecording.listen({ onFailed: Callback }})

Emitted when the recording fails to start. Your event handler will receive the instance of CallRecording.

Parameters

recording
CallRecordingRequired

The instance of CallRecording that failed.

onEnded

  • CallRecording.listen({ onEnded: Callback }})

Emitted when the recording ends. Your event handler will receive the instance of CallRecording.

Parameters

recording
CallRecordingRequired

The instance of CallRecording that ended.