set properties for new files (i need to get this documented)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@9960 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.4
Kevin P. Fleming 20 years ago
parent 7616d69a63
commit b9918fb16b

@ -1,412 +1,412 @@
/* /*
* Asterisk -- An open source telephony toolkit. * Asterisk -- An open source telephony toolkit.
* *
* Copyright (C) 2003 - 2006, Aheeva Technology. * Copyright (C) 2003 - 2006, Aheeva Technology.
* *
* Claude Klimos (claude.klimos@aheeva.com) * Claude Klimos (claude.klimos@aheeva.com)
* *
* Disclaimed to Digium * Disclaimed to Digium
* *
* See http://www.asterisk.org for more information about * See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact * the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance; * any of the maintainers of this project for assistance;
* the project provides a web site, mailing lists and IRC * the project provides a web site, mailing lists and IRC
* channels for your use. * channels for your use.
* *
* This program is free software, distributed under the terms of * This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file * the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree. * at the top of the source tree.
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "asterisk/module.h" #include "asterisk/module.h"
#include "asterisk/lock.h" #include "asterisk/lock.h"
#include "asterisk/options.h" #include "asterisk/options.h"
#include "asterisk/channel.h" #include "asterisk/channel.h"
#include "asterisk/dsp.h" #include "asterisk/dsp.h"
#include "asterisk/pbx.h" #include "asterisk/pbx.h"
#include "asterisk/config.h" #include "asterisk/config.h"
#include "asterisk/app.h" #include "asterisk/app.h"
static char *tdesc = "Answering Machine Detection Application"; static char *tdesc = "Answering Machine Detection Application";
static char *app = "AMD"; static char *app = "AMD";
static char *synopsis = "Attempts to detect answering machines"; static char *synopsis = "Attempts to detect answering machines";
static char *descrip = static char *descrip =
" AMD([initialSilence][|greeting][|afterGreetingSilence][|totalAnalysisTime]\n" " AMD([initialSilence][|greeting][|afterGreetingSilence][|totalAnalysisTime]\n"
" [|minimumWordLength][|betweenWordsSilence][|maximumNumberOfWords]\n" " [|minimumWordLength][|betweenWordsSilence][|maximumNumberOfWords]\n"
" [|silenceThreshold])\n" " [|silenceThreshold])\n"
" This application attempts to detect answering machines at the beginning\n" " This application attempts to detect answering machines at the beginning\n"
" of outbound calls. Simply call this application after the call\n" " of outbound calls. Simply call this application after the call\n"
" has been answered (outbound only, of course).\n" " has been answered (outbound only, of course).\n"
" When loaded, AMD reads amd.conf and uses the parameters specified as\n" " When loaded, AMD reads amd.conf and uses the parameters specified as\n"
" default values. Those default values get overwritten when calling AMD\n" " default values. Those default values get overwritten when calling AMD\n"
" with parameters.\n" " with parameters.\n"
"- 'initialSilence' is the maximum silence duration before the greeting. If\n" "- 'initialSilence' is the maximum silence duration before the greeting. If\n"
" exceeded then MACHINE.\n" " exceeded then MACHINE.\n"
"- 'greeting' is the maximum length of a greeting. If exceeded then MACHINE.\n" "- 'greeting' is the maximum length of a greeting. If exceeded then MACHINE.\n"
"- 'afterGreetingSilence' is the silence after detecting a greeting.\n" "- 'afterGreetingSilence' is the silence after detecting a greeting.\n"
" If exceeded then HUMAN.\n" " If exceeded then HUMAN.\n"
"- 'totalAnalysisTime' is the maximum time allowed for the algorithm to decide\n" "- 'totalAnalysisTime' is the maximum time allowed for the algorithm to decide\n"
" on a HUMAN or MACHINE.\n" " on a HUMAN or MACHINE.\n"
"- 'minimumWordLength'is the minimum duration of Voice to considered as a word.\n" "- 'minimumWordLength'is the minimum duration of Voice to considered as a word.\n"
"- 'betweenWordsSilence' is the minimum duration of silence after a word to \n" "- 'betweenWordsSilence' is the minimum duration of silence after a word to \n"
" consider the audio that follows as a new word.\n" " consider the audio that follows as a new word.\n"
"- 'maximumNumberOfWords'is the maximum number of words in the greeting. \n" "- 'maximumNumberOfWords'is the maximum number of words in the greeting. \n"
" If exceeded then MACHINE.\n" " If exceeded then MACHINE.\n"
"- 'silenceThreshold' is the silence threshold.\n" "- 'silenceThreshold' is the silence threshold.\n"
"This application sets the following channel variable upon completion:\n" "This application sets the following channel variable upon completion:\n"
" AMDSTATUS - This is the status of the answering machine detection.\n" " AMDSTATUS - This is the status of the answering machine detection.\n"
" Possible values are:\n" " Possible values are:\n"
" AMD_MACHINE | AMD_PERSON | AMD_NOTSURE | AMD_HANGUP\n" " AMD_MACHINE | AMD_PERSON | AMD_NOTSURE | AMD_HANGUP\n"
" AMDCAUSE - Indicates the cause that led to the conclusion.\n" " AMDCAUSE - Indicates the cause that led to the conclusion.\n"
" Possible values are:\n" " Possible values are:\n"
" AMD_TOOLONG-<%d total_time>\n" " AMD_TOOLONG-<%d total_time>\n"
" AMD_INITIALSILENCE-<%d silenceDuration>-<%d initialSilence>\n" " AMD_INITIALSILENCE-<%d silenceDuration>-<%d initialSilence>\n"
" AMD_HUMAN-<%d silenceDuration>-<%d afterGreetingSilence>\n" " AMD_HUMAN-<%d silenceDuration>-<%d afterGreetingSilence>\n"
" AMD_MAXWORDS-<%d wordsCount>-<%d maximumNumberOfWords>\n" " AMD_MAXWORDS-<%d wordsCount>-<%d maximumNumberOfWords>\n"
" AMD_LONGGREETING-<%d voiceDuration>-<%d greeting>\n"; " AMD_LONGGREETING-<%d voiceDuration>-<%d greeting>\n";
STANDARD_LOCAL_USER; STANDARD_LOCAL_USER;
LOCAL_USER_DECL; LOCAL_USER_DECL;
#define STATE_IN_WORD 1 #define STATE_IN_WORD 1
#define STATE_IN_SILENCE 2 #define STATE_IN_SILENCE 2
/* Some default values for the algorithm parameters. These defaults will be overwritten from amd.conf */ /* Some default values for the algorithm parameters. These defaults will be overwritten from amd.conf */
static int dfltInitialSilence = 2500; static int dfltInitialSilence = 2500;
static int dfltGreeting = 1500; static int dfltGreeting = 1500;
static int dfltAfterGreetingSilence = 800; static int dfltAfterGreetingSilence = 800;
static int dfltTotalAnalysisTime = 5000; static int dfltTotalAnalysisTime = 5000;
static int dfltMinimumWordLength = 100; static int dfltMinimumWordLength = 100;
static int dfltBetweenWordsSilence = 50; static int dfltBetweenWordsSilence = 50;
static int dfltMaximumNumberOfWords = 3; static int dfltMaximumNumberOfWords = 3;
static int dfltSilenceThreshold = 256; static int dfltSilenceThreshold = 256;
static void isAnsweringMachine(struct ast_channel *chan, void *data) static void isAnsweringMachine(struct ast_channel *chan, void *data)
{ {
int res = 0; int res = 0;
struct ast_frame *f = NULL; struct ast_frame *f = NULL;
struct ast_dsp *silenceDetector; /* silence detector dsp */ struct ast_dsp *silenceDetector; /* silence detector dsp */
int dspsilence = 0; int dspsilence = 0;
int readFormat; int readFormat;
int inInitialSilence = 1; int inInitialSilence = 1;
int inGreeting = 0; int inGreeting = 0;
int voiceDuration = 0; int voiceDuration = 0;
int silenceDuration = 0; int silenceDuration = 0;
int iTotalTime = 0; int iTotalTime = 0;
int iWordsCount = 0; int iWordsCount = 0;
int currentState = STATE_IN_SILENCE; int currentState = STATE_IN_SILENCE;
int previousState = STATE_IN_SILENCE; int previousState = STATE_IN_SILENCE;
int consecutiveVoiceDuration = 0; int consecutiveVoiceDuration = 0;
char amdCause[256] = ""; char amdCause[256] = "";
char amdStatus[256] = ""; char amdStatus[256] = "";
/* Lets set the initial values of the variables that will control the algorithm. /* Lets set the initial values of the variables that will control the algorithm.
The initial values are the default ones. If they are passed as arguments The initial values are the default ones. If they are passed as arguments
when invoking the application, then the default values will be overwritten when invoking the application, then the default values will be overwritten
by the ones passed as parameters. */ by the ones passed as parameters. */
int initialSilence = dfltInitialSilence; int initialSilence = dfltInitialSilence;
int greeting = dfltGreeting; int greeting = dfltGreeting;
int afterGreetingSilence = dfltAfterGreetingSilence; int afterGreetingSilence = dfltAfterGreetingSilence;
int totalAnalysisTime = dfltTotalAnalysisTime; int totalAnalysisTime = dfltTotalAnalysisTime;
int minimumWordLength = dfltMinimumWordLength; int minimumWordLength = dfltMinimumWordLength;
int betweenWordsSilence = dfltBetweenWordsSilence; int betweenWordsSilence = dfltBetweenWordsSilence;
int maximumNumberOfWords = dfltMaximumNumberOfWords; int maximumNumberOfWords = dfltMaximumNumberOfWords;
int silenceThreshold = dfltSilenceThreshold; int silenceThreshold = dfltSilenceThreshold;
char *parse; char *parse;
AST_DECLARE_APP_ARGS(args, AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(argInitialSilence); AST_APP_ARG(argInitialSilence);
AST_APP_ARG(argGreeting); AST_APP_ARG(argGreeting);
AST_APP_ARG(argAfterGreetingSilence); AST_APP_ARG(argAfterGreetingSilence);
AST_APP_ARG(argTotalAnalysisTime); AST_APP_ARG(argTotalAnalysisTime);
AST_APP_ARG(argMinimumWordLength); AST_APP_ARG(argMinimumWordLength);
AST_APP_ARG(argBetweenWordsSilence); AST_APP_ARG(argBetweenWordsSilence);
AST_APP_ARG(argMaximumNumberOfWords); AST_APP_ARG(argMaximumNumberOfWords);
AST_APP_ARG(argSilenceThreshold); AST_APP_ARG(argSilenceThreshold);
); );
ast_verbose(VERBOSE_PREFIX_3 "AMD: %s %s %s (Fmt: %d)\n", chan->name ,chan->cid.cid_ani, chan->cid.cid_rdnis, chan->readformat); ast_verbose(VERBOSE_PREFIX_3 "AMD: %s %s %s (Fmt: %d)\n", chan->name ,chan->cid.cid_ani, chan->cid.cid_rdnis, chan->readformat);
/* Lets parse the arguments. */ /* Lets parse the arguments. */
if (ast_strlen_zero(data)) { if (ast_strlen_zero(data)) {
ast_log(LOG_NOTICE, "AMD using the default parameters.\n"); ast_log(LOG_NOTICE, "AMD using the default parameters.\n");
} else { } else {
/* Some arguments have been passed. Lets parse them and overwrite the defaults. */ /* Some arguments have been passed. Lets parse them and overwrite the defaults. */
if (!(parse = ast_strdupa(data))) { if (!(parse = ast_strdupa(data))) {
ast_log(LOG_WARNING, "Memory allocation failure\n"); ast_log(LOG_WARNING, "Memory allocation failure\n");
pbx_builtin_setvar_helper(chan , "AMDSTATUS" , "" ); pbx_builtin_setvar_helper(chan , "AMDSTATUS" , "" );
pbx_builtin_setvar_helper(chan , "AMDCAUSE" , "" ); pbx_builtin_setvar_helper(chan , "AMDCAUSE" , "" );
return; return;
} }
AST_STANDARD_APP_ARGS(args, parse); AST_STANDARD_APP_ARGS(args, parse);
if (!ast_strlen_zero(args.argInitialSilence)) { if (!ast_strlen_zero(args.argInitialSilence)) {
initialSilence = atoi(args.argInitialSilence); initialSilence = atoi(args.argInitialSilence);
} }
if (!ast_strlen_zero(args.argGreeting)) { if (!ast_strlen_zero(args.argGreeting)) {
greeting = atoi(args.argGreeting); greeting = atoi(args.argGreeting);
} }
if (!ast_strlen_zero(args.argAfterGreetingSilence)) { if (!ast_strlen_zero(args.argAfterGreetingSilence)) {
afterGreetingSilence = atoi(args.argAfterGreetingSilence); afterGreetingSilence = atoi(args.argAfterGreetingSilence);
} }
if (!ast_strlen_zero(args.argTotalAnalysisTime)) { if (!ast_strlen_zero(args.argTotalAnalysisTime)) {
totalAnalysisTime = atoi(args.argTotalAnalysisTime); totalAnalysisTime = atoi(args.argTotalAnalysisTime);
} }
if (!ast_strlen_zero(args.argMinimumWordLength)) { if (!ast_strlen_zero(args.argMinimumWordLength)) {
minimumWordLength = atoi(args.argMinimumWordLength); minimumWordLength = atoi(args.argMinimumWordLength);
} }
if (!ast_strlen_zero(args.argBetweenWordsSilence)) { if (!ast_strlen_zero(args.argBetweenWordsSilence)) {
betweenWordsSilence = atoi(args.argBetweenWordsSilence); betweenWordsSilence = atoi(args.argBetweenWordsSilence);
} }
if (!ast_strlen_zero(args.argMaximumNumberOfWords)) { if (!ast_strlen_zero(args.argMaximumNumberOfWords)) {
maximumNumberOfWords = atoi(args.argMaximumNumberOfWords); maximumNumberOfWords = atoi(args.argMaximumNumberOfWords);
} }
if (!ast_strlen_zero(args.argSilenceThreshold)) { if (!ast_strlen_zero(args.argSilenceThreshold)) {
silenceThreshold = atoi(args.argSilenceThreshold); silenceThreshold = atoi(args.argSilenceThreshold);
} }
} }
/* Now we're ready to roll! */ /* Now we're ready to roll! */
ast_verbose(VERBOSE_PREFIX_3 "AMD: initialSilence [%d] greeting [%d] afterGreetingSilence [%d] " ast_verbose(VERBOSE_PREFIX_3 "AMD: initialSilence [%d] greeting [%d] afterGreetingSilence [%d] "
"totalAnalysisTime [%d] minimumWordLength [%d] betweenWordsSilence [%d] maximumNumberOfWords [%d] silenceThreshold [%d] \n", "totalAnalysisTime [%d] minimumWordLength [%d] betweenWordsSilence [%d] maximumNumberOfWords [%d] silenceThreshold [%d] \n",
initialSilence, greeting, afterGreetingSilence, totalAnalysisTime, initialSilence, greeting, afterGreetingSilence, totalAnalysisTime,
minimumWordLength, betweenWordsSilence, maximumNumberOfWords, silenceThreshold ); minimumWordLength, betweenWordsSilence, maximumNumberOfWords, silenceThreshold );
readFormat = chan->readformat; readFormat = chan->readformat;
res = ast_set_read_format(chan, AST_FORMAT_SLINEAR); res = ast_set_read_format(chan, AST_FORMAT_SLINEAR);
if (res < 0 ) { if (res < 0 ) {
ast_log(LOG_WARNING, "AMD: Channel [%s]. Unable to set to linear mode, giving up\n", chan->name ); ast_log(LOG_WARNING, "AMD: Channel [%s]. Unable to set to linear mode, giving up\n", chan->name );
pbx_builtin_setvar_helper(chan , "AMDSTATUS" , "" ); pbx_builtin_setvar_helper(chan , "AMDSTATUS" , "" );
pbx_builtin_setvar_helper(chan , "AMDCAUSE" , "" ); pbx_builtin_setvar_helper(chan , "AMDCAUSE" , "" );
return; return;
} }
silenceDetector = ast_dsp_new(); silenceDetector = ast_dsp_new();
if (!silenceDetector ) { if (!silenceDetector ) {
ast_log(LOG_WARNING, "AMD: Channel [%s]. Unable to create silence detector :(\n", chan->name ); ast_log(LOG_WARNING, "AMD: Channel [%s]. Unable to create silence detector :(\n", chan->name );
pbx_builtin_setvar_helper(chan , "AMDSTATUS" , "" ); pbx_builtin_setvar_helper(chan , "AMDSTATUS" , "" );
pbx_builtin_setvar_helper(chan , "AMDCAUSE" , "" ); pbx_builtin_setvar_helper(chan , "AMDCAUSE" , "" );
return; return;
} }
ast_dsp_set_threshold(silenceDetector, silenceThreshold ); ast_dsp_set_threshold(silenceDetector, silenceThreshold );
while (ast_waitfor(chan, -1) > -1) while (ast_waitfor(chan, -1) > -1)
{ {
f = ast_read(chan); f = ast_read(chan);
if (!f ) { if (!f ) {
/* No Frame: Called Party Must Have Dropped */ /* No Frame: Called Party Must Have Dropped */
ast_verbose(VERBOSE_PREFIX_3 "AMD: HANGUP\n"); ast_verbose(VERBOSE_PREFIX_3 "AMD: HANGUP\n");
ast_log(LOG_DEBUG, "Got hangup\n"); ast_log(LOG_DEBUG, "Got hangup\n");
strcpy(amdStatus , "AMD_HANGUP" ); strcpy(amdStatus , "AMD_HANGUP" );
strcpy(amdCause , "" ); strcpy(amdCause , "" );
break; break;
} }
iTotalTime += 20; iTotalTime += 20;
if (iTotalTime >= totalAnalysisTime ) { if (iTotalTime >= totalAnalysisTime ) {
ast_verbose(VERBOSE_PREFIX_3 "AMD: Channel [%s]. Too long...\n", chan->name ); ast_verbose(VERBOSE_PREFIX_3 "AMD: Channel [%s]. Too long...\n", chan->name );
ast_frfree(f); ast_frfree(f);
strcpy(amdStatus , "AMD_NOTSURE" ); strcpy(amdStatus , "AMD_NOTSURE" );
sprintf(amdCause , "AMD_TOOLONG-%d", iTotalTime ); sprintf(amdCause , "AMD_TOOLONG-%d", iTotalTime );
break; break;
} }
if (f->frametype == AST_FRAME_VOICE ) { if (f->frametype == AST_FRAME_VOICE ) {
dspsilence = 0; dspsilence = 0;
ast_dsp_silence(silenceDetector, f, &dspsilence); ast_dsp_silence(silenceDetector, f, &dspsilence);
if (dspsilence ) { if (dspsilence ) {
silenceDuration = dspsilence; silenceDuration = dspsilence;
/* ast_verbose(VERBOSE_PREFIX_3 "AMD: %d SILENCE: silenceDuration:%d afterGreetingSilence:%d inGreeting:%d\n", currentState, silenceDuration, afterGreetingSilence, inGreeting ); */ /* ast_verbose(VERBOSE_PREFIX_3 "AMD: %d SILENCE: silenceDuration:%d afterGreetingSilence:%d inGreeting:%d\n", currentState, silenceDuration, afterGreetingSilence, inGreeting ); */
if (silenceDuration >= betweenWordsSilence ) { if (silenceDuration >= betweenWordsSilence ) {
if (currentState != STATE_IN_SILENCE ) { if (currentState != STATE_IN_SILENCE ) {
previousState = currentState; previousState = currentState;
ast_verbose(VERBOSE_PREFIX_3 "AMD: Changed state to STATE_IN_SILENCE\n"); ast_verbose(VERBOSE_PREFIX_3 "AMD: Changed state to STATE_IN_SILENCE\n");
} }
currentState = STATE_IN_SILENCE; currentState = STATE_IN_SILENCE;
consecutiveVoiceDuration = 0; consecutiveVoiceDuration = 0;
} }
if (inInitialSilence == 1 && silenceDuration >= initialSilence ) { if (inInitialSilence == 1 && silenceDuration >= initialSilence ) {
ast_verbose(VERBOSE_PREFIX_3 "AMD: ANSWERING MACHINE: silenceDuration:%d initialSilence:%d\n", ast_verbose(VERBOSE_PREFIX_3 "AMD: ANSWERING MACHINE: silenceDuration:%d initialSilence:%d\n",
silenceDuration, initialSilence ); silenceDuration, initialSilence );
ast_frfree(f); ast_frfree(f);
strcpy(amdStatus , "AMD_MACHINE" ); strcpy(amdStatus , "AMD_MACHINE" );
sprintf(amdCause , "AMD_INITIALSILENCE-%d-%d", silenceDuration, initialSilence ); sprintf(amdCause , "AMD_INITIALSILENCE-%d-%d", silenceDuration, initialSilence );
break; break;
} }
if (silenceDuration >= afterGreetingSilence && inGreeting == 1 ) { if (silenceDuration >= afterGreetingSilence && inGreeting == 1 ) {
ast_verbose(VERBOSE_PREFIX_3 "AMD: HUMAN: silenceDuration:%d afterGreetingSilence:%d\n", ast_verbose(VERBOSE_PREFIX_3 "AMD: HUMAN: silenceDuration:%d afterGreetingSilence:%d\n",
silenceDuration, afterGreetingSilence ); silenceDuration, afterGreetingSilence );
ast_frfree(f); ast_frfree(f);
strcpy(amdStatus , "AMD_PERSON" ); strcpy(amdStatus , "AMD_PERSON" );
sprintf(amdCause , "AMD_HUMAN-%d-%d", silenceDuration, afterGreetingSilence ); sprintf(amdCause , "AMD_HUMAN-%d-%d", silenceDuration, afterGreetingSilence );
break; break;
} }
} else { } else {
consecutiveVoiceDuration += 20; consecutiveVoiceDuration += 20;
voiceDuration += 20; voiceDuration += 20;
/* ast_verbose(VERBOSE_PREFIX_3 "AMD: %d VOICE: ConsecutiveVoice:%d voiceDuration:%d inGreeting:%d\n", currentState, consecutiveVoiceDuration, voiceDuration, inGreeting ); */ /* ast_verbose(VERBOSE_PREFIX_3 "AMD: %d VOICE: ConsecutiveVoice:%d voiceDuration:%d inGreeting:%d\n", currentState, consecutiveVoiceDuration, voiceDuration, inGreeting ); */
/* If I have enough consecutive voice to say that I am in a Word, I can only increment the /* If I have enough consecutive voice to say that I am in a Word, I can only increment the
number of words if my previous state was Silence, which means that I moved into a word. */ number of words if my previous state was Silence, which means that I moved into a word. */
if (consecutiveVoiceDuration >= minimumWordLength ) { if (consecutiveVoiceDuration >= minimumWordLength ) {
if (currentState == STATE_IN_SILENCE ) { if (currentState == STATE_IN_SILENCE ) {
iWordsCount++; iWordsCount++;
ast_verbose(VERBOSE_PREFIX_3 "AMD: Word detected. iWordsCount:%d\n", iWordsCount ); ast_verbose(VERBOSE_PREFIX_3 "AMD: Word detected. iWordsCount:%d\n", iWordsCount );
previousState = currentState; previousState = currentState;
currentState = STATE_IN_WORD; currentState = STATE_IN_WORD;
} }
} }
if (iWordsCount >= maximumNumberOfWords ) { if (iWordsCount >= maximumNumberOfWords ) {
ast_verbose(VERBOSE_PREFIX_3 "AMD: ANSWERING MACHINE: iWordsCount:%d\n", iWordsCount ); ast_verbose(VERBOSE_PREFIX_3 "AMD: ANSWERING MACHINE: iWordsCount:%d\n", iWordsCount );
ast_frfree(f); ast_frfree(f);
strcpy(amdStatus , "AMD_MACHINE" ); strcpy(amdStatus , "AMD_MACHINE" );
sprintf(amdCause , "AMD_MAXWORDS-%d-%d", iWordsCount, maximumNumberOfWords ); sprintf(amdCause , "AMD_MAXWORDS-%d-%d", iWordsCount, maximumNumberOfWords );
break; break;
} }
if (inGreeting == 1 && voiceDuration >= greeting ) { if (inGreeting == 1 && voiceDuration >= greeting ) {
ast_verbose(VERBOSE_PREFIX_3 "AMD: ANSWERING MACHINE: voiceDuration:%d greeting:%d\n", ast_verbose(VERBOSE_PREFIX_3 "AMD: ANSWERING MACHINE: voiceDuration:%d greeting:%d\n",
voiceDuration, greeting ); voiceDuration, greeting );
ast_frfree(f); ast_frfree(f);
strcpy(amdStatus , "AMD_MACHINE" ); strcpy(amdStatus , "AMD_MACHINE" );
sprintf(amdCause , "AMD_LONGGREETING-%d-%d", voiceDuration, greeting ); sprintf(amdCause , "AMD_LONGGREETING-%d-%d", voiceDuration, greeting );
break; break;
} }
if (voiceDuration >= minimumWordLength ) { if (voiceDuration >= minimumWordLength ) {
silenceDuration = 0; silenceDuration = 0;
inInitialSilence = 0; inInitialSilence = 0;
inGreeting = 1; inGreeting = 1;
} }
} }
} }
ast_frfree(f); ast_frfree(f);
} }
pbx_builtin_setvar_helper(chan , "AMDSTATUS" , amdStatus ); pbx_builtin_setvar_helper(chan , "AMDSTATUS" , amdStatus );
pbx_builtin_setvar_helper(chan , "AMDCAUSE" , amdCause ); pbx_builtin_setvar_helper(chan , "AMDCAUSE" , amdCause );
/* If We Started With A Valid Read Format, Return To It... */ /* If We Started With A Valid Read Format, Return To It... */
if (readFormat) { if (readFormat) {
res = ast_set_read_format(chan, readFormat ); res = ast_set_read_format(chan, readFormat );
if (res) if (res)
ast_log(LOG_WARNING, "AMD: Unable to restore read format on '%s'\n", chan->name); ast_log(LOG_WARNING, "AMD: Unable to restore read format on '%s'\n", chan->name);
} }
/* Free The Silence Detector DSP */ /* Free The Silence Detector DSP */
ast_dsp_free(silenceDetector ); ast_dsp_free(silenceDetector );
return; return;
} }
static int amd_exec(struct ast_channel *chan, void *data) static int amd_exec(struct ast_channel *chan, void *data)
{ {
struct localuser *u; struct localuser *u;
LOCAL_USER_ADD(u); LOCAL_USER_ADD(u);
isAnsweringMachine(chan, data); isAnsweringMachine(chan, data);
LOCAL_USER_REMOVE(u); LOCAL_USER_REMOVE(u);
return 0; return 0;
} }
static void load_config(void) static void load_config(void)
{ {
struct ast_config *cfg; struct ast_config *cfg;
char *cat; char *cat;
struct ast_variable *var; struct ast_variable *var;
cfg = ast_config_load("amd.conf"); cfg = ast_config_load("amd.conf");
if (!cfg) { if (!cfg) {
ast_log(LOG_ERROR, "Configuration file amd.conf missing.\n"); ast_log(LOG_ERROR, "Configuration file amd.conf missing.\n");
return; return;
} }
cat = ast_category_browse(cfg, NULL); cat = ast_category_browse(cfg, NULL);
while (cat) { while (cat) {
if (!strcasecmp(cat, "amd") ) { if (!strcasecmp(cat, "amd") ) {
var = ast_variable_browse(cfg, cat); var = ast_variable_browse(cfg, cat);
while (var) { while (var) {
if (!strcasecmp(var->name, "initial_silence")) { if (!strcasecmp(var->name, "initial_silence")) {
dfltInitialSilence = atoi(var->value); dfltInitialSilence = atoi(var->value);
} else if (!strcasecmp(var->name, "greeting")) { } else if (!strcasecmp(var->name, "greeting")) {
dfltGreeting = atoi(var->value); dfltGreeting = atoi(var->value);
} else if (!strcasecmp(var->name, "after_greeting_silence")) { } else if (!strcasecmp(var->name, "after_greeting_silence")) {
dfltAfterGreetingSilence = atoi(var->value); dfltAfterGreetingSilence = atoi(var->value);
} else if (!strcasecmp(var->name, "silence_threshold")) { } else if (!strcasecmp(var->name, "silence_threshold")) {
dfltSilenceThreshold = atoi(var->value); dfltSilenceThreshold = atoi(var->value);
} else if (!strcasecmp(var->name, "total_analysis_time")) { } else if (!strcasecmp(var->name, "total_analysis_time")) {
dfltTotalAnalysisTime = atoi(var->value); dfltTotalAnalysisTime = atoi(var->value);
} else if (!strcasecmp(var->name, "min_word_length")) { } else if (!strcasecmp(var->name, "min_word_length")) {
dfltMinimumWordLength = atoi(var->value); dfltMinimumWordLength = atoi(var->value);
} else if (!strcasecmp(var->name, "between_words_silence")) { } else if (!strcasecmp(var->name, "between_words_silence")) {
dfltBetweenWordsSilence = atoi(var->value); dfltBetweenWordsSilence = atoi(var->value);
} else if (!strcasecmp(var->name, "maximum_number_of_words")) { } else if (!strcasecmp(var->name, "maximum_number_of_words")) {
dfltMaximumNumberOfWords = atoi(var->value); dfltMaximumNumberOfWords = atoi(var->value);
} else { } else {
ast_log(LOG_WARNING, "%s: Cat:%s. Unknown keyword %s at line %d of amd.conf\n", ast_log(LOG_WARNING, "%s: Cat:%s. Unknown keyword %s at line %d of amd.conf\n",
app, cat, var->name, var->lineno); app, cat, var->name, var->lineno);
} }
var = var->next; var = var->next;
} }
} }
cat = ast_category_browse(cfg, cat); cat = ast_category_browse(cfg, cat);
} }
ast_config_destroy(cfg); ast_config_destroy(cfg);
ast_verbose(VERBOSE_PREFIX_3 "AMD defaults: initialSilence [%d] greeting [%d] afterGreetingSilence [%d] " ast_verbose(VERBOSE_PREFIX_3 "AMD defaults: initialSilence [%d] greeting [%d] afterGreetingSilence [%d] "
"totalAnalysisTime [%d] minimumWordLength [%d] betweenWordsSilence [%d] maximumNumberOfWords [%d] silenceThreshold [%d] \n", "totalAnalysisTime [%d] minimumWordLength [%d] betweenWordsSilence [%d] maximumNumberOfWords [%d] silenceThreshold [%d] \n",
dfltInitialSilence, dfltGreeting, dfltAfterGreetingSilence, dfltTotalAnalysisTime, dfltInitialSilence, dfltGreeting, dfltAfterGreetingSilence, dfltTotalAnalysisTime,
dfltMinimumWordLength, dfltBetweenWordsSilence, dfltMaximumNumberOfWords, dfltSilenceThreshold ); dfltMinimumWordLength, dfltBetweenWordsSilence, dfltMaximumNumberOfWords, dfltSilenceThreshold );
return; return;
} }
int unload_module(void) int unload_module(void)
{ {
STANDARD_HANGUP_LOCALUSERS; STANDARD_HANGUP_LOCALUSERS;
return ast_unregister_application(app); return ast_unregister_application(app);
} }
int load_module(void) int load_module(void)
{ {
load_config(); load_config();
return ast_register_application(app, amd_exec, synopsis, descrip); return ast_register_application(app, amd_exec, synopsis, descrip);
} }
int reload(void) int reload(void)
{ {
load_config(); load_config();
return 0; return 0;
} }
char *description(void) char *description(void)
{ {
return tdesc; return tdesc;
} }
int usecount(void) int usecount(void)
{ {
int res; int res;
STANDARD_USECOUNT(res); STANDARD_USECOUNT(res);
return res; return res;
} }
char *key() char *key()
{ {
return ASTERISK_GPL_KEY; return ASTERISK_GPL_KEY;
} }

@ -1,24 +1,24 @@
; initial_silence: Maximum silence duration before the greeting. ; initial_silence: Maximum silence duration before the greeting.
; If exceeded then MACHINE. ; If exceeded then MACHINE.
; greeting: Maximum length of a greeting. If exceeded then MACHINE. ; greeting: Maximum length of a greeting. If exceeded then MACHINE.
; after_greeting_silence: Silence after detecting a greeting. ; after_greeting_silence: Silence after detecting a greeting.
; If exceeded then HUMAN ; If exceeded then HUMAN
; total_analysis_time: Maximum time allowed for the algorithm to decide ; total_analysis_time: Maximum time allowed for the algorithm to decide
; on a HUMAN or PERSON ; on a HUMAN or PERSON
; min_word_length: Minimum duration of Voice to considered as a word ; min_word_length: Minimum duration of Voice to considered as a word
; between_words_silence: Minimum duration of silence after a word to consider ; between_words_silence: Minimum duration of silence after a word to consider
; the audio what follows as a new word ; the audio what follows as a new word
; maximum_number_of_words: Maximum number of words in the greeting. ; maximum_number_of_words: Maximum number of words in the greeting.
; If exceeded then MACHINE ; If exceeded then MACHINE
[AnsweringMachineDetector] [AnsweringMachineDetector]
initial_silence = 2500 initial_silence = 2500
greeting = 1500 greeting = 1500
after_greeting_silence = 300 after_greeting_silence = 300
total_analysis_time = 5000 total_analysis_time = 5000
min_word_length = 120 min_word_length = 120
between_words_silence = 50 between_words_silence = 50
maximum_number_of_words = 2 maximum_number_of_words = 2
silence_threshold = 256 silence_threshold = 256

Loading…
Cancel
Save