update links
This commit is contained in:
parent
7afc521e53
commit
96cb9fac92
33
api/tts.php
Normal file
33
api/tts.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
// api/tts.php
|
||||
header('Content-Type: audio/mpeg');
|
||||
header('Cache-Control: public, max-age=31536000');
|
||||
|
||||
$text = isset($_GET['text']) ? trim($_GET['text']) : '';
|
||||
$lang = isset($_GET['lang']) ? trim($_GET['lang']) : 'en';
|
||||
|
||||
if (empty($text)) {
|
||||
http_response_code(400);
|
||||
exit;
|
||||
}
|
||||
|
||||
$url = 'https://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&tl=' . urlencode($lang) . '&q=' . urlencode($text);
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
||||
'Referer: https://translate.google.com/'
|
||||
]);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
$audioData = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
if ($httpCode === 200 && $audioData) {
|
||||
echo $audioData;
|
||||
} else {
|
||||
http_response_code(500);
|
||||
}
|
||||
@ -131,12 +131,29 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
if (e && e.type === 'keydown' && e.key !== 'Enter' && e.key !== ' ') return;
|
||||
if (window.localStorage.getItem('hospitalQueue:audioEnabled') !== 'false') {
|
||||
initAudio();
|
||||
|
||||
// Prime Speech Synthesis
|
||||
if ('speechSynthesis' in window) {
|
||||
const primeUtterance = new SpeechSynthesisUtterance('');
|
||||
primeUtterance.volume = 0;
|
||||
window.speechSynthesis.speak(primeUtterance);
|
||||
}
|
||||
|
||||
// Prime HTML5 Audio for the origin
|
||||
try {
|
||||
const dummyAudio = new Audio('data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA');
|
||||
dummyAudio.volume = 0.01;
|
||||
const p = dummyAudio.play();
|
||||
if (p !== undefined) p.catch(() => {});
|
||||
} catch (err) {}
|
||||
}
|
||||
document.removeEventListener('click', unlockAudio);
|
||||
document.removeEventListener('keydown', unlockAudio);
|
||||
document.removeEventListener('touchstart', unlockAudio);
|
||||
};
|
||||
document.addEventListener('click', unlockAudio);
|
||||
document.addEventListener('keydown', unlockAudio);
|
||||
document.addEventListener('touchstart', unlockAudio);
|
||||
|
||||
let availableVoices = [];
|
||||
if ('speechSynthesis' in window) {
|
||||
@ -228,8 +245,8 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
let audioObj = null;
|
||||
if (text) {
|
||||
const tl = locale === 'ar' ? 'ar' : 'en';
|
||||
const gTtsUrl = 'https://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&tl=' + tl + '&q=' + encodeURIComponent(text);
|
||||
audioObj = new Audio(gTtsUrl);
|
||||
const ttsUrl = window.location.pathname.replace(/\/[^\/]*$/, '/api/tts.php') + '?lang=' + tl + '&text=' + encodeURIComponent(text);
|
||||
audioObj = new Audio(ttsUrl);
|
||||
audioObj.preload = 'auto'; // Force browser to start downloading
|
||||
}
|
||||
|
||||
@ -260,6 +277,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
utterance.onend = () => { if (videoPlayer) videoPlayer.volume = 1.0; };
|
||||
utterance.onerror = () => { if (videoPlayer) videoPlayer.volume = 1.0; };
|
||||
window.speechSynthesis.cancel(); // Clear any stuck queue
|
||||
window.speechSynthesis.speak(utterance);
|
||||
} else {
|
||||
if (videoPlayer) videoPlayer.volume = 1.0;
|
||||
@ -271,6 +289,14 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
if (playPromise !== undefined) {
|
||||
playPromise.catch(handleFallback);
|
||||
}
|
||||
|
||||
// Failsafe timeout in case audioObj hangs (e.g., blocked by adblocker, bad network)
|
||||
setTimeout(() => {
|
||||
if (audioObj.networkState === HTMLMediaElement.NETWORK_NO_SOURCE || audioObj.error) {
|
||||
handleFallback(new Error("Audio load timeout"));
|
||||
}
|
||||
}, 2500);
|
||||
|
||||
} else {
|
||||
if (videoPlayer) videoPlayer.volume = 1.0;
|
||||
}
|
||||
|
||||
@ -695,12 +695,28 @@ function qh_render_nav(string $activePage): void
|
||||
echo ' </button>';
|
||||
echo ' <div class="collapse navbar-collapse" id="appNav">';
|
||||
echo ' <ul class="navbar-nav ms-auto align-items-lg-center gap-lg-2 mt-3 mt-lg-0">';
|
||||
foreach ($links as $key => $link) {
|
||||
$activeClass = $key === $activePage ? ' active' : '';
|
||||
echo ' <li class="nav-item"><a class="nav-link' . $activeClass . '" href="' . qh_h($link['href']) . '">' . qh_h($link['label']) . '</a></li>';
|
||||
}
|
||||
if (!empty($_SESSION["user_id"])) {
|
||||
$role = $_SESSION["role"] ?? "admin";
|
||||
foreach ($links as $key => $link) {
|
||||
$showLink = false;
|
||||
if ($role === "admin") {
|
||||
$showLink = true;
|
||||
} elseif ($key === "home" || $key === "display") {
|
||||
$showLink = true;
|
||||
} elseif ($key === $role) {
|
||||
$showLink = true;
|
||||
}
|
||||
|
||||
if ($showLink) {
|
||||
$activeClass = $key === $activePage ? ' active' : '';
|
||||
echo ' <li class="nav-item"><a class="nav-link' . $activeClass . '" href="' . qh_h($link['href']) . '">' . qh_h($link['label']) . '</a></li>';
|
||||
}
|
||||
}
|
||||
echo ' <li class="nav-item"><a class="nav-link text-danger fw-semibold" href="' . qh_h(qh_url("logout.php")) . '"><svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="me-1"><path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"></path><polyline points="16 17 21 12 16 7"></polyline><line x1="21" y1="12" x2="9" y2="12"></line></svg>' . qh_h(qh_t("Logout", "تسجيل الخروج")) . '</a></li>';
|
||||
} else {
|
||||
// Show public display link only if not logged in
|
||||
$activeClass = 'display' === $activePage ? ' active' : '';
|
||||
echo ' <li class="nav-item"><a class="nav-link' . $activeClass . '" href="' . qh_h(qh_url('display.php')) . '">' . qh_h(qh_t('Display', 'الشاشة')) . '</a></li>';
|
||||
}
|
||||
|
||||
echo ' </ul>';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user