1

Is it possible to use "AMD" to detect silence in EAGI script and receive the audio on fd 3 at the same time?

Is this scenario supported or I am doing something wrong?

Simple demonstration bash script, which is run as EAGI(/home/agi/eagi.sh) from asterisk:

#!/bin/bash

log=/tmp/eagi.log
# Read all variables sent by Asterisk to array
declare -a array
while read -e ARG && [ "$ARG" ] ; do
        array=(` echo $ARG | sed -e 's/://'`)
        export ${array[0]}=${array[1]}
        echo $ARG | sed -e 's/://' >>$log
done

/usr/bin/dd if=/dev/fd/3 of=/tmp/eagi.tmp.out &>>$log &

### or just sleep 10 ###
sleep 1
echo "EXEC AMD"
read line # blocks until silence is detected by AMD
echo $line >>$log
sleep 1
### ###

kill -USR1 %1; sleep 0.1; kill %1
ls -lh /tmp/eagi.tmp.out >>$log

echo "EXEC HANGUP "
read line
echo $line >>$log

exit

What it does is it starts capturing the audio data from fd 3 via dd started as background process. When I have just sleep 10 instead of the echo EXEC AMD, after the 10 seconds, dd has recorded the full audio file.

However with "AMD", dd stops receiving data on fd 3 as soon as the "AMD" is executed (confirmed also via strace) and continues after "AMD" finishes. So while "AMD" is running, no audio is recorded.

Output in the logfile looks like this:

Working (with just sleep):

1522+501 records in
1897+0 records out
971264 bytes (971 kB, 948 KiB) copied, 10.0023 s, 97.1 kB/s
-rw-r--r-- 1 asterisk asterisk 958K Sep 24 10:16 /tmp/eagi.tmp.out

Non-working (with "AMD" which detected silence after 6 seconds, and dd was running the whole time but only 1 second before and 1 second after "AMD" was recorded into the file):

322+101 records in
397+0 records out
203264 bytes (203 kB, 198 KiB) copied, 8.06516 s, 25.2 kB/s
-rw-r--r-- 1 asterisk asterisk 208K Sep 24 10:13 /tmp/eagi.tmp.out

So is this some kind of bug in Asterisk, or just unsupported usage? I didn't find much info about EAGI in the Asterisk documentation, so not sure what is supported and what not. Version of Asterisk is 16.2.1 on Debian 10, the testing call was done via webphone on Chrome browser, audio passed via fd 3 was 48 kHz, 16bit, mono (maybe with some other audio format/codec, both fd 3 and "AMD" would work at the same time?)

EDIT2: Removed info about my complicated setup and added simple reproducible example.

EDIT3: During further debugging I used "EXEC Background" to output some short audio file to the caller and also during this no audio was recorded. So the issue seems to be not only with "EXEC AMD", but also "EXEC Background" and probably also other asterisk applications invoked by "EXEC".

miken32
  • 42,008
  • 16
  • 111
  • 154
Marki555
  • 6,434
  • 3
  • 37
  • 59
  • I bet you are only user who do that strange thing. So answer will be like "nobody know and it highly depend of asterisk version" – arheops Sep 23 '21 at 15:33
  • @arheops Why strange? Using AMD to detect when person stops talking? Or combining AMD with EAGI? I thought it was perfect fit for this purpose... Anyway, any hints on how can I troubleshoot it? Or maybe it depends also on the codec used for that particular call? (version info added to question) – Marki555 Sep 23 '21 at 16:12
  • @miken32 I mention that the main EAGI script is in PHP and it lanuches child script in Python (as the Speech SDK is only in Python), which receives audio data on inherited file descriptor 3. The question is about why the audio does not "flow" while Asterisk built-in "AMD" application is being run by the EAGI script. – Marki555 Sep 23 '21 at 21:48
  • @miken32 Sorry, I removed the confusing info about my setup and managed to create a simple reproducible example. – Marki555 Sep 24 '21 at 08:27
  • @Marki555 Very few people use EAGI. Much smaller number of those use both EAGI and AMD. For debug your case need do not trivial setup, so nobody will do just for answer this question. For sure you can do it via ChanSpy – arheops Sep 24 '21 at 09:25
  • Question is much clearer now, but probably arheops is right you won't find an answer here. The [Asterisk forums](https://community.asterisk.org/) might be a better place to find a subject matter expert. As a best guess I'd say the AMD application captures the audio stream and doesn't "pipe" it through for the EAGI process to receive. – miken32 Sep 24 '21 at 15:09

0 Answers0