fix: reduce console spam and improve audio error handling
- Limit translation.js console output to 100 chars for long text (was showing 22KB) - Add content filtering to TTS to prevent inappropriate content processing - Enhance audio error handling with abort, stalled, and specific error types - Add user-friendly error messages for audio playback failures
This commit is contained in:
parent
ade7f4a35e
commit
f42ea86c7b
3 changed files with 64 additions and 11 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
24
src/tts.js
24
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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue