Кеширование сгенерированных фраз в Redis
[php.git] / festival-php / voice_class_inc.php
index 5f49c36ee2d93cc46a4c38783514962c43a9b7fd..b5ef032ef9e28560ca39961327c1a3eb7e1cc1ac 100644 (file)
@@ -12,7 +12,15 @@ class voice
        function text2Wav($string,$lang = "ru")
        {
                
        function text2Wav($string,$lang = "ru")
        {
                
-               print_r($this);
+               $redis = new Redis();
+               $hash ='';
+               if ($redis->pconnect('127.0.0.1', 6379, 2.5)) {
+                       $hash="voice-".hash("sha256","$lang-$string");
+                       $result=$redis->get($hash);
+                       if ($result) {
+                               return $result;
+                       }
+               }
                
                if ($this->mode == 'festival') {
                
                
                if ($this->mode == 'festival') {
                
@@ -48,6 +56,9 @@ class voice
                }
 
                if (!$proc_result) {
                }
 
                if (!$proc_result) {
+                 if ($hash) {
+                   $redis->set($hash,$data);
+                 }
                  return $data;
                } else {
                  return '';
                  return $data;
                } else {
                  return '';