<div dir="ltr">Thanks Eric,<div><br></div><div>Well, with your guidance and after a fair bit of Googling, experimentation and headscratching, here is the Python version for anyone who wants it....</div><div>Also works with other long AGI background tasks to quickly return to the dialplan when something else is being processed.</div><div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><div><font face="monospace, monospace">import os, sys</font></div></div><div><div><font face="monospace, monospace">from asterisk.agi import AGI</font></div></div><div><div><font face="monospace, monospace">from speechrecgoogle import *</font></div></div><div><div><font face="monospace, monospace"><br></font></div></div><div><div><font face="monospace, monospace">agi = AGI() </font></div></div><div><div><font face="monospace, monospace"><br></font></div></div><div><div><font face="monospace, monospace">recFilename = str(agi.env['agi_arg_1'])</font></div></div><div><div><font face="monospace, monospace"><br></font></div></div><div><div><font face="monospace, monospace">if os.fork(): </font></div></div><div><div><font face="monospace, monospace"> sys.exit(0)</font></div></div><div><div><font face="monospace, monospace">else: </font></div></div><div><div><font face="monospace, monospace"> os.setsid()</font></div></div><div><div><font face="monospace, monospace"> os.close(sys.stdout.fileno())</font></div></div><div><div><font face="monospace, monospace"> response_data = speechrec(recFilename)</font></div></div><div><div><font face="monospace, monospace"> feedback = response_data.results[0].alternatives[0].transcript</font></div></div><div><div><font face="monospace, monospace"> # You now have your plain text feedback which takes a few seconds, but</font></div></div><div><div><font face="monospace, monospace"> # Asterisk has safely already returned to the dialplan or hangup handler </font></div></div></blockquote><div><br></div><div>Hope this helps someone!</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 18 January 2018 at 17:42, Eric Wieling <span dir="ltr"><<a href="mailto:ewieling@nyigc.com" target="_blank">ewieling@nyigc.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF">
<br>
Asterisk (after 1.4?) sends the AGI a HUP when the call hangs up. <br>
<br>
Try setting your script to ignore the HUP signal and make it fork
and go into the background so Asterisk thinks the process has
completed. <br>
<br>
In PHP ignore HUP: <br>
<br>
pcntl_signal(SIGHUP, SIG_IGN);<br>
<br>
In PHP fork and become a short lived daemon:<br>
<br>
$pid = pcntl_fork();<br>
if ($pid == -1) {<br>
die("could not fork");<br>
} elseif ($pid) {<br>
exit; // we are the parent<br>
}<br>
// we are the child<br>
// detatch from the controlling terminal so we don't become
a zombie when we die.<br>
if (posix_setsid() == -1) {<br>
die("could not detach from terminal");<div><div class="h5"><br>
} <br>
<br>
<br>
<div class="m_-1222630755246893055moz-cite-prefix">On 01/18/2018 12:27 PM, Jonathan H
wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">I know that hangup handlers (<a href="https://wiki.asterisk.org/wiki/display/AST/Hangup+Handlers" target="_blank">https://wiki.asterisk.org/<wbr>wiki/display/AST/Hangup+<wbr>Handlers</a>)
have to finish quickly.
<div><br>
</div>
<div>So it's no surprise that my speech to text agi which takes
8 seconds gets killed.</div>
<div><br>
</div>
<div>However, can anyone think of a way round this? So, once the
caller has hung up, I need to take one of the channel
variables, and pass it to a python agi script which then does
speech to text.</div>
<div><br>
</div>
<div>In-call, it works fine. After hangup, it doesn't. Which is
correct, but any thoughts on ways round this?</div>
<div><br>
Thanks.</div>
</div>
<br>
<fieldset class="m_-1222630755246893055mimeAttachmentHeader"></fieldset>
<br>
</blockquote>
<br>
</div></div></div>
</blockquote></div><br></div>