如何使用 PHP 将文本转换为语音,可能生成 MP3 文件并将其发送回用户?
谢谢。
最佳答案
可能以下是上述链接中提到的代码:
<?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;
?>
关于php - 如何在 PHP 中将文本转换为语音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4755510/