Spaces:
Running
Running
Upload app.js with huggingface_hub
Browse files1204 unmodified lines12051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321204 unmodified lines}}// For non-English languages (e.g. Tamil, Hindi, Telugu, Malayalam, etc.)// Windows browsers lack native speech packs by default, causing silent failure.// We stream high-quality native voice audio directly.if (currentTargetLang !== 'en') {try {const audioUrl = serverAvailable? `/tts_audio?tl=${encodeURIComponent(currentTargetLang)}&q=${encodeURIComponent(text)}`: `https://translate.google.com/translate_tts?ie=UTF-8&tl=${encodeURIComponent(currentTargetLang)}&client=tw-ob&q=${encodeURIComponent(text)}`;const audio = new Audio(audioUrl);audio.onended = resetSpeakButton;audio.onerror = () => {console.warn('[SignLens] Audio TTS failed, attempting browser SpeechSynthesis fallback');speakViaSpeechSynthesis(text, langInfo, btnSpeak, resetSpeakButton);};audio.play().catch(err => {console.warn('[SignLens] Audio play blocked or failed:', err);speakViaSpeechSynthesis(text, langInfo, btnSpeak, resetSpeakButton);});return;} catch (err) {console.warn('[SignLens] Native Audio TTS error:', err);}}// Default English or SpeechSynthesis pathway1204 unmodified lines1205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491204 unmodified lines}}// Multi-tiered audio stream for non-English languages (Tamil, Hindi, Telugu, Malayalam, etc.)// Even when hosted as a static site without a server, we try cascading endpoints:// 1) /tts_audio backend (if Flask running)// 2) Free open-source TTS proxy / CORS-enabled endpoints// 3) Browser SpeechSynthesis with dialect fallbackif (currentTargetLang !== 'en') {const q = encodeURIComponent(text);const tl = encodeURIComponent(currentTargetLang);const candidateAudioUrls = serverAvailable? [`/tts_audio?tl=${tl}&q=${q}`]: [`https://api.streamelements.com/kappa/v2/speech?voice=${langInfo.bcp47 || 'en-US'}&text=${q}`,`https://dict.youdao.com/dictvoice?audio=${q}&le=${tl}`,`https://translate.google.com/translate_tts?ie=UTF-8&tl=${tl}&client=tw-ob&q=${q}`];let urlIndex = 0;function tryNextAudioCandidate() {if (urlIndex < candidateAudioUrls.length) {const url = candidateAudioUrls[urlIndex++];const audio = new Audio(url);audio.onended = resetSpeakButton;audio.onerror = () => {console.warn(`[SignLens] Audio TTS endpoint failed (${url}), trying next candidate...`);tryNextAudioCandidate();};audio.play().catch(err => {console.warn(`[SignLens] Audio play error on ${url}:`, err);tryNextAudioCandidate();});} else {// All remote audio streams failed (e.g. offline), fallback to browser speech synthesisconsole.warn('[SignLens] All remote audio streams failed, falling back to local speech synthesis');speakViaSpeechSynthesis(text, langInfo, btnSpeak, resetSpeakButton);}}tryNextAudioCandidate();return;}// Default English or SpeechSynthesis pathway
app.js+36-19