It is relatively easy to write voice applications for the Asterisk software PBX using the CGI-like AGI (Asterisk Gateway Interface). The following document describes the AGI and has some examples in Python: http://home.cogeco.ca/~camstuff/agi.html