--- /dev/null
+<?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) {
+ }
+ }
+}
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;
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;
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
use Articles;
use Cache;
use Search;
+ use Accessibility;
protected static $uaPrefixes = array('-moz-', '-webkit-', '-o-', '-ms-', '');
}
}
-
protected function _extranetToToolboxPath($path)
{
if (str_starts_with($path, '/application/fluidbook/books/working/')) {
}
- 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])) {