0

I am implementing text-to-speech using Festival on the localhost. I have managed to produce a scheme file but cannot produce the mp3 file. Here are the codes

index.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');

?>

This is what I get:

Notice: Undefined index: text in /opt/lampp/htdocs/interface/fwrite.php on line 2

Warning: fopen(/home/david/Desktop/david/newfile.scm): failed to open stream: Permission denied in /opt/lampp/htdocs/interface/fwrite.php on line 4 Unable to open file

I would like the fwrite.php file to return a result that I can play on the web using the audio tags.

Community
  • 1
  • 1
davidkihara
  • 493
  • 1
  • 10
  • 30

2 Answers2

0

When you want to submit an HTML form you have to define a name attribute for your inputs. Id is not enough.

      <textarea id="text" class="form-control" name='text' rows="5"></textarea>
Farzad Rastgar Sani
  • 371
  • 1
  • 4
  • 12
0

@avidkihara first you pass variable though textarea. and used GET method so you also add name="text". in textarea. as said @Farzad Rastgar Sani

<form method="GET" action="fwrite.php">
      <div class="form-group">
      <label for="voice">Voice:</label>
      <select id="voice" class="form-control">
        <?= '<option value="kal_diphine">kal_diphine</option>'; ?>
      </select>
    </div>
    <div class="form-group">
      <label for="text">Text:</label>
      <textarea name="text" class="form-control" rows="5"></textarea>
    </div>
    <button class="btn btn-default">Listen</button>
 </form>
Sandesh Mankar
  • 699
  • 4
  • 16