From 06edffc2f7f6324b194bebdd527d2fcecdb13364 Mon Sep 17 00:00:00 2001
From: Roman Bazalevsky <rvb@rvb.name>
Date: Sat, 24 Sep 2016 12:51:34 +0300
Subject: [PATCH] =?utf8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?=
 =?utf8?q?=D0=B0=20=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6=D0=BA=D0=B0?=
 =?utf8?q?=20RHVoice,=20=D0=B2=D1=81=D0=B5=20=D0=BE=D1=81=D1=82=D0=B0?=
 =?utf8?q?=D0=BB=D1=8C=D0=BD=D0=BE=D0=B5=20=D1=82=D0=BE=D0=B6=D0=B5=20?=
 =?utf8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=BF=D0=B8=D1=81=D0=B0=D0=BD=D0=BE.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=utf8
Content-Transfer-Encoding: 8bit

---
 festival-php/README              |  2 ++
 festival-php/index.php           |  4 +--
 festival-php/voice_class_inc.php | 58 ++++++++++++++++++++++++++++++++
 3 files changed, 62 insertions(+), 2 deletions(-)
 create mode 100644 festival-php/README
 create mode 100644 festival-php/voice_class_inc.php

diff --git a/festival-php/README b/festival-php/README
new file mode 100644
index 0000000..a0d5b36
--- /dev/null
+++ b/festival-php/README
@@ -0,0 +1,2 @@
+Поддерживает festival (работающий в режиме демона) и rhvoice (через DBUS). В последнем случае требует 
+(из-за зависимостей dbus в Ubuntu) наличия Xvfb.
diff --git a/festival-php/index.php b/festival-php/index.php
index 769b8ce..4b0a5e1 100644
--- a/festival-php/index.php
+++ b/festival-php/index.php
@@ -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
index 0000000..5f49c36
--- /dev/null
+++ b/festival-php/voice_class_inc.php
@@ -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
-- 
2.34.1