我正在本地主机上使用 Festival 实现文本到语音转换。我设法生成了一个方案文件,但无法生成 mp3 文件。这是代码
索引.php
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Festival Voice Tester</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script>
function play() {
$.ajax({url: "voice.php?voice=" + $("#voice").val() + "&text=" + $("#text").val(), success: function(result){
console.log(result);
}});
}
</script>
</head>
<body>
<div class="container" style="max-width:500px;padding-top:100px;">
<form method="GET" action="fwrite.php">
<div class="form-group">
<label for="voice">Voice:</label>
<select id="voice" class="form-control">
<?php
echo '<option value="kal_diphine">kal_diphine</option>';
?>
</select>
</div>
<div class="form-group">
<label for="text">Text:</label>
<textarea id="text" class="form-control" rows="5"></textarea>
</div>
<!-- <button class="btn btn-default" onclick="play()" >Listen</button> -->
<button class="btn btn-default">Listen</button>
</form>
<audio controls="true">
</audio>
</div>
</body>
fwrite.php
<?php
$tex= $_GET['text'];
$synth_voice ="(voice_rab_diphone)\n";
$myfile = fopen('/home/david/Desktop/david/newfile.scm', "w") or die("Unable to open file");
fwrite($myfile, $synth_voice);
// create the scheme file for the generation of the voice
fwrite($myfile, "(set! utt1 (Utterance Text $tex))\n");
fwrite($myfile, "(utt.synth utt1)\n");
fwrite($myfile, '(utt.save.wave utt1 "/home/david/Desktop/newf.wav")');
//storing the result in a wav in the specified directory since scheme does not have passing values by reference;
write($myfile, "\n(quit)");
fclose($myfile);
shell_exec('festival /home/david/Desktop/david/newfile.scm');
echo ("wav file generated\n");
shell_exec('aplay /home/david/Desktop/newf.wav');
echo('OK!!\n');
?>
这就是我得到的:
注意:未定义索引:第 2 行 /opt/lampp/htdocs/interface/fwrite.php 中的文本
警告:fopen(/home/david/Desktop/david/newfile.scm):无法打开流:第 4 行 /opt/lampp/htdocs/interface/fwrite.php 中的权限被拒绝 无法打开文件
我希望 fwrite.php 文件返回一个我可以使用音频标签在网络上播放的结果。