From: Roman Bazalevsky Date: Sat, 24 Sep 2016 09:51:34 +0000 (+0300) Subject: Добавлена поддержка RHVoice, все остальное тоже переписано. X-Git-Url: https://git.rvb.name/php.git/commitdiff_plain/06edffc2f7f6324b194bebdd527d2fcecdb13364?hp=0ec8149ead12060359d02e6b1cbf3a91fad19af8 Добавлена поддержка RHVoice, все остальное тоже переписано. --- 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 @@ +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