recordAudio

View as Markdown

recordAudio

Records the audio from the call.

Parameters

params
object

Object containing the parameters for recording audio.

beep
booleanDefaults to false

Whether to play a beep before recording.

format
"mp3" | "wav"Defaults to mp3

Format of the recording.

stereo
booleanDefaults to false

Whether to record in stereo mode.

direction
"listen" | "speak" | "both"Defaults to speak

Direction to record. Can be listen (what the caller hears), speak (what the caller says), or both.

initialTimeout
numberDefaults to 5.0

How long to wait (in seconds) until something is heard in the recording. Disable by passing 0.

endSilenceTimeout
numberDefaults to 1.0

How long to wait (in seconds) until the caller has stopped speaking. Disable by passing 0.

terminators
stringDefaults to #*

DTMF digits that, when dialed, will end the recording.

inputSensitivity
numberDefaults to 44

Controls how sensitive the voice activity detector is to background noise, where 0 is least sensitive (hear nothing) and 100 is most sensitive (hear everything).

listen
object

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

Returns

Promise<CallRecording>

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

Example

In this example, we dial a phone number and record the call audio. During the recording, we play a TTS message. Once the TTS message is finished, we hangup the call and print the URL of the recording to console.

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
10 topics: ["office"],
11 onCallReceived: async (call) => {
12 console.log("Call received");
13 // Answer the call
14 call.answer();
15
16 await call.recordAudio({
17 beep: true,
18 format: "mp3",
19 direction: "both",
20 initialTimeout: 0,
21 endSilenceTimeout: 0,
22 terminators: "#",
23 stereo: true,
24 listen: {
25 onStarted: async (recording) => {
26 console.log("Recording started");
27 await call.playTTS({
28 text: "This is a call recording test.",
29 });
30 // Stop the recording after the TTS is played
31 recording.stop();
32 },
33 onFailed: () => {
34 console.log("Recording failed");
35 },
36 onUpdated: (recording) => {
37 console.log("Recording updated", recording.state);
38 },
39 onEnded: (recording) => {
40 console.log("Recording ended", recording.url, recording.state);
41 call.hangup();
42 },
43 }
44 }).onStarted();
45 }
46});