您可以尝试这样的事情,您可以根据需要更改参数(语音),如果 espeak 支持。这用于希腊语测试。您可能还想检查这个答案。
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
define('ESPEAK', 'C:\path\to\eSpeak\command_line\espeak');
define('LAME', 'C:\path\to\eSpeak\command_line\lame');
} else {
define('ESPEAK', '/usr/bin/espeak');
define('LAME', '/usr/bin/lame');
}
$text = 'This is a test';
$voice = "mb-gr2";
$speed_delta = 0;
$speed = 145;
$pitch = 90;
$volume = 100;
$filename = date("Y-m-d-H-i-s").'.mp3';
$text = escapeshellarg($text);
if (!file_exists($filename)) {
$cmd = ESPEAK." -v $voice $text -s $speed -p $pitch -a $volume --stdout | ".LAME." --preset voice -q 9 --vbr-new - $filename";
exec($cmd);
echo $filename;
}