Examples recordgreeting js
From FreeSWITCH Wiki
This simple recording application is intended to be used with the answermachine.js application. It will play a beep tone, and record the greeting (or any other file you name) voice file.
use("TeleTone");
// * recordgreeting.js
// * Written by: Mike B. Murdock for use with FreeSwitch
// * Based on original samples by Anthony Minessale II
// * Revision: 12-28-2006
//
// * Version: MPL 1.1
// *
// * The contents of this file are subject to the Mozilla Public License Version
// * 1.1 (the "License"); you may not use this file except in compliance with
// * the License. You may obtain a copy of the License at
// * http://www.mozilla.org/MPL/
// *
// * Software distributed under the License is distributed on an "AS IS" basis,
// * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
// * for the specific language governing rights and limitations under the
// * License.
// *
// * This simple application is used to record the greeting file for the answermachine.js application
// * It will simply play a bong tone and record the file. You can press # to stop and it will play
// * the new greeting file back.
// Place your recorded greeting here !!IMPORTANT!! THE PATH MUST EXIST
var vMailGreetingFile = "/usr/local/freeswitch/sounds/greeting.wav"
//var BONG = "v=4000;>=0;+=2;#(60,0);v=2000;d(940,0)";
var BONG = "v=4000;>=0;+=2;#(60,0)";
// Maximum recording length in seconds (240 = 4 minutes should be enough)
var maxreclen = 240;
// Energy level audio must fall below to be considered silence (300-500 is good starting point)
var silencethreshold = 500;
// Amount of time in seconds caller must be silent to trigger detector
var silencehits = 10; // we don't want to trigger too soon in this application
var allDigits = "";
function on_dtmf(session, type, digits, arg)
{
if (digits.digit == "#") {
return allDigits;
}
if (digits.digit == "*") {
return "hangup";
}
console_log("digit: " + digits.digit + "\n");
allDigits += digits.digit;
}
// If not answered answer the call
session.answer();
if(session.ready()) {
allDigits = "";
// Play bong
var tts = new TeleTone(session);
tts.addTone("d", 350.0, 440.0, 0.0);
tts.generate(BONG);
// Record message
console_log("Recording greeting\n");
rtn = session.recordFile(vMailGreetingFile, on_dtmf, "", maxreclen, silencethreshold, silencehits);
console_log("Done Recording greeting: rtn=[" + rtn + "]\n");
if (session.ready()) {
// play it back - for testing
rtn = session.streamFile(vMailGreetingFile, "", on_dtmf, "");
// Hangup
session.hangup
}
else {
console_log("Caller Hungup during record\n");
}
}
[edit]
