2011-01-21 21 views
2

PHPを使用してテキストを音声に変換し、MP3ファイルを生成してユーザに送り返すにはどうすればよいですか?PHPでテキストを音声に変換する方法

ありがとうございます。上記のリンクで説明したように、おそらく次

+2

TTSリンゴを使用することができますPHPが呼び出すサーバ。私はそれが純粋なPHPで実現するとは思わない。 – Sam152

+0

@ Sam152:ファイルを保存するだけで済むので、技術的には純粋なPHP( 'file_put_contents()'、 'pack()')で可能です。しかし、それは無意味なcompletleyだろう。 ;) – Crozin

答えて

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のを使用する場合は、単にあなたはおそらく上のソフトウェアのいくつかの並べ替えを実行する必要があります

shell_exec("say -o test.aiff this is a test"); 
関連する問題