$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());
$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'];
}
}
+
$x->addAlert(sprintf(__('%d liens insérés ou mis à jour'), $updated));
}
public $accessibleTexts = [];
protected $_svgSymbols = [];
protected $_addedPDFJS = false;
+ protected $audioDescriptionTextsList = [];
protected $_docDimensions = [];
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);
}
$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];
} 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);
}
}
}
}
+
+ 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);
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()