Кеширование сгенерированных фраз в Redis master
authorRoman Bazalevsky <rvb@rvb.name>
Tue, 27 Sep 2016 16:43:45 +0000 (19:43 +0300)
committerRoman Bazalevsky <rvb@rvb.name>
Tue, 27 Sep 2016 16:43:45 +0000 (19:43 +0300)
festival-php/voice_class_inc.php

index 5f49c36ee2d93cc46a4c38783514962c43a9b7fd..b5ef032ef9e28560ca39961327c1a3eb7e1cc1ac 100644 (file)
@@ -12,7 +12,15 @@ class voice
        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') {
                
@@ -48,6 +56,9 @@ class voice
                }
 
                if (!$proc_result) {
+                 if ($hash) {
+                   $redis->set($hash,$data);
+                 }
                  return $data;
                } else {
                  return '';