HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Text to Voice</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<h1>Text to Voice Converter</h1>
<textarea id="text-input" placeholder="Enter text here..."></textarea>
<button id="speak-button">Speak</button>
</div>
<script src="script.js"></script>
</body>
</html>
CSS
/* styles.css */
body {
background: linear-gradient(135deg, #f8f9fa, #e9ecef);
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
font-family: 'Arial', sans-serif;
}
.container {
background: #ffffff;
padding: 20px 30px;
border-radius: 10px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
text-align: center;
width: 400px;
}
h1 {
color: #333333;
margin-bottom: 20px;
}
textarea {
width: 100%;
height: 150px;
border: 1px solid #ced4da;
border-radius: 5px;
padding: 10px;
font-size: 16px;
resize: none;
box-sizing: border-box;
margin-bottom: 20px;
}
button {
background: #007bff;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
transition: background 0.3s ease;
}
button:hover {
background: #0056b3;
}
Javascript
// script.js
document.getElementById('speak-button').addEventListener('click', () => {
const textInput = document.getElementById('text-input').value;
if (textInput.trim() !== '') {
const speech = new SpeechSynthesisUtterance(textInput);
speech.lang = 'en-US';
window.speechSynthesis.speak(speech);
} else {
alert('Please enter some text to speak');
}
});
0 Comments