Vibe coded Text to Speech Converter

by Ebuka Chibueze

HTML

<div class="container">
        <h1>Vibe coded Text to Speech Converter</h1>
        <p class="subtitle">Enter text and hear it spoken aloud</p>
        
        <div class="input-group">
            <input type="text" id="text-input" placeholder="Type or paste text here...">
        </div>
        
        <div class="buttons">
            <button id="speak-btn">Speak</button>
            <button id="stop-btn">Stop</button>
            <button id="clear-btn">Clear</button>
        </div>
        
        <div class="status" id="status">
            <span>Ready to speak</span>
        </div>
        
        <p class="info">Note: This works best in Chrome, but we've made it compatible with Firefox as well.</p>
    </div>

CSS

* {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        
        body {
            background: linear-gradient(135deg, #1a2a6c, #b21f1f, #fdbb2d);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
        }
        
        .container {
            background-color: rgba(255, 255, 255, 0.9);
            border-radius: 20px;
            box-shadow: 0 15px 30px rgba(0, 0, 0, 0.3);
            width: 90%;
            max-width: 500px;
            padding: 40px;
            text-align: center;
        }
        
        h1 {
            color: #333;
            margin-bottom: 10px;
            font-size: 2.5rem;
        }
        
        .subtitle {
            color: #666;
            margin-bottom: 30px;
            font-size: 1.1rem;
        }
        
        .input-group {
            margin-bottom: 25px;
        }
        
        input {
            width: 100%;
            padding: 15px;
            border: 2px solid #ddd;
            border-radius: 10px;
            font-size: 1.1rem;
            transition: border-color 0.3s;
        }
        
        input:focus {
            border-color: #4a90e2;
            outline: none;
        }
        
        .buttons {
            display: flex;
            justify-content: center;
            gap: 15px;
            margin-bottom: 25px;
        }
        
        button {
            padding: 15px 30px;
            border: none;
            border-radius: 10px;
            font-size: 1rem;
            font-weight: 600;
            cursor: pointer;
            transition: transform 0.2s, box-shadow 0.2s;
        }
        
        button:hover {
            transform: translateY(-3px);
            box-shadow: 0...

JavaScript

document.addEventListener('DOMContentLoaded', function() {
            const textInput = document.getElementById('text-input');
            const speakBtn = document.getElementById('speak-btn');
            const stopBtn = document.getElementById('stop-btn');
            const clearBtn = document.getElementById('clear-btn');
            const status = document.getElementById('status');
            
            // Check if browser supports speech synthesis
            const checkSupport = () => {
                if ('speechSynthesis' in window) {
                    status.textContent = "Web Speech API supported";
                    status.className = "status";
                } else {
                    status.textContent = "Web Speech API not supported in this browser";
                    status.className = "status error";
                    speakBtn.disabled = true;
                    stopBtn.disabled = true;
                }
            }
            
            // Initialize speech synthesis
            let isSpeaking = false;
            let utterance = null;
            
            // Speak function
            function speakText() {
                const text = textInput.value.trim();
                
                if (!text) {
                    status.textContent = "Please enter some text first";
                    status.className = "status error";
                    return;
                }
                
                // Cancel any ongoing speech
                if (isSpeaking) {
                    window.speechSynthesis.cancel();
                    isSpeaking = false;
                    status.textContent = "Speech canceled";
                    status.className = "status stopped";
                }
                
                // Create a new utterance
                utterance = new SpeechSynthesisUtterance(text);
                utterance.lang = 'en-US';
               ...