title: asterisk - write plugin to "catch" voice stream
body: <p>I have installed Asterisk and FreePBX on a server. I have set up some extensions for testing and I have configured voicemail for these. I have discovered that voice mail files gets stored in <code>/var/spool/asterisk/voicemail/default/(EXTENSION)/tmp/(TMPFILE).wav</code>
  and that they are later moved to <code>/var/spool/asterisk/voicemail/default/(EXTENSION)/INBOX/msg####.wav</code></p>
  
  <p>I want to stream the voice data to another server in real time so that the server can start processing of the data. That is I want to start streaming the data as soon as a call is received by Asterisk and I do not want to wait for the hang up before sending the sound.</p>
  
  <p>I am looking for how to hook into Asterisk to get hold of the voice data. I have a few ideas so far:</p>
  
  <p>1) Regularly check the /tmp directories for new files and start reading them as soon as they are available. But the file names are random and I also want to find out who is calling for example. Seem like a dead end. Files might also get stuck if I read them while Asterisk tries to move them?</p>
  
  <p>2) Maybe I could write a plugin for Asterisk that can pick up the files in the right step of the process. If so, what do I need to write such a plugin and how can I configure it to get access to the voice data as soon as the voice mail module picks up the phone?</p>