2011-01-21 123 views
2

如何使用PHP將文本轉換爲語音,可能會生成一個MP3文件並將其發回給用戶?如何在PHP中將文本轉換爲語音

謝謝。

+2

您可能需要運行某種軟件PHP調用的服務器。我認爲用純PHP做這件事並不可行。 – Sam152 2011-01-21 04:56:17

回答

1

也許下面是在上面的鏈接提到的代碼:

<?php 
//create a random number filename so that simultaneous users don't overwrite each other 
$filename = 'test.txt'; 
$text = 'This text will be converted to audio recording'; 
$outputfile = basename($filename, ".txt"); 
$outputfile = $outputfile . '.wav'; 

if (!$handle = fopen($filename, "w")) 
{ 
    //we cannot open the file handle! 
    return false; 
} 
// Write $text to our opened file. 
if (fwrite($handle, $text) === FALSE) 
{ 
    //couldn't write the file...Check permissions 
    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; 
//finally return the uptput file path and filename 
return $outputfile; 

?> 
0

,如果你使用的MacOS,你可以簡單地使用蘋果TTS

shell_exec("say -o test.aiff this is a test");