]> _ Git - fluidbook-toolbox.git/commitdiff
wait #6306 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 26 Sep 2023 15:41:05 +0000 (17:41 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 26 Sep 2023 15:41:05 +0000 (17:41 +0200)
app/Fluidbook/Compiler/Accessibility.php [new file with mode: 0644]
app/Fluidbook/Compiler/Compiler.php
app/Models/FluidbookPublication.php

diff --git a/app/Fluidbook/Compiler/Accessibility.php b/app/Fluidbook/Compiler/Accessibility.php
new file mode 100644 (file)
index 0000000..964cdee
--- /dev/null
@@ -0,0 +1,103 @@
+<?php
+
+namespace App\Fluidbook\Compiler;
+
+use Cubist\Util\Files\Files;
+use Cubist\Util\Text;
+use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
+
+trait Accessibility
+{
+    protected function writeAccessibility()
+    {
+        if ($this->fluidbookSettings->audiodescriptionTexts) {
+
+            $file = $this->wdir . '/' . $this->fluidbookSettings->audiodescriptionTexts;
+            if (file_exists($file)) {
+                $reader = new Xlsx();
+                $phpexcel = $reader->load($file);
+
+                $sheet = $phpexcel->getActiveSheet();
+                $maxRow = $sheet->getHighestRow('A');
+
+                for ($i = 0; $i <= $maxRow; $i++) {
+                    $page = trim($sheet->getCell('A' . $i)->getValue());
+                    $text = trim($sheet->getCell('B' . $i)->getValue());
+                    $voice = trim($sheet->getCell('C' . $i)->getValue());
+                    if ($page == '' || $text == '') {
+                        continue;
+                    }
+                    $data = ['text' => $text];
+                    if ($voice) {
+                        $data['voice'] = $voice;
+                    }
+                    $this->audioDescriptionTextsList[$page] = $data;
+                }
+            }
+        }
+
+        foreach ($this->audioDescriptionTextsList as $page => $data) {
+            $replace = [
+                '`' => "'",
+                '“' => '"',
+                '”' => '"',
+                '’' => "'",
+                '—' => " - ",
+                '‘' => "'",
+                "…" => "...",
+            ];
+
+            $text = trim($data['text']);
+            $text = str_replace(array_keys($replace), array_values($replace), $text);
+            $text = Text::cleanUTF8($text, '');
+
+            $voiceInfos = $data['voice'] ?? $this->fluidbookSettings->audiodescriptionVoice;
+
+            if ($voiceInfos) {
+                $e = explode(':', $voiceInfos);
+
+                if (count($e) === 1) {
+                    $engine = 'azuretts';
+                    $voice = $voiceInfos;
+                } else {
+                    $engine = $e[0];
+                    $voice = $e[1];
+                }
+
+                $hash = hash('sha256', $engine . ':' . $voice . '_^_' . $text);
+                $fname = $hash . '.mp3';
+                $dir = Files::mkdir(protected_path('audiodescription'));
+
+                $file = $dir . $fname;
+
+                if (!file_exists($file) || filesize($file) === 0) {
+                    if ($engine == 'azuretts') {
+                        $e = explode('/', $voice);
+                        $this->_azureTTS($text, $e[0], $e[1], $e[2], $file);
+                    }
+                }
+
+                $this->config->set('audiodescription.' . $page, $fname);
+                $this->vdir->copy($file, 'data/audiodescription/' . $fname);
+            }
+            $this->accessibleTexts[$page] = $text;
+        }
+
+        if (count($this->accessibleTexts) > 0) {
+            $this->config->accessibleTexts = $this->accessibleTexts;
+        }
+    }
+
+
+    protected function _azureTTS($text, $locale, $gender, $voiceName, $output)
+    {
+        try {
+            $api = new \Cubist\Azure\TTS\Api(env('AZURE_API_KEY'));
+            $api->textToSpeech($text, $locale, $gender, $voiceName, $output);
+            if (!file_exists($output)) {
+                throw new Exception('Error while making tts (' . $output . ') : ' . $text . ', ' . $locale . ', ' . $gender . ', ' . $voiceName);
+            }
+        } catch (Exception $e) {
+        }
+    }
+}
index 0d81f145f47ea3ac478204716bcd3f0144e85e94..5922d57aca2f0773c2f32bbbd571eb9f82a90f4b 100644 (file)
@@ -3,10 +3,7 @@
 namespace App\Fluidbook\Compiler;
 
 use App\Fields\FluidbookFont;
-use App\Fluidbook\Link\Link;
 use App\Fluidbook\PDF;
-use App\Fluidbook\SearchIndex;
-use App\Fluidbook\SEO\Document;
 use App\Fluidbook\SEO\Page;
 use App\Fluidbook\SocialImage;
 use App\Http\Controllers\Admin\Operations\Tools\Favicon;
@@ -14,14 +11,12 @@ use App\Jobs\Base;
 use App\Jobs\FluidbookImagesPreprocess;
 use App\Models\FluidbookPublication;
 use App\Models\FluidbookTheme;
-use App\Models\FluidbookTranslate;
 use App\Models\Signature;
 use App\Models\Traits\FluidbookPlayerBranches;
 use Cubist\Backpack\Magic\Fields\Checkbox;
 use Cubist\Excel\ExcelToArray;
 use Cubist\Locale\Country;
 use Cubist\Locale\Locale;
-use Cubist\PDF\CommandLine\FWSTK;
 use Cubist\Util\ArrayUtil;
 use Cubist\Util\CommandLine;
 use Cubist\Util\Data;
