<p>Friendly Automation <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/18974">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span></span><br></pre><div style="white-space:pre-wrap">Approvals:
Joshua Colp: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved
Friendly Automation: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">app_amd: Add option to play audio during AMD.<br><br>Adds an option that will play an audio file<br>to the party while AMD is running on the<br>channel, so the called party does not just<br>hear silence.<br><br>ASTERISK-30179 #close<br><br>Change-Id: I4af306274552b61b3d9f0883c33f698abd4699b6<br>---<br>M apps/app_amd.c<br>M configs/samples/amd.conf.sample<br>A doc/CHANGES-staging/app_amd.txt<br>3 files changed, 75 insertions(+), 4 deletions(-)<br><br></pre>
<pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/apps/app_amd.c b/apps/app_amd.c</span><br><span>index 39d0b79..fb63c7d 100644</span><br><span>--- a/apps/app_amd.c</span><br><span>+++ b/apps/app_amd.c</span><br><span>@@ -92,6 +92,12 @@</span><br><span> <para>Is the maximum duration of a word to accept.</para></span><br><span> <para>If exceeded, then the result is detection as a MACHINE</para></span><br><span> </parameter></span><br><span style="color: hsl(120, 100%, 40%);">+ <parameter name="audioFile" required="false"></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>Is an audio file to play to the caller while AMD is in progress.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>By default, no audio file is played.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>If an audio file is configured in amd.conf, then that file will be used</span><br><span style="color: hsl(120, 100%, 40%);">+ if one is not specified here. That file may be overridden by this argument.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ </parameter></span><br><span> </syntax></span><br><span> <description></span><br><span> <para>This application attempts to detect answering machines at the beginning</span><br><span>@@ -155,6 +161,9 @@</span><br><span> static int dfltMaximumNumberOfWords = 2;</span><br><span> static int dfltSilenceThreshold = 256;</span><br><span> static int dfltMaximumWordLength = 5000; /* Setting this to a large default so it is not used unless specify it in the configs or command line */</span><br><span style="color: hsl(120, 100%, 40%);">+static char *dfltAudioFile = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static ast_mutex_t config_lock;</span><br><span> </span><br><span> /* Set to the lowest ms value provided in amd.conf or application parameters */</span><br><span> static int dfltMaxWaitTimeForFrame = 50;</span><br><span>@@ -179,7 +188,7 @@</span><br><span> char amdCause[256] = "", amdStatus[256] = "";</span><br><span> char *parse = ast_strdupa(data);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- /* Lets set the initial values of the variables that will control the algorithm.</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Let's set the initial values of the variables that will control the algorithm.</span><br><span> The initial values are the default ones. If they are passed as arguments</span><br><span> when invoking the application, then the default values will be overwritten</span><br><span> by the ones passed as parameters. */</span><br><span>@@ -193,6 +202,7 @@</span><br><span> int silenceThreshold = dfltSilenceThreshold;</span><br><span> int maximumWordLength = dfltMaximumWordLength;</span><br><span> int maxWaitTimeForFrame = dfltMaxWaitTimeForFrame;</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *audioFile = NULL;</span><br><span> </span><br><span> AST_DECLARE_APP_ARGS(args,</span><br><span> AST_APP_ARG(argInitialSilence);</span><br><span>@@ -204,8 +214,15 @@</span><br><span> AST_APP_ARG(argMaximumNumberOfWords);</span><br><span> AST_APP_ARG(argSilenceThreshold);</span><br><span> AST_APP_ARG(argMaximumWordLength);</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_APP_ARG(audioFile);</span><br><span> );</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ ast_mutex_lock(&config_lock);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_strlen_zero(dfltAudioFile)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ audioFile = ast_strdupa(dfltAudioFile);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_mutex_unlock(&config_lock);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> ast_verb(3, "AMD: %s %s %s (Fmt: %s)\n", ast_channel_name(chan),</span><br><span> S_COR(ast_channel_caller(chan)->ani.number.valid, ast_channel_caller(chan)->ani.number.str, "(N/A)"),</span><br><span> S_COR(ast_channel_redirecting(chan)->from.number.valid, ast_channel_redirecting(chan)->from.number.str, "(N/A)"),</span><br><span>@@ -233,6 +250,9 @@</span><br><span> silenceThreshold = atoi(args.argSilenceThreshold);</span><br><span> if (!ast_strlen_zero(args.argMaximumWordLength))</span><br><span> maximumWordLength = atoi(args.argMaximumWordLength);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_strlen_zero(args.audioFile)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ audioFile = args.audioFile;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> } else {</span><br><span> ast_debug(1, "AMD using the default parameters.\n");</span><br><span> }</span><br><span>@@ -280,6 +300,11 @@</span><br><span> /* Set our start time so we can tie the loop to real world time and not RTP updates */</span><br><span> amd_tvstart = ast_tvnow();</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ /* Optional audio file to play to caller while AMD is doing its thing. */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_strlen_zero(audioFile)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_streamfile(chan, audioFile, ast_channel_language(chan));</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /* Now we go into a loop waiting for frames from the channel */</span><br><span> while ((res = ast_waitfor(chan, 2 * maxWaitTimeForFrame)) > -1) {</span><br><span> int ms = 0;</span><br><span>@@ -462,10 +487,14 @@</span><br><span> /* Free the DSP used to detect silence */</span><br><span> ast_dsp_free(silenceDetector);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ /* If we were playing something to pass the time, stop it now. */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_strlen_zero(audioFile)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_stopstream(chan);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> return;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> static int amd_exec(struct ast_channel *chan, const char *data)</span><br><span> {</span><br><span> isAnsweringMachine(chan, data);</span><br><span>@@ -516,7 +545,16 @@</span><br><span> dfltMaximumNumberOfWords = atoi(var->value);</span><br><span> } else if (!strcasecmp(var->name, "maximum_word_length")) {</span><br><span> dfltMaximumWordLength = atoi(var->value);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (!strcasecmp(var->name, "playback_file")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_mutex_lock(&config_lock);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (dfltAudioFile) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(dfltAudioFile);</span><br><span style="color: hsl(120, 100%, 40%);">+ dfltAudioFile = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_strlen_zero(var->value)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ dfltAudioFile = ast_strdup(var->value);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_mutex_unlock(&config_lock);</span><br><span> } else {</span><br><span> ast_log(LOG_WARNING, "%s: Cat:%s. Unknown keyword %s at line %d of amd.conf\n",</span><br><span> app, cat, var->name, var->lineno);</span><br><span>@@ -539,6 +577,12 @@</span><br><span> </span><br><span> static int unload_module(void)</span><br><span> {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_mutex_lock(&config_lock);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (dfltAudioFile) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(dfltAudioFile);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_mutex_unlock(&config_lock);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_mutex_destroy(&config_lock);</span><br><span> return ast_unregister_application(app);</span><br><span> }</span><br><span> </span><br><span>@@ -554,6 +598,7 @@</span><br><span> */</span><br><span> static int load_module(void)</span><br><span> {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_mutex_init(&config_lock);</span><br><span> if (load_config(0) || ast_register_application_xml(app, amd_exec)) {</span><br><span> return AST_MODULE_LOAD_DECLINE;</span><br><span> }</span><br><span>diff --git a/configs/samples/amd.conf.sample b/configs/samples/amd.conf.sample</span><br><span>index d1764b5..b108298 100644</span><br><span>--- a/configs/samples/amd.conf.sample</span><br><span>+++ b/configs/samples/amd.conf.sample</span><br><span>@@ -8,6 +8,11 @@</span><br><span> silence_threshold = 256 ; If the average level of noise in a sample does not reach</span><br><span> ; this value, from a scale of 0 to 32767, then we will consider</span><br><span> ; it to be silence.</span><br><span style="color: hsl(120, 100%, 40%);">+;playback_file = ; Audio file to play while AMD is running, so the caller</span><br><span style="color: hsl(120, 100%, 40%);">+ ; does not just hear silence. Note that specifying this here</span><br><span style="color: hsl(120, 100%, 40%);">+ ; will apply to ALL AMD runs, so you may wish to set it</span><br><span style="color: hsl(120, 100%, 40%);">+ ; in the dialplan as an argument to AMD() instead.</span><br><span style="color: hsl(120, 100%, 40%);">+ ; Default is no audio file (not to play anything).</span><br><span> </span><br><span> ; Greeting ;</span><br><span> initial_silence = 2500 ; Maximum silence duration before the greeting.</span><br><span>@@ -19,7 +24,7 @@</span><br><span> </span><br><span> ; Word detection ;</span><br><span> min_word_length = 100 ; Minimum duration of Voice to considered as a word</span><br><span style="color: hsl(0, 100%, 40%);">-maximum_word_length = 5000 ; Maximum duration of a single Voice utterance allowed.</span><br><span style="color: hsl(120, 100%, 40%);">+maximum_word_length = 5000 ; Maximum duration of a single Voice utterance allowed.</span><br><span> between_words_silence = 50 ; Minimum duration of silence after a word to consider</span><br><span> ; the audio what follows as a new word</span><br><span> </span><br><span>diff --git a/doc/CHANGES-staging/app_amd.txt b/doc/CHANGES-staging/app_amd.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..ffccd8c</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/app_amd.txt</span><br><span>@@ -0,0 +1,5 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: app_amd</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+An audio file to play during AMD processing can</span><br><span style="color: hsl(120, 100%, 40%);">+now be specified to the AMD application or configured</span><br><span style="color: hsl(120, 100%, 40%);">+in the amd.conf configuration file.</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/18974">change 18974</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/18974"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I4af306274552b61b3d9f0883c33f698abd4699b6 </div>
<div style="display:none"> Gerrit-Change-Number: 18974 </div>
<div style="display:none"> Gerrit-PatchSet: 8 </div>
<div style="display:none"> Gerrit-Owner: N A <mail@interlinked.x10host.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>