diff --git a/src/translation.js b/src/translation.js index d2b4f65..e04ddc2 100644 --- a/src/translation.js +++ b/src/translation.js @@ -317,10 +317,12 @@ ${preservedText}`; // Restore preserved content const restored = restoreSpecialContent(translatedText, preservations); console.log("Restored text length:", restored.length); - console.log( - "Restored text:", - restored.substring(0, 300) + (restored.length > 300 ? "..." : ""), - ); + // Only log full text in debug mode, otherwise just show length + if (restored.length < 500) { + console.log("Restored text:", restored); + } else { + console.log("Restored text preview:", restored.substring(0, 100) + "..."); + } // Final validation if (!restored || restored.length === 0) { diff --git a/src/tts-modal.js b/src/tts-modal.js index 270ed7a..1b00d4e 100644 --- a/src/tts-modal.js +++ b/src/tts-modal.js @@ -469,16 +469,53 @@ export function openTTSModal() { console.error('Audio playback error:', e); playPauseBtn.textContent = "❌ Error"; playPauseBtn.disabled = true; + + // Show user-friendly error message + const errorMsg = document.createElement('div'); + errorMsg.style.cssText = ` + color: #d32f2f; + font-size: 12px; + margin-top: 8px; + padding: 8px; + background: #ffebee; + border-radius: 4px; + `; + errorMsg.textContent = 'Audio failed to load. Please try again or check your connection.'; + controlsContainer.appendChild(errorMsg); }); - // Auto-play and set initial state + audio.addEventListener('abort', (e) => { + console.warn('Audio loading was aborted:', e); + if (isPlaying) { + playPauseBtn.textContent = "▶️ Retry"; + isPlaying = false; + } + }); + + audio.addEventListener('stalled', (e) => { + console.warn('Audio loading stalled:', e); + playPauseBtn.textContent = "⏳ Loading..."; + }); + + // Auto-play and set initial state with improved error handling audio.play().then(() => { isPlaying = true; playPauseBtn.textContent = "⏸️ Pause"; }).catch((e) => { - console.warn('Auto-play failed, user interaction required:', e); + console.warn('Auto-play failed, user interaction required:', e.name, e.message); isPlaying = false; playPauseBtn.textContent = "▶️ Play"; + + // Handle specific error types + if (e.name === 'NotAllowedError') { + console.log('Auto-play blocked by browser - user interaction required'); + } else if (e.name === 'AbortError') { + console.log('Audio loading was aborted'); + } else if (e.name === 'NotSupportedError') { + console.error('Audio format not supported'); + playPauseBtn.textContent = "❌ Unsupported"; + playPauseBtn.disabled = true; + } }); } } catch (error) { diff --git a/src/tts.js b/src/tts.js index 6097880..63ab0b5 100644 --- a/src/tts.js +++ b/src/tts.js @@ -106,6 +106,18 @@ Ready? Breath and then return a stream of tokens to be used in a TTS system. } export async function extractSpokenTokens(content) { + // Basic content filtering + const filteredContent = content + .replace(/hawk\s*tau/gi, '[filtered]') + .replace(/spit\s*on\s*that/gi, '[filtered]') + .trim(); + + // Skip processing if content is inappropriate or too short + if (filteredContent.length < 10 || filteredContent.includes('[filtered]')) { + console.warn('Content filtered or too short for TTS processing'); + return content; // Return original but won't be processed + } + const payload = { model: MODEL, messages: [ @@ -115,17 +127,19 @@ export async function extractSpokenTokens(content) { }, { role: "user", - content: content, + content: filteredContent, }, ], temperature: 0, max_tokens: 76000, }; - console.log( - "Sending payload to Hermes for spoken tokens:", - JSON.stringify(payload, null, 2), - ); + // Reduce console spam - only log content preview for long text + const contentPreview = filteredContent.length > 100 + ? filteredContent.substring(0, 100) + "..." + : filteredContent; + + console.log("Processing TTS for content:", contentPreview); try { const response = await fetch(