Spaces:
Running

text-kimo / index.html
Karimen's picture
undefined - Initial Deployment
c5eeec0 verified
Raw History Blame Contribute Delete
19.5 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>American English Text-to-Speech Converter</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');
body {
font-family: 'Poppins', sans-serif;
background-color: #f8fafc;
}
.gradient-bg {
background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
}
.wave-animation {
animation: wave 2s ease-in-out infinite;
}
@keyframes wave {
0%, 100% {
transform: translateY(0);
}
50% {
transform: translateY(-10px);
}
}
.speech-controls {
transition: all 0.3s ease;
}
.speech-controls:hover {
transform: scale(1.05);
}
#textInput {
min-height: 150px;
resize: none;
}
/* Custom range slider */
input[type="range"] {
-webkit-appearance: none;
height: 8px;
background: #e2e8f0;
border-radius: 5px;
background-image: linear-gradient(#3b82f6, #3b82f6);
background-size: 0% 100%;
background-repeat: no-repeat;
}
input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
height: 20px;
width: 20px;
border-radius: 50%;
background: #3b82f6;
cursor: pointer;
box-shadow: 0 0 2px 0 #555;
transition: all 0.3s ease;
}
input[type="range"]::-webkit-slider-thumb:hover {
transform: scale(1.2);
background: #2563eb;
}
/* Animation for speaking state */
@keyframes pulse {
0%, 100% {
transform: scale(1);
box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.7);
}
50% {
transform: scale(1.05);
box-shadow: 0 0 0 10px rgba(59, 130, 246, 0);
}
}
.speaking {
animation: pulse 1.5s infinite;
}
</style>
</head>
<body class="min-h-screen flex flex-col">
<header class="gradient-bg text-white py-6 shadow-lg">
<div class="container mx-auto px-4">
<div class="flex items-center justify-between">
<div class="flex items-center space-x-3">
<i class="fas fa-language text-3xl wave-animation"></i>
<h1 class="text-2xl md:text-3xl font-bold">American Speech Converter</h1>
</div>
<div class="hidden md:flex items-center space-x-2">
<span class="text-sm bg-white bg-opacity-20 px-3 py-1 rounded-full">New</span>
<span class="text-sm">v1.0</span>
</div>
</div>
</div>
</header>
<main class="flex-grow container mx-auto px-4 py-8">
<div class="max-w-4xl mx-auto">
<div class="bg-white rounded-xl shadow-lg overflow-hidden">
<!-- Controls Section -->
<div class="bg-gray-50 px-6 py-4 border-b">
<div class="flex flex-wrap items-center justify-between gap-4">
<div class="flex items-center space-x-4">
<button id="speakBtn" class="bg-blue-500 hover:bg-blue-600 text-white px-6 py-2 rounded-lg font-medium flex items-center space-x-2 speech-controls">
<i class="fas fa-play"></i>
<span>Speak</span>
</button>
<button id="stopBtn" class="bg-gray-200 hover:bg-gray-300 text-gray-800 px-6 py-2 rounded-lg font-medium flex items-center space-x-2 speech-controls">
<i class="fas fa-stop"></i>
<span>Stop</span>
</button>
</div>
<div class="flex items-center space-x-4">
<button id="downloadBtn" class="bg-green-500 hover:bg-green-600 text-white px-4 py-2 rounded-lg font-medium flex items-center space-x-2 speech-controls">
<i class="fas fa-download"></i>
<span class="hidden md:inline">Download</span>
</button>
</div>
</div>
<div class="mt-4 grid grid-cols-1 md:grid-cols-2 gap-4">
<div class="space-y-2">
<label for="repeatCount" class="block text-sm font-medium text-gray-700">Repeat Sentences: <span id="repeatValue" class="font-bold">1</span> times</label>
<input type="range" id="repeatCount" min="1" max="5" value="1" class="w-full">
</div>
<div class="space-y-2">
<label for="pauseDuration" class="block text-sm font-medium text-gray-700">Pause Between Sentences: <span id="pauseValue" class="font-bold">1</span> seconds</label>
<input type="range" id="pauseDuration" min="1" max="4" value="1" class="w-full">
</div>
</div>
</div>
<!-- Text Input Section -->
<div class="p-6">
<div class="mb-4">
<label for="textInput" class="block text-sm font-medium text-gray-700 mb-2">Enter your text to convert to American English speech:</label>
<textarea id="textInput" class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition duration-200" placeholder="Type or paste your text here..."></textarea>
</div>
<div class="flex flex-wrap items-center justify-between gap-4">
<div class="flex items-center space-x-2">
<button id="clearBtn" class="text-gray-600 hover:text-gray-800 flex items-center space-x-1">
<i class="fas fa-trash-alt"></i>
<span>Clear</span>
</button>
</div>
<div class="flex items-center space-x-2 text-sm text-gray-500">
<i class="fas fa-info-circle"></i>
<span>Character count: <span id="charCount">0</span></span>
</div>
</div>
</div>
</div>
<!-- Voice Preview Section -->
<div class="mt-8 bg-white rounded-xl shadow-lg overflow-hidden">
<div class="px-6 py-4 border-b bg-gray-50">
<h2 class="text-lg font-medium text-gray-800">Voice Preview</h2>
</div>
<div class="p-6">
<div class="flex items-center justify-between mb-4">
<div class="flex items-center space-x-3">
<div id="voiceIcon" class="bg-blue-100 text-blue-600 p-3 rounded-full">
<i class="fas fa-user-tie text-xl"></i>
</div>
<div>
<h3 class="font-medium">American English</h3>
<p class="text-sm text-gray-500">Standard US accent</p>
</div>
</div>
<button id="testVoiceBtn" class="bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded-lg text-sm flex items-center space-x-2">
<i class="fas fa-volume-up"></i>
<span>Test Voice</span>
</button>
</div>
<div class="bg-blue-50 border border-blue-100 rounded-lg p-4">
<p class="text-blue-800 text-sm">"Hello, welcome to the American English text-to-speech converter. This is how your text will sound."</p>
</div>
</div>
</div>
</div>
</main>
<footer class="bg-gray-100 py-6 border-t">
<div class="container mx-auto px-4 text-center text-gray-600 text-sm">
<p>© 2023 American Speech Converter. All rights reserved.</p>
</div>
</footer>
<script>
document.addEventListener('DOMContentLoaded', function() {
// DOM Elements
const textInput = document.getElementById('textInput');
const speakBtn = document.getElementById('speakBtn');
const stopBtn = document.getElementById('stopBtn');
const downloadBtn = document.getElementById('downloadBtn');
const clearBtn = document.getElementById('clearBtn');
const testVoiceBtn = document.getElementById('testVoiceBtn');
const repeatCount = document.getElementById('repeatCount');
const pauseDuration = document.getElementById('pauseDuration');
const repeatValue = document.getElementById('repeatValue');
const pauseValue = document.getElementById('pauseValue');
const charCount = document.getElementById('charCount');
const voiceIcon = document.getElementById('voiceIcon');
// Speech Synthesis
const synth = window.speechSynthesis;
let utterance = null;
let speechQueue = [];
let isSpeaking = false;
let audioChunks = [];
let mediaRecorder;
let audioContext;
// Update character count
textInput.addEventListener('input', function() {
charCount.textContent = this.value.length;
});
// Update slider values
repeatCount.addEventListener('input', function() {
repeatValue.textContent = this.value;
});
pauseDuration.addEventListener('input', function() {
pauseValue.textContent = this.value;
});
// Clear text
clearBtn.addEventListener('click', function() {
textInput.value = '';
charCount.textContent = '0';
});
// Test voice
testVoiceBtn.addEventListener('click', function() {
if (isSpeaking) {
synth.cancel();
}
const testText = "Hello, welcome to the American English text-to-speech converter. This is how your text will sound.";
speakText(testText, 1, 1, false);
});
// Speak button
speakBtn.addEventListener('click', function() {
if (textInput.value.trim() === '') {
showAlert('Please enter some text to convert to speech.', 'error');
return;
}
if (isSpeaking) {
synth.cancel();
isSpeaking = false;
updateSpeakingState(false);
return;
}
const text = textInput.value;
const repeat = parseInt(repeatCount.value);
const pause = parseInt(pauseDuration.value);
speakText(text, repeat, pause, true);
});
// Stop button
stopBtn.addEventListener('click', function() {
synth.cancel();
isSpeaking = false;
updateSpeakingState(false);
speechQueue = [];
});
// Download button
downloadBtn.addEventListener('click', function() {
if (textInput.value.trim() === '') {
showAlert('Please enter some text before downloading.', 'error');
return;
}
showAlert('Audio download feature requires server-side processing in a real application. This is a frontend demo.', 'info');
// In a real application, you would:
// 1. Send the text to a server
// 2. Generate audio file using a TTS service
// 3. Return the audio file for download
// This is just a simulation for the demo
// const link = document.createElement('a');
// link.href = '#'; // Would be the audio file URL in a real app
// link.download = 'american-speech.mp3';
// link.click();
});
// Function to speak text
function speakText(text, repeat, pause, updateState) {
if (synth.speaking) {
synth.cancel();
}
// Split text into sentences
const sentences = text.split(/(?<=[.!?])\s+/);
speechQueue = [];
// Create utterances for each sentence with repeats
sentences.forEach(sentence => {
if (sentence.trim() === '') return;
for (let i = 0; i < repeat; i++) {
const utterance = new SpeechSynthesisUtterance(sentence);
utterance.lang = 'en-US';
utterance.rate = 1.0;
utterance.pitch = 1.0;
utterance.volume = 1.0;
speechQueue.push(utterance);
// Add pause utterances between repeats (except the last one)
if (i < repeat - 1) {
const pauseUtterance = new SpeechSynthesisUtterance('');
pauseUtterance.lang = 'en-US';
pauseUtterance.rate = 0.1; // Very slow to simulate pause
speechQueue.push(pauseUtterance);
}
}
// Add pause between sentences (except the last one)
if (sentences.indexOf(sentence) < sentences.length - 1) {
const pauseUtterance = new SpeechSynthesisUtterance('');
pauseUtterance.lang = 'en-US';
pauseUtterance.rate = 0.1; // Very slow to simulate pause
speechQueue.push(pauseUtterance);
}
});
// Start speaking
isSpeaking = true;
if (updateState) {
updateSpeakingState(true);
}
speakNextInQueue();
}
// Function to speak next item in queue
function speakNextInQueue() {
if (speechQueue.length === 0) {
isSpeaking = false;
updateSpeakingState(false);
return;
}
const utterance = speechQueue.shift();
// Check if this is a pause utterance
if (utterance.text === '') {
// This is a pause - wait for the specified duration
setTimeout(() => {
speakNextInQueue();
}, parseInt(pauseDuration.value) * 1000);
return;
}
utterance.onend = function() {
speakNextInQueue();
};
synth.speak(utterance);
}
// Update speaking state UI
function updateSpeakingState(speaking) {
if (speaking) {
speakBtn.innerHTML = '<i class="fas fa-pause"></i><span>Pause</span>';
speakBtn.classList.remove('bg-blue-500', 'hover:bg-blue-600');
speakBtn.classList.add('bg-yellow-500', 'hover:bg-yellow-600');
voiceIcon.classList.add('speaking');
} else {
speakBtn.innerHTML = '<i class="fas fa-play"></i><span>Speak</span>';
speakBtn.classList.remove('bg-yellow-500', 'hover:bg-yellow-600');
speakBtn.classList.add('bg-blue-500', 'hover:bg-blue-600');
voiceIcon.classList.remove('speaking');
}
}
// Show alert message
function showAlert(message, type) {
const alert = document.createElement('div');
alert.className = `fixed top-4 right-4 px-6 py-3 rounded-lg shadow-lg text-white font-medium flex items-center space-x-2 z-50 ${
type === 'error' ? 'bg-red-500' :
type === 'success' ? 'bg-green-500' :
'bg-blue-500'
}`;
alert.innerHTML = `
<i class="fas ${type === 'error' ? 'fa-exclamation-circle' : type === 'success' ? 'fa-check-circle' : 'fa-info-circle'}"></i>
<span>${message}</span>
`;
document.body.appendChild(alert);
setTimeout(() => {
alert.style.opacity = '0';
alert.style.transition = 'opacity 0.5s ease';
setTimeout(() => {
document.body.removeChild(alert);
}, 500);
}, 3000);
}
// Initialize
charCount.textContent = textInput.value.length;
});
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Karimen/text-kimo" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>