Добавлена поддержка RHVoice, все остальное тоже переписано.
authorRoman Bazalevsky <rvb@rvb.name>
Sat, 24 Sep 2016 09:51:34 +0000 (12:51 +0300)
committerRoman Bazalevsky <rvb@rvb.name>
Sat, 24 Sep 2016 09:51:34 +0000 (12:51 +0300)
festival-php/README [new file with mode: 0644]
festival-php/index.php
festival-php/voice_class_inc.php [new file with mode: 0644]

diff --git a/festival-php/README b/festival-php/README
new file mode 100644 (file)
index 0000000..a0d5b36
--- /dev/null
@@ -0,0 +1,2 @@
+Поддерживает festival (работающий в режиме демона) и rhvoice (через DBUS). В последнем случае требует 
+(из-за зависимостей dbus в Ubuntu) наличия Xvfb.
index 769b8ce82490310b07ae4a03085a1c15a37a8229..4b0a5e13f936391aa0fd10a5057b58130b2dd014 100644 (file)
@@ -7,8 +7,8 @@ if ( !$text ) {
   exit;
 }
 
-include("festival_class_inc.php");
-$tts = new festival;
+include("voice_class_inc.php");
+$tts = new voice;
 $data=$tts->text2Wav($text,$lang);
 
 if ($data) {
diff --git a/festival-php/voice_class_inc.php b/festival-php/voice_class_inc.php
new file mode 100644 (file)
index 0000000..5f49c36
--- /dev/null
@@ -0,0 +1,58 @@
+<?php
+class voice
+{
+       
+       function __construct() {
+               $this->mode = 'rhvoice';
+               $this->pitch = -0.1;
+               $this->speed = -0.3;
+               $this->display = ":99";
+       }
+
+       function text2Wav($string,$lang = "ru")
+       {
+               
+               print_r($this);
+               
+               if ($this->mode == 'festival') {
+               
+                       $prolog="/etc/festival/$lang.scm";
+                       if (!file_exists($prolog)) {
+                               $prolog="/etc/festival/default.scm";
+                       }
+               
+                       //make sure that your environment is set to find the festival binaries!
+                       $cmd = "festival_client --prolog $prolog --ttw | lame -f - -";
+               } elseif ($this->mode == 'rhvoice') {
+                       $cmd = "DISPLAY=".$this->display." RHVoice-client -s Anna+CLB -r ".$this->speed." -p ".$this->pitch." | lame -f - -";
+               }
+               
+               print $cmd;
+               
+               //execute the command
+               $descriptorspec = array(
+                   0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
+                   1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
+                   2 => array("pipe", "w")   // stderr is a file to write to
+                 );
+               $cwd = '/tmp';
+               $env = array();
+               $process = proc_open($cmd, $descriptorspec, $pipes, $cwd, $env);
+               if (is_resource($process)) {
+                       fwrite($pipes[0],$string);
+                       fclose($pipes[0]);
+                       $data = stream_get_contents($pipes[1]);
+                       fclose($pipes[1]);
+                       fclose($pipes[2]);
+                       $proc_result = proc_close($process);
+               }
+
+               if (!$proc_result) {
+                 return $data;
+               } else {
+                 return '';
+               }
+       }
+       
+}//end class
+?>
\ No newline at end of file