From 25994c080bed247b2f68dfaf28bd382297929721 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Mon, 31 Jan 2022 18:35:02 +0000 Subject: [PATCH] wait #5065 @1 --- composer.json | 2 +- inc/commons/class.common.ajax.php | 22 ++++-- inc/ws/Controlleur/class.ws.droits.php | 2 + inc/ws/Controlleur/class.ws.maintenance.php | 7 ++ .../html5/master/class.ws.html5.compiler.php | 76 ++++++++++++++----- 5 files changed, 85 insertions(+), 24 deletions(-) diff --git a/composer.json b/composer.json index 04d2d8a55..b8ea51356 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ ], "require": { - "php": ">=7.2", + "php": "7.2.*", "php-mime-mail-parser/php-mime-mail-parser": "2.11.1", "jaybizzle/crawler-detect": "^1.2", "ext-mbstring": "*", diff --git a/inc/commons/class.common.ajax.php b/inc/commons/class.common.ajax.php index 933690a32..a29acc49e 100644 --- a/inc/commons/class.common.ajax.php +++ b/inc/commons/class.common.ajax.php @@ -594,8 +594,10 @@ Mot de passe : $password"; $sheet = $phpexcel->getSheet(0); $maxRow = $sheet->getHighestRow(0); - $updated = 0; + + $add = []; + for ($i = 1; $i <= $maxRow; $i++) { $ref = trim($sheet->getCellByColumnAndRow(0, $i)); $url = trim($sheet->getCellByColumnAndRow(1, $i)->getOldCalculatedValue()); @@ -615,12 +617,21 @@ Mot de passe : $password"; $fref = self::_formatWsReferenceRef($ref, $_POST['type']); $furl = self::_formatWsReferenceUrl($url, $_POST['type']); - try { - $delete = "DELETE FROM wsref WHERE ref='" . $core->con->escape($fref) . "' AND type='" . $core->con->escape($_POST['type']) . "'"; - $core->con->execute($delete); - } catch (Exception $e) { + $add[$fref] = $furl; + } + + try { + $refs = []; + foreach ($add as $fref => $furl) { + $refs[] = "'" . $core->con->escape($fref) . "'"; } + $delete = "DELETE FROM wsref WHERE ref IN(" . implode(',', $refs) . ") AND type='" . $core->con->escape($_POST['type']) . "'"; + $core->con->execute($delete); + } catch (Exception $e) { + } + + foreach ($add as $fref => $furl) { try { $c = $core->con->openCursor('wsref'); $c->type = $_POST['type']; @@ -632,6 +643,7 @@ Mot de passe : $password"; } } + $x->addAlert(sprintf(__('%d liens insérés ou mis à jour'), $updated)); } diff --git a/inc/ws/Controlleur/class.ws.droits.php b/inc/ws/Controlleur/class.ws.droits.php index c83a5d711..44b727aad 100644 --- a/inc/ws/Controlleur/class.ws.droits.php +++ b/inc/ws/Controlleur/class.ws.droits.php @@ -117,6 +117,8 @@ class wsDroits $advancedVoices = [ __('ReadSpeaker Sophie (en-US)') => 'readspeaker:Sophie/en_us', __('ReadSpeaker Marc (en-US)') => 'readspeaker:Marc/en_us', + __('Azure Denise (fr-FR)') => 'azuretts:fr-FR/Female/fr-FR-DeniseNeural', + __('Azure Henry (fr-FR)') => 'azuretts:fr-FR/Male/fr-FR-MaleNeural', ]; if ($rights->creation || $rights->revendeur) { $res = array_merge($res, $freeVoices); diff --git a/inc/ws/Controlleur/class.ws.maintenance.php b/inc/ws/Controlleur/class.ws.maintenance.php index 5f2775b4c..ee0ca3a28 100644 --- a/inc/ws/Controlleur/class.ws.maintenance.php +++ b/inc/ws/Controlleur/class.ws.maintenance.php @@ -1812,6 +1812,13 @@ class wsMaintenance } } + public static function azureTTSVoices() + { + $api = new \Cubist\Azure\TTS\Api('28fdfcdcc7f141b29cd9db4afc5779c5'); + print_r($api->listVoices()); + + } + } diff --git a/inc/ws/Util/html5/master/class.ws.html5.compiler.php b/inc/ws/Util/html5/master/class.ws.html5.compiler.php index d633ca3dd..5f499dfed 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/master/class.ws.html5.compiler.php @@ -227,6 +227,7 @@ class wsHTML5Compiler public $accessibleTexts = []; protected $_svgSymbols = []; protected $_addedPDFJS = false; + protected $audioDescriptionTextsList = []; protected $_docDimensions = []; @@ -1213,33 +1214,42 @@ height="0" width="0" style="display:none;visibility:hidden"> protected function writeAccessibility() { - if (!$this->book->parametres->audiodescriptionTexts) { - return; - } - $file = $this->wdir . '/' . $this->book->parametres->audiodescriptionTexts; - new PHPExcel(); - $reader = new PHPExcel_Reader_Excel2007(); - $phpexcel = $reader->load($file); + if ($this->book->parametres->audiodescriptionTexts) { - $sheet = $phpexcel->getActiveSheet(); - $maxRow = $sheet->getHighestRow(0); + $file = $this->wdir . '/' . $this->book->parametres->audiodescriptionTexts; + if (file_exists($file)) { + new PHPExcel(); + $reader = new PHPExcel_Reader_Excel2007(); + $phpexcel = $reader->load($file); - for ($i = 0; $i <= $maxRow; $i++) { - $page = trim($sheet->getCellByColumnAndRow(0, $i)->getValue()); - $text = trim($sheet->getCellByColumnAndRow(1, $i)->getValue()); - if ($page == '' || $text == '') { - continue; + $sheet = $phpexcel->getActiveSheet(); + $maxRow = $sheet->getHighestRow(0); + + for ($i = 0; $i <= $maxRow; $i++) { + $page = trim($sheet->getCellByColumnAndRow(0, $i)->getValue()); + $text = trim($sheet->getCellByColumnAndRow(1, $i)->getValue()); + if ($page == '' || $text == '') { + continue; + } + $this->audioDescriptionTextsList[$page] = $text; + } } + } - $replace = ['`' => "'", + foreach ($this->audioDescriptionTextsList as $page => $text) { + $replace = [ + '`' => "'", '“' => '"', '”' => '"', '’' => "'", '—' => " - ", '‘' => "'", + "…" => "...", ]; + $text = trim($text); $text = str_replace(array_keys($replace), array_values($replace), $text); + $text = CubeIT_Text::cleanUTF8($text, ''); if ($this->book->parametres->audiodescriptionVoice) { $hash = hash('sha256', $this->book->parametres->audiodescriptionVoice . '_^_' . $text); @@ -1250,9 +1260,15 @@ height="0" width="0" style="display:none;visibility:hidden"> } $file = $dir . $fname; - if (!file_exists($file)) { + + if ($this->book_id === '18860' && file_exists($file)) { + unlink($file); + } + + if (!file_exists($file) || filesize($file) === 0) { $e = explode(':', $this->book->parametres->audiodescriptionVoice); + $engine = $e[0]; $voice = $e[1]; @@ -1270,6 +1286,9 @@ height="0" width="0" style="display:none;visibility:hidden"> } else if ($engine == 'readspeaker') { $e = explode('/', $voice); $this->_readSpeaker($text, $e[1], $e[0], $file); + } else if ($engine == 'azuretts') { + $e = explode('/', $voice); + $this->_azureTTS($text, $e[0], $e[1], $e[2], $file); } } @@ -1285,6 +1304,17 @@ height="0" width="0" style="display:none;visibility:hidden"> } } + + protected function _azureTTS($text, $locale, $gender, $voiceName, $output) + { + try { + $api = new \Cubist\Azure\TTS\Api('28fdfcdcc7f141b29cd9db4afc5779c5'); + $api->textToSpeech($text, $locale, $gender, $voiceName, $output); + } catch (Exception $e) { + dd($e); + } + } + protected function _readSpeaker($text, $language, $voice, $output) { $text_to_read = urlencode($text); @@ -2290,8 +2320,18 @@ height="0" width="0" style="display:none;visibility:hidden"> public function addAudiodescription($link) { - $this->config->audiodescription[$link['page']] = $link['to']; - $this->copyLinkFile($link['to'], 'data/audiodescription/'); + + $e = explode('.', $link['to']); + $ext = mb_strtolower(array_pop($e)); + if ($ext === 'txt') { + $file = $this->wdir . '/' . $link['to']; + if (file_exists($file)) { + $this->audioDescriptionTextsList[$link['page']] = file_get_contents($file); + } + } else { + $this->config->audiodescription[$link['page']] = $link['to']; + $this->copyLinkFile($link['to'], 'data/audiodescription/'); + } } protected function beforeWriteConfig() -- 2.39.5