0

I'm trying to set up a text-to-speech server on my Mac (Mavericks) using PHP and Python. When I execute the Python script via the terminal, it works fine. However, when I execute it through my browser via PHP, the TTS audio file is generated, but LAME fails to convert the file.

This is what I have in my Python script:

from os import system
import sys
word=sys.argv[1].strip()
system('say -v Allison -o audio/'+word+'.aiff '+word)
system('lame audio/'+word+'.aiff audio/'+word+'.mp3')

And this is my PHP:

<html>
<?php
error_reporting(E_ALL);
if (isset($_GET['word'])){$word=$_GET['word'];}
else {$word="test";}
echo $word;
exec('python tts.py '.$word);
echo "<audio controls><source src='audio/".$word.".mp3'></audio>";
?>
</html>

Any suggestions on what might be going wrong would be very much appreciated.

praine
  • 405
  • 1
  • 3
  • 14

1 Answers1

0

So, I figured out the problem was that while the 'say' exec file was in usr/bin, lame was in usr/bin/local. The following PHP script worked after moving lame to usr/bin, and I was able to do away with the Python completely:

<html>
<?php
error_reporting(E_ALL);
if (isset($_GET['word'])){$word=$_GET['word'];}
else {$word="test";}
echo $word;
//exec('python tts.py '.$word);
exec('say -v Allison -o audio/'.$word.'.aiff '.$word);
exec('lame audio/'.$word.'.aiff audio/'.$word.'.mp3');
echo "<audio controls><source src='audio/".$word.".mp3'></audio>";
?>
</html>
praine
  • 405
  • 1
  • 3
  • 14