v1.0.4 - init version
This commit is contained in:
452
static/index.html
Normal file
452
static/index.html
Normal file
@@ -0,0 +1,452 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Go Speech - TTS</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.container {
|
||||
background: white;
|
||||
border-radius: 16px;
|
||||
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
||||
padding: 40px;
|
||||
max-width: 600px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #333;
|
||||
margin-bottom: 30px;
|
||||
text-align: center;
|
||||
font-weight: 600;
|
||||
font-size: 28px;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
label {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
color: #555;
|
||||
font-weight: 500;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
select {
|
||||
width: 100%;
|
||||
padding: 12px 16px;
|
||||
border: 2px solid #e0e0e0;
|
||||
border-radius: 8px;
|
||||
font-size: 16px;
|
||||
background: white;
|
||||
color: #333;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.3s;
|
||||
}
|
||||
|
||||
select:focus {
|
||||
outline: none;
|
||||
border-color: #667eea;
|
||||
}
|
||||
|
||||
textarea {
|
||||
width: 100%;
|
||||
padding: 12px 16px;
|
||||
border: 2px solid #e0e0e0;
|
||||
border-radius: 8px;
|
||||
font-size: 16px;
|
||||
font-family: inherit;
|
||||
resize: vertical;
|
||||
min-height: 120px;
|
||||
color: #333;
|
||||
transition: border-color 0.3s;
|
||||
}
|
||||
|
||||
textarea:focus {
|
||||
outline: none;
|
||||
border-color: #667eea;
|
||||
}
|
||||
|
||||
.buttons {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
margin-top: 24px;
|
||||
}
|
||||
|
||||
button {
|
||||
flex: 1;
|
||||
padding: 14px 24px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 16px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-primary:hover:not(:disabled) {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 8px 20px rgba(102, 126, 234, 0.4);
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background: #f5f5f5;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.btn-secondary:hover:not(:disabled) {
|
||||
background: #e8e8e8;
|
||||
}
|
||||
|
||||
button:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.audio-player {
|
||||
margin-top: 24px;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.audio-player.show {
|
||||
display: block;
|
||||
}
|
||||
|
||||
audio {
|
||||
width: 100%;
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
.status {
|
||||
margin-top: 16px;
|
||||
padding: 12px;
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
text-align: center;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.status.show {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.status.success {
|
||||
background: #d4edda;
|
||||
color: #155724;
|
||||
border: 1px solid #c3e6cb;
|
||||
}
|
||||
|
||||
.status.error {
|
||||
background: #f8d7da;
|
||||
color: #721c24;
|
||||
border: 1px solid #f5c6cb;
|
||||
}
|
||||
|
||||
.status.loading {
|
||||
background: #d1ecf1;
|
||||
color: #0c5460;
|
||||
border: 1px solid #bee5eb;
|
||||
}
|
||||
|
||||
.loader-overlay {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(255, 255, 255, 0.95);
|
||||
display: none;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 16px;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.loader-overlay.show {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.loader {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.spinner {
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
border: 4px solid #f3f3f3;
|
||||
border-top: 4px solid #667eea;
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.loader-text {
|
||||
color: #667eea;
|
||||
font-weight: 500;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.container {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.form-disabled {
|
||||
pointer-events: none;
|
||||
opacity: 0.6;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="loader-overlay" id="loaderOverlay">
|
||||
<div class="loader">
|
||||
<div class="spinner"></div>
|
||||
<div class="loader-text" id="loaderText">Генерация аудио...</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h1>🎤 Go Speech TTS</h1>
|
||||
|
||||
<form id="ttsForm">
|
||||
<div class="form-group">
|
||||
<label for="voice">Выберите голос:</label>
|
||||
<select id="voice" name="voice">
|
||||
<option value="ruslan">Ruslan (мужской)</option>
|
||||
<option value="irina">Irina (женский)</option>
|
||||
<option value="denis">Denis (мужской)</option>
|
||||
<option value="dmitri">Dmitri (мужской)</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="text">Введите текст для озвучки:</label>
|
||||
<textarea
|
||||
id="text"
|
||||
name="text"
|
||||
placeholder="Введите текст на русском языке..."
|
||||
required
|
||||
></textarea>
|
||||
</div>
|
||||
|
||||
<div class="buttons">
|
||||
<button type="submit" class="btn-primary" id="speakBtn">
|
||||
🔊 Озвучить
|
||||
</button>
|
||||
<button type="button" class="btn-secondary" id="downloadBtn" disabled>
|
||||
💾 Скачать
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="status" id="status"></div>
|
||||
|
||||
<div class="audio-player" id="audioPlayer">
|
||||
<audio id="audio" controls></audio>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const form = document.getElementById('ttsForm');
|
||||
const textInput = document.getElementById('text');
|
||||
const voiceSelect = document.getElementById('voice');
|
||||
const speakBtn = document.getElementById('speakBtn');
|
||||
const downloadBtn = document.getElementById('downloadBtn');
|
||||
const statusDiv = document.getElementById('status');
|
||||
const audioPlayer = document.getElementById('audioPlayer');
|
||||
const audio = document.getElementById('audio');
|
||||
const loaderOverlay = document.getElementById('loaderOverlay');
|
||||
const loaderText = document.getElementById('loaderText');
|
||||
const container = document.querySelector('.container');
|
||||
|
||||
let currentAudioUrl = null;
|
||||
let currentBlob = null;
|
||||
let isPlaying = false;
|
||||
|
||||
function showStatus(message, type) {
|
||||
statusDiv.textContent = message;
|
||||
statusDiv.className = `status show ${type}`;
|
||||
}
|
||||
|
||||
function hideStatus() {
|
||||
statusDiv.className = 'status';
|
||||
}
|
||||
|
||||
function setLoading(loading, message = 'Генерация аудио...') {
|
||||
speakBtn.disabled = loading;
|
||||
downloadBtn.disabled = loading || isPlaying;
|
||||
|
||||
if (loading) {
|
||||
speakBtn.textContent = '⏳ Обработка...';
|
||||
loaderText.textContent = message;
|
||||
loaderOverlay.classList.add('show');
|
||||
container.classList.add('form-disabled');
|
||||
} else {
|
||||
speakBtn.textContent = '🔊 Озвучить';
|
||||
loaderOverlay.classList.remove('show');
|
||||
container.classList.remove('form-disabled');
|
||||
updateButtonsState();
|
||||
}
|
||||
}
|
||||
|
||||
function updateButtonsState() {
|
||||
// Блокируем кнопки во время воспроизведения
|
||||
speakBtn.disabled = isPlaying;
|
||||
downloadBtn.disabled = isPlaying || !currentBlob;
|
||||
}
|
||||
|
||||
async function generateSpeech(text, voice) {
|
||||
try {
|
||||
setLoading(true);
|
||||
hideStatus();
|
||||
showStatus('Генерация аудио...', 'loading');
|
||||
|
||||
const response = await fetch('/go-speech/api/v1/tts', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ text: text, voice: voice })
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
throw new Error(errorText || 'Ошибка генерации аудио');
|
||||
}
|
||||
|
||||
const blob = await response.blob();
|
||||
currentBlob = blob;
|
||||
currentAudioUrl = URL.createObjectURL(blob);
|
||||
|
||||
audio.src = currentAudioUrl;
|
||||
audioPlayer.classList.add('show');
|
||||
|
||||
showStatus('Аудио готово!', 'success');
|
||||
|
||||
// Устанавливаем флаг воспроизведения перед автоплеем
|
||||
isPlaying = true;
|
||||
updateButtonsState();
|
||||
|
||||
// Автоматическое воспроизведение
|
||||
audio.play().catch(err => {
|
||||
console.log('Автовоспроизведение заблокировано:', err);
|
||||
isPlaying = false;
|
||||
updateButtonsState();
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('Ошибка:', error);
|
||||
showStatus('Ошибка: ' + error.message, 'error');
|
||||
audioPlayer.classList.remove('show');
|
||||
currentBlob = null;
|
||||
isPlaying = false;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
function downloadAudio() {
|
||||
if (!currentBlob) {
|
||||
showStatus('Нет аудио для скачивания', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
const url = currentAudioUrl;
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = `speech-${voiceSelect.value}-${Date.now()}.ogg`;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
|
||||
showStatus('Файл скачан', 'success');
|
||||
setTimeout(hideStatus, 2000);
|
||||
}
|
||||
|
||||
form.addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
const text = textInput.value.trim();
|
||||
|
||||
if (!text) {
|
||||
showStatus('Введите текст для озвучки', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
if (text.length > 5000) {
|
||||
showStatus('Текст слишком длинный (максимум 5000 символов)', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
const voice = voiceSelect.value;
|
||||
await generateSpeech(text, voice);
|
||||
});
|
||||
|
||||
downloadBtn.addEventListener('click', downloadAudio);
|
||||
|
||||
// Отслеживание событий воспроизведения аудио
|
||||
audio.addEventListener('play', () => {
|
||||
isPlaying = true;
|
||||
updateButtonsState();
|
||||
showStatus('Воспроизведение...', 'loading');
|
||||
});
|
||||
|
||||
audio.addEventListener('pause', () => {
|
||||
isPlaying = false;
|
||||
updateButtonsState();
|
||||
hideStatus();
|
||||
});
|
||||
|
||||
audio.addEventListener('ended', () => {
|
||||
isPlaying = false;
|
||||
updateButtonsState();
|
||||
showStatus('Воспроизведение завершено', 'success');
|
||||
setTimeout(hideStatus, 2000);
|
||||
});
|
||||
|
||||
audio.addEventListener('error', () => {
|
||||
isPlaying = false;
|
||||
updateButtonsState();
|
||||
showStatus('Ошибка воспроизведения', 'error');
|
||||
});
|
||||
|
||||
// Очистка URL при разгрузке страницы
|
||||
window.addEventListener('beforeunload', () => {
|
||||
if (currentAudioUrl) {
|
||||
URL.revokeObjectURL(currentAudioUrl);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user