php - 如何在 PHP 中将文本转换为语音

标签 php mp3 text-to-speech

如何使用 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/

相关文章:

php - Wordpress 数据库不小心更改了 URL

php - 如何居中动态生成的div?

.net - 如何在 .NET 中录制在线广播?

android - 使用 FFmpeg 合并 2 个 mp3 文件

api - 您知道评估英语发音的API服务吗?

java - 在微调器中显示 TTS 可用语言

java - 我在 Android 上正确使用文本转语音 TTS 吗

php - 加入belongsToMany并获取所有列

php - 从命令行运行 Zend_Application?

c# - 如何使用 NAudio 将任何音频格式转换为 mp3