<?php
ini_set('error_reporting',8191);
ini_set('display_errors',1);
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Description of espeak
*
* @author len
*/
class espeak {
//put your code here
function __construct() {
;
}
function speak($text){
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 = __DIR__."/".date("Y-m-d-H-i-s").'.mp3';
// echo $file_address = __DIR__;
$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;
}
}
function speak2($text){
define('ESPEAK', '/usr/bin/espeak');
define('LAME', '/usr/bin/lame');
define('COMMAND', ESPEAK.' --stdout -v %s+m3 -p 60 -a 75 -s 130 "%s" | '.LAME.' --preset voice -q 9 --vbr-new - %s');
$lang_voice = 'en';
$input_text = $text;
// $file_path = 'voice-cache/output.mp3';
$file_path = __DIR__."/".'output2.mp3';
$exe_path = sprintf(COMMAND, $lang_voice, $input_text, $file_path); // fills %s spots
// exit();
exec($exe_path);
header('Content-Type: audio/mpeg');
header('Content-Length: '.filesize($file_path));
readfile($file_path);
}
}
$espeak = new espeak();
//$espeak->speak("hello world");
$espeak->speak2("hello world");