Skip to main content

Session recordFile

About

Records audio data to a file.

Click here to expand Table of Contents

Error rendering macro 'toc'

null

Synopsis

recordFile(filename, <callback_function>, <[callback_args]>, <[max_len]>, <[silence_threshold]>, <[silence_secs]>);

arguments

  • filename - Full path to filename to write.
  • callback_function - See section below.
  • callback_args - argument to pass to the callback function if called.
  • max_len - maximum length of the recording in seconds
  • silence_threshold - energy level audio must fall below to be considered silence (500 is a good starting point).
  • silence_secs - seconds of silence to interrupt the record.

Returns

Will return anything returned by the callback function, or true/false if no callback is used.

Note: the file must contain an extension known to freeswitch so it can determine the filetype to write. Freeswitch will abort the script if the extension is not provided.

callback_function

The callback function can be used to process DTMF signals that are pressed during the recording. You can use them to abort the recording.

here is a sample method:

 var allDigits = ""; 
function on_dtmf(session, type, obj, arg)
{
try {
if (type == "dtmf") {
allDigits += obj.digit;
console_log("info", "DTMF digit: " + session.name + " [" + obj.digit + "] len [" + obj.duration + "]\n\n");
}
} catch (e) {
console_log("err", e + "\n");
}
return true;
}

Variables

You can specify a number of variables that will be used when saving the file. The variables must be set by using session.setVariable. The variables that can be set are:

  • RECORD_TITLE
  • RECORD_COPYRIGHT
  • RECORD_SOFTWARE
  • RECORD_ARTIST
  • RECORD_COMMENT
  • RECORD_DATE

Example

rtn = session.recordFile("\tmp\recording.wav", on_dtmf, "", 240, 500, 3);