0

Hi,

Can anyone tell me how to convert text to speech in PHP? There are some tools like festival and flite etc that can be used for converting text to speech. But i don't have much expertise in PHP.

2
Contributors
2
Replies
5
Views
5 Years
Discussion Span
Last Post by falakniazi
1

You can use festival TTS program for converting text to voice (text to speech) in PHP. Following code is taken from here

<?php
$filename = 'test.txt';
$text = 'This text will be converted to audio recording';
$outputfile = basename($filename, ".txt");
$outputfile = $outputfile . '.wav'; 
if (!$handle = fopen($filename, "w"))
{
    return false;
}
if (fwrite($handle, $text) === FALSE)
{
    return false;
} 
fclose($handle); 
//initialise and execute the festival C engine
//make sure that your environment is set to find the festival binaries!
$cmd = "text2wave $filename -o $outputfile";
//execute the command
exec($cmd); 
unlink($filename);
echo "Recording is successful. \nRecording File: " . $outputfile;
return $outputfile; 
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.