// Initialize Eric TTS document.addEventListener('DOMContentLoaded', () => { window.ericTTS = new EricTTS(); }); // Save/Load Settings class Settings { saveSettings() { const settings = { rate: document.getElementById('rate').value, pitch: document.getElementById('pitch').value, voice: document.getElementById('voiceSelect').value }; localStorage.setItem('ericTTS_settings', JSON.stringify(settings)); } loadSettings() { const saved = localStorage.getItem('ericTTS_settings'); if (saved) { const settings = JSON.parse(saved); document.getElementById('rate').value = settings.rate; document.getElementById('pitch').value = settings.pitch; document.getElementById('voiceSelect').value = settings.voice; } } }
speak() { const text = this.textInput.value.trim(); if (!text) { this.showNotification('Please enter some text to speak!', 'warning'); return; } // Stop any ongoing speech this.stop(); // Create new utterance this.utterance = new SpeechSynthesisUtterance(text); // Set properties this.utterance.rate = parseFloat(this.rateSlider.value); this.utterance.pitch = parseFloat(this.pitchSlider.value); // Set voice if selected const selectedVoice = this.voiceSelect.value; if (selectedVoice) { const voices = this.synth.getVoices(); const voice = voices.find(v => v.name === selectedVoice); if (voice) this.utterance.voice = voice; } // Event handlers this.utterance.onstart = () => { this.isPlaying = true; this.speakBtn.disabled = true; this.showNotification('🔊 Speaking...', 'info'); }; this.utterance.onend = () => { this.isPlaying = false; this.speakBtn.disabled = false; this.showNotification('✅ Speech completed', 'success'); }; this.utterance.onerror = (event) => { console.error('TTS Error:', event); this.isPlaying = false; this.speakBtn.disabled = false; this.showNotification('Error occurred during speech', 'error'); }; // Speak this.synth.speak(this.utterance); }
.button-group { flex-direction: column; }