]> _ Git - cubeextranet.git/commitdiff
wait #2475 @0:40
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Thu, 24 Jan 2019 17:45:30 +0000 (17:45 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Thu, 24 Jan 2019 17:45:30 +0000 (17:45 +0000)
inc/ws/Metier/class.ws.book.parametres.php
inc/ws/Util/html5/master/class.ws.html5.compiler.php

index 268317a1b4298b5d026a920fdb2fc521c1165d6e..8e61912369900f856415f55c14dcb734a98c6d8b 100644 (file)
@@ -402,6 +402,8 @@ class wsBookParametres extends wsParametres
                $voices = [
                        '' => '',
                        __('Festival (en-US)') => 'festival:voice_cmu_us_slt_arctic_hts',
+                       __('ReadSpeaker Sophie (en-US)') => 'readspeaker:Sophie/en_us',
+                       __('ReadSpeaker Marc (en-US)') => 'readspeaker:Marc/en_us',
                ];
 
                $this->fields['audiodescriptionTexts'] = ['type' => 'freefile', 'default' => '', 'editable' => true, 'label' => __('Contenus textuels pour l\'audiodescription'), 'fileFilter' => $seoFilter];
index 87b946ffa5a8d5c547a57605ad1ac500f0f67b24..2312a9f518f10748cf4fa5fcd84cae832e4a5f36 100644 (file)
@@ -623,9 +623,10 @@ class wsHTML5Compiler
                        $replace = ['`' => "'",
                                '“' => '"',
                                '”' => '"',
-                               '’'=> "'",
-                               '—'=> " - ",
-                               ];
+                               '’' => "'",
+                               '—' => " - ",
+                               '‘' => "'",
+                       ];
 
                        $text = str_replace(array_keys($replace), array_values($replace), $text);
 
@@ -654,6 +655,9 @@ class wsHTML5Compiler
                                        `lame $tmp $file`;
                                        unlink($tmp);
                                        unlink($tmptext);
+                               } else if ($engine == 'readspeaker') {
+                                       $e = explode('/', $voice);
+                                       $this->_readSpeaker($text, $e[1], $e[0], $file);
                                }
                        }
 
@@ -662,6 +666,43 @@ class wsHTML5Compiler
                }
        }
 
+       protected function _readSpeaker($text, $language, $voice, $output)
+       {
+               $text_to_read = urlencode($text);
+               // Your API key here
+               $apikey = 'e9c321908f2dd016f6a0c34d2d786aff';
+
+               // File path and file name
+               $filepath = $output;
+
+               // API URL of text-to-speech enabler
+               $api_url = 'https://tts.readspeaker.com/a/speak';
+
+               // Compose API call url
+               $url = $api_url . '?key=' . $apikey . '&streaming=0&lang=' . $language . '&voice=' . $voice . '&text=' . $text_to_read;
+
+               // Initiating curl
+               $ch = curl_init($url);
+
+               curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+               curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
+
+               $data = curl_exec($ch);
+
+               $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+
+               if ($status == 200 && !curl_errno($ch)) {
+                       // Everything is fine, close curl and save file
+                       curl_close($ch);
+                       file_put_contents($filepath, $data);
+               } else {
+                       // Cannot translate text to speech because of text-to-speech API error
+                       error_log(__FILE__ . ': API error while text-to-speech. error code=' . $status);
+                       curl_close($ch);
+               }
+
+       }
+
        protected function _writeIndex($page)
        {
                if (!isset($this->seo->pages[$page])) {