<?php
/*
 * Turning Sound Generator
 *
 * Copyright (c) 2004 Colin Viebrock <colin@viebrock.ca>
 * 
 * Usage of the works is permitted provided that this
 * instrument is retained with the works, so that any entity
 * that uses the works is notified of this instrument.
 * 
 * DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
 */

session_start();

/* path to flite */

$FLITE '/usr/bin/flite';

/* We need to add spaces to the turing string, to make it "spelled" instead of "read" */

$string strtolower$_SESSION['turing_string'] );
$string trimpreg_replace('/(.)/''$1, '$string) );
$string preg_replace('/,$/''.'$string );


/* find a temporary place to store the WAV file (flite doesn't support output to stdout) */

$tempfile tempnam('/tmp''turing');


/* build the command and run it */

$cmd $FLITE ' -t "' $string '" -i ' $tempfile;
`
$cmd`;


/* output the right header, and passthrough the temp file */

header('Content-Type: audio/x-wav');
header('Content-Length: ' filesize($tempfile) );
#header('X-Command: ' . $cmd );
readfile($tempfile);


/* cleanup */

unlink($tempfile);