<p>N A has uploaded this change for <strong>review</strong>.</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;">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, 41 insertions(+), 3 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/74/18974/1</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..d43f65c 100644</span><br><span>--- a/apps/app_amd.c</span><br><span>+++ b/apps/app_amd.c</span><br><span>@@ -92,6 +92,10 @@</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%);">+ </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 +159,7 @@</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> </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>@@ -193,6 +198,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 = dfltAudioFile;</span><br><span> </span><br><span> AST_DECLARE_APP_ARGS(args,</span><br><span> AST_APP_ARG(argInitialSilence);</span><br><span>@@ -204,6 +210,7 @@</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> ast_verb(3, "AMD: %s %s %s (Fmt: %s)\n", ast_channel_name(chan),</span><br><span>@@ -233,6 +240,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 +290,12 @@</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_stopstream(chan);</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 +478,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 +536,14 @@</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%);">+ 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> } 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 +566,9 @@</span><br><span> </span><br><span> static int unload_module(void)</span><br><span> {</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> return ast_unregister_application(app);</span><br><span> }</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..873b43e 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,10 @@</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 = good-morning ; 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> </span><br><span> ; Greeting ;</span><br><span> initial_silence = 2500 ; Maximum silence duration before the greeting.</span><br><span>@@ -19,7 +23,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..997f346</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/app_amd.txt</span><br><span>@@ -0,0 +1,4 @@</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.</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: 1 </div>
<div style="display:none"> Gerrit-Owner: N A <mail@interlinked.x10host.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>