How to setup eSpeak TTS server for WebSpeech

STEP-1 :   Download and install Espeak

Please get eSpeak  from  http://espeak.sourceforge.net/download.html

STEP-2:  Install  LAME from         http://lame.buanzo.org/

STEP-3:   write a web script to handle request


<?php

if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
  define('ESPEAK', 'C:\xampp\htdocs\eSpeak\command_line\espeak');
  define('LAME', 'C:\xampp\htdocs\eSpeak\command_line\lame');
} else {
  define('ESPEAK', '/usr/bin/espeak');
  define('LAME', '/usr/bin/lame');
}
  $text = $_GET['text'];
if (isset($_GET['voice'])) {
  $voice = $_GET['voice'];
} else {
  $voice = 'en';
}
if (isset($_GET['speedDelta'])) {
  $speed_delta = $_GET['speedDelta'];
} else {
  $speed_delta = 0;
}
  $speed = (int)(175 + 175 * $speed_delta / 100);
if (isset($_GET['pitchDelta'])) {
  $pitch_delta = $_GET['pitchDelta'];
} else {
  $pitch_delta = 0;
}
  $pitch = (int)(50 + $pitch_delta / 2);
if (isset($_GET['volumeDelta'])) {
  $volume_delta = $_GET['volumeDelta'];
} else {
  $volume_delta = 0;
}
  $volume = (int)(100 + $volume_delta);
  $filename = md5($text) . '.mp3';
 
 $filepath =  'voicesmp3/v' . $voice . 's' . $speed . 'p' . $pitch . 'a' . $volume . 't' . $filename;
  $text = escapeshellarg($text);
if (!file_exists($filepath)) {
  $cmd = ESPEAK." -s $speed -p $pitch -a $volume --stdout $text | ".LAME." --preset voice -q 9 --vbr-new - $filepath";
   exec($cmd);
  } 
  header('Content-Type: audio/mpeg');
  header('Content-Length: ' . filesize($filepath));
  readfile($filepath);
?>


 NOTE :  first you install espeak in xamp htdocs
In my case xamp in c drive  after installing espeak you show a folder in htdocs folder name is eSpeak
In espeak folder you see a folder name command_line and lame is install in command_line folder
 You make a folder in htdocs name is testespeak
In testespeak you put a php file name is test.php
And put the above code in test.php
Also make a folder in testespeak folder name is voicesmp3 in this folder mp3 file is show

No comments:

Write a program in PHP to reverse a number

A number can be written in reverse order. For example 12345 = 54321 <?php   $ num = 23456;   $ revnum = 0;   while ($ num > 1)   {   $...