Добавлена поддержка RHVoice, все остальное тоже переписано.
[php.git] / festival-php / voice_class_inc.php
1 <?php
2 class voice
3 {
4         
5         function __construct() {
6                 $this->mode = 'rhvoice';
7                 $this->pitch = -0.1;
8                 $this->speed = -0.3;
9                 $this->display = ":99";
10         }
11
12         function text2Wav($string,$lang = "ru")
13         {
14                 
15                 print_r($this);
16                 
17                 if ($this->mode == 'festival') {
18                 
19                         $prolog="/etc/festival/$lang.scm";
20                         if (!file_exists($prolog)) {
21                                 $prolog="/etc/festival/default.scm";
22                         }
23                 
24                         //make sure that your environment is set to find the festival binaries!
25                         $cmd = "festival_client --prolog $prolog --ttw | lame -f - -";
26                 } elseif ($this->mode == 'rhvoice') {
27                         $cmd = "DISPLAY=".$this->display." RHVoice-client -s Anna+CLB -r ".$this->speed." -p ".$this->pitch." | lame -f - -";
28                 }
29                 
30                 print $cmd;
31                 
32                 //execute the command
33                 $descriptorspec = array(
34                     0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
35                     1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
36                     2 => array("pipe", "w")   // stderr is a file to write to
37                   );
38                 $cwd = '/tmp';
39                 $env = array();
40                 $process = proc_open($cmd, $descriptorspec, $pipes, $cwd, $env);
41                 if (is_resource($process)) {
42                         fwrite($pipes[0],$string);
43                         fclose($pipes[0]);
44                         $data = stream_get_contents($pipes[1]);
45                         fclose($pipes[1]);
46                         fclose($pipes[2]);
47                         $proc_result = proc_close($process);
48                 }
49
50                 if (!$proc_result) {
51                   return $data;
52                 } else {
53                   return '';
54                 }
55         }
56         
57 }//end class
58 ?>