CallRecording
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).
import { SignalWire, Voice } from "@signalwire/realtime-api";
const client = await SignalWire({ project: "ProjectID Here", token: "Token Here" })
const call = await client.voice.dialPhone({
from: "+YYYYYYYYYY",
to: "+XXXXXXXXXX",
});
await call.playTTS({ text: "This call will be recorded." });
// Start recording
await call.recordAudio({
direction: "both",
endSilenceTimeout: 0,
terminators: "",
listen: {
onStarted: async (recording) => {
console.log("Recording started", recording.state);
call.playTTS({
text: "This is a recording test."
});
// Wait 5 seconds
setTimeout(async () => {
// Stop recording
await recording.stop();
}, 5000);
},
onEnded: async (recording) => {
console.log("Recording ended", recording.state);
call.hangup();
}
}
}).onStarted();
Properties
The size of the recording file in bytes. Available after the recording has ended.
The duration of the recording in seconds. Available after the recording has ended.
Whether the recording has ended. Returns true if the state is "finished" or "no_input".
Methods
pause
▸ pause(behavior?): Promise<CallRecording>
Pauses the recording.
Parameters
"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
import { SignalWire } from "@signalwire/realtime-api";
const client = await SignalWire({ project: "your-project-id", token: "your-api-token" });
const call = await client.voice.dialPhone({
from: "+1xxxxxxxxxx",
to: "+1yyyyyyyyyy",
timeout: 30
});
const recording = await call.recordAudio({ direction: "both" }).onStarted();
// Pause recording (e.g., during sensitive information)
await recording.pause("skip");
resume
▸ resume(): Promise<CallRecording>
Resumes the recording.
Returns
Promise<CallRecording>
A promise that resolves to the CallRecording when the recording is resumed.
Example
import { SignalWire } from "@signalwire/realtime-api";
const client = await SignalWire({ project: "your-project-id", token: "your-api-token" });
const call = await client.voice.dialPhone({
from: "+1xxxxxxxxxx",
to: "+1yyyyyyyyyy",
timeout: 30
});
const recording = await call.recordAudio({ direction: "both" }).onStarted();
await recording.pause();
// Resume recording after sensitive information is done
await recording.resume();
stop
▸ stop(): Promise<CallRecording>
Stops the recording.
Returns
Promise<CallRecording>
A promise that resolves to the CallRecording when the recording is stopped.
Example
import { SignalWire } from "@signalwire/realtime-api";
const client = await SignalWire({ project: "your-project-id", token: "your-api-token" });
const call = await client.voice.dialPhone({
from: "+1xxxxxxxxxx",
to: "+1yyyyyyyyyy",
timeout: 30
});
const recording = await call.recordAudio({ direction: "both" }).onStarted();
console.log("Recording started with ID:", recording.id);
// Stop recording after some time
await recording.stop();
console.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
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
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
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
The instance of CallRecording that ended.