@@ -31,19 +26,13 @@ use Cubist\Util\Graphics\Color;
 use Cubist\Util\Graphics\Image;
 use Cubist\Util\PHP;
 use Cubist\Util\Text;
-use Cubist\Util\WebVideo;
 use Cubist\Util\Zip;
 use DOMDocument;
 use DOMElement;
 use DOMXPath;
-use Exception;
 use Fluidbook\Tools\Compiler\CompilerInterface;
 use Fluidbook\Tools\SVG\SVGTools;
 use Illuminate\Console\Command;
-use Illuminate\Support\Facades\Log;
-use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
-use PhpOffice\PhpSpreadsheet\Spreadsheet;
-use SimpleXMLElement;
 use SplFileInfo;
 
 class Compiler extends Base implements CompilerInterface
@@ -57,6 +46,7 @@ class Compiler extends Base implements CompilerInterface
     use Articles;
     use Cache;
     use Search;
+    use Accessibility;
 
     protected static $uaPrefixes = array('-moz-', '-webkit-', '-o-', '-ms-', '');
 
@@ -760,7 +750,6 @@ class Compiler extends Base implements CompilerInterface
         }
     }
 
-
     protected function _extranetToToolboxPath($path)
     {
         if (str_starts_with($path, '/application/fluidbook/books/working/')) {
@@ -882,100 +871,6 @@ class Compiler extends Base implements CompilerInterface
     }
 
 
-    protected function writeAccessibility()
-    {
-        if ($this->fluidbookSettings->audiodescriptionTexts) {
-
-            $file = $this->wdir . '/' . $this->fluidbookSettings->audiodescriptionTexts;
-            if (file_exists($file)) {
-                $reader = new Xlsx();
-                $phpexcel = $reader->load($file);
-
-                $sheet = $phpexcel->getActiveSheet();
-                $maxRow = $sheet->getHighestRow('A');
-
-                for ($i = 0; $i <= $maxRow; $i++) {
-                    $page = trim($sheet->getCell('A' . $i)->getValue());
-                    $text = trim($sheet->getCell('B' . $i)->getValue());
-                    $voice = trim($sheet->getCell('C' . $i)->getValue());
-                    if ($page == '' || $text == '') {
-                        continue;
-                    }
-                    $data = ['text' => $text];
-                    if ($voice) {
-                        $data['voice'] = $voice;
-                    }
-                    $this->audioDescriptionTextsList[$page] = $data;
-                }
-            }
-        }
-
-        foreach ($this->audioDescriptionTextsList as $page => $data) {
-            $replace = [
-                '`' => "'",
-                '“' => '"',
-                '”' => '"',
-                '’' => "'",
-                '—' => " - ",
-                '‘' => "'",
-                "…" => "...",
-            ];
-
-            $text = trim($data['text']);
-            $text = str_replace(array_keys($replace), array_values($replace), $text);
-            $text = Text::cleanUTF8($text, '');
-
-            $voiceInfos = $data['voice'] ?? $this->fluidbookSettings->audiodescriptionVoice;
-
-            if ($voiceInfos) {
-                $e = explode(':', $voiceInfos);
-
-                if (count($e) === 1) {
-                    $engine = 'azuretts';
-                    $voice = $voiceInfos;
-                } else {
-                    $engine = $e[0];
-                    $voice = $e[1];
-                }
-
-                $hash = hash('sha256', $engine . ':' . $voice . '_^_' . $text);
-                $fname = $hash . '.mp3';
-                $dir = Files::mkdir(protected_path('audiodescription'));
-
-                $file = $dir . $fname;
-
-                if (!file_exists($file) || filesize($file) === 0) {
-                    if ($engine == 'azuretts') {
-                        $e = explode('/', $voice);
-                        $this->_azureTTS($text, $e[0], $e[1], $e[2], $file);
-                    }
-                }
-
-                $this->config->set('audiodescription.' . $page, $fname);
-                $this->vdir->copy($file, 'data/audiodescription/' . $fname);
-            }
-            $this->accessibleTexts[$page] = $text;
-        }
-
-        if (count($this->accessibleTexts) > 0) {
-            $this->config->accessibleTexts = $this->accessibleTexts;
-        }
-    }
-
-
-    protected function _azureTTS($text, $locale, $gender, $voiceName, $output)
-    {
-        try {
-            $api = new \Cubist\Azure\TTS\Api('28fdfcdcc7f141b29cd9db4afc5779c5');
-            $api->textToSpeech($text, $locale, $gender, $voiceName, $output);
-            if (!file_exists($output)) {
-                throw new Exception('Error while making tts (' . $output . ') : ' . $text . ', ' . $locale . ', ' . $gender . ', ' . $voiceName);
-            }
-        } catch (Exception $e) {
-            dd($e);
-        }
-    }
-
     protected function _writeIndex($page)
     {
         if (!isset($this->seo->pages[$page])) {
index 3da16f38d9f2e5d45cfde370435c8bc634a0415c..249990bb59825561b956a9b0fc43a8740a145ac6 100644 (file)
@@ -883,6 +883,9 @@ class FluidbookPublication extends ToolboxSettingsModel
 
     public function getAssetDirId()
     {
+        if ($this->composition_fluidbook && $this->composition_fluidbook_links && $this->composition_fluidbook_id && !$this->assetsDir) {
+            $this->assetsDir = $this->composition_fluidbook_id;
+        }
         return !isset($this->assetsDir) || !$this->assetsDir ? $this->id : trim($this->assetsDir);
     }