9

I want to synthesize Mac OS X speech, but I'm using a PC. Can I set up a PHP server on my Macbook at home, and have it synthesize text for me, and return it to me through a web request?

Like http://mymacbook.com/speak.php?t=why+hello+there

What secret PHP codes will unlock this possibility? I know I can synthesize speech on the command line with say -o "output.aiff" -f "input.txt" but I need help with the connective tissue here.

And no - I do not want links to Cepstral or AT&T's online speech synthesizer, because I want to use special Mac speech synthesis syntax.

Matt Montag
  • 7,105
  • 8
  • 41
  • 47

1 Answers1

14
<?php
    file_put_contents('input.txt', $_GET['t']);
    exec('say -o output.aiff -f input.txt');
    header("Content-Type: audio/x-aiff");
    readfile("output.aiff");
    unlink("output.aiff");
    exit;
mpartel
  • 4,474
  • 1
  • 24
  • 31
  • 5
    Caveat: multiple simultaneous requests can write to those files at once. At best this can have hilarious consequences, but if you don't care for that, use `tempnam()` or similar to generate unique temporary files for both input and output. – mpartel Sep 27 '11 at 02:24
  • Cool - uh oh, what about getting the text from a HTTP GET request? – Matt Montag Sep 27 '11 at 02:33