Redial: Interactive Telephony : Week 12

Grab bag.. 1

Sphinx through PHP/AGI

Now that we have Sphinx running faster and communicating with Festival (text2wave) and Asterisk, let's take a look at how we can use the text output that our Sphinx client gives us programmatically.

Here is a dialplan context and a PHP AGI script that calls our Sphinx client/server setup:

		[sve204_sphinxagi]
		exten => s,1,Wait(1);
		exten => s,n,System(/usr/bin/perl /home/sve204/sphinx/sphinxserver.pl &); Start the sphinx server
		exten => s,n,AGI(useragi/sve204/agi_examples/sphinxagi.php); run the agi script
		exten => s,n,Goto(redial_sve204,s,1);
		


		#!/usr/bin/php -qc /var/lib/asterisk/agi-bin/useragi/php_agi.ini
		<?PHP
		require('/var/lib/asterisk/agi-bin/useragi/phpagi.php');
		/*
		exten => s,n,Playback(/home/sve204/sphinx/tellmeyourname);
		exten => s,n,Monitor(wav,/home/sve204/sphinx/name-${UNIQUEID});
		exten => s,n,Wait(5);
		exten => s,n,StopMonitor();
		exten => s,n,Playback(/home/sve204/sphinx/ithinkyousaid);
		exten => s,n,System(/usr/bin/perl /home/sve204/sphinx/sphinxclient_new.pl name-${UNIQUEID}-in.wav | /usr/bin/text2wave -scale 1.5 -F 8000 -o /home/sve204/sphinx/playbackname.wav);
		exten => s,n,Playback(/home/sve204/sphinx/playbackname);
		exten => s,n,Wait(5);
		*/
		
		$agi = new AGI();
		
		$agi->stream_file("/home/sve204/sphinx/tellmeyourname",0);
		//$agi->exec("Monitor","wav|/home/sve204/sphinx/name-" . $agi->request['agi_uniqueid']);        // Separate options with |
		$agi->record_file("/home/sve204/sphinx/name-" . $agi->request['agi_uniqueid'], 'wav', "#", -1, 0, true, 5);
		sleep(5);
		$agi->exec("StopMonitor");
		$agi->stream_file("/home/sve204/sphinx/ithinkyousaid",0);
		//$results = exec("/usr/bin/perl /home/sve204/sphinx/sphinxclient_new.pl /home/sve204/sphinx/name-" . $agi->request['agi_uniqueid'] . "-in.wav");
		$results = exec("/usr/bin/perl /home/sve204/sphinx/sphinxclient_new.pl /home/sve204/sphinx/name-" . $agi->request['agi_uniqueid'] . ".wav");
		//echo("/usr/bin/perl /home/sve204/sphinx/sphinxclient_new.pl /home/sve204/sphinx/name-" . $agi->request['agi_uniqueid'] . "-in.wav\n");
		//echo $results . "\n";
		$agi->say_phonetic($results);
		sleep(10);
		?>
		


Streaming Live from Asterisk

Earlier in the semester I promised that Asterisk had the ability to stream live phone calls. Unfortunately, the capability that it has isn't the most popular streaming format (It uses Ogg instead of MP3) so I came up with a Java EAGI example that could be extended to do more.

Unfortunately, Java has no way of accessing the "process id" of itself which is how Asterisk identifies the audio that is sent. This means that we have to run the EAGI application via an external script which can pass in the PID.

Here is the shell script that is called from asterisk via the EAGI command:

		#!/bin/sh
		/usr/java/jdk1.5.0_09/bin/java -classpath /var/lib/asterisk/agi-bin/useragi/sve204/agi_examples/ JEAGIStreamer $$
		
This is in a file called runEAGIStreamer.sh and is executable by Asterisk.

Here is the dialplan:
		[sve204_eagistream]
		exten => s,1,EAGI(useragi/sve204/agi_examples/runEAGIStreamer.sh);
		exten => s,n,Goto(redial_sve204,s,1);
		
Finally, here is the code of the Java application JEAGIStreamer.java

To compile this you need to at least enter the appropriate server, password and mount point for the Icecast compatible streaming server

Following that, the command to compile on Social is: /usr/java/jdk1.5.0_09/bin/javac JEAGIStreamer.java

To listen to anyone calling my script you would put the following URL into iTunes/WinAMP/Real or pretty much anything else: http://itpmac40.itp.tsoa.nyu.edu:8000/redial