Spaces:
Running
Running
Update index.html
Browse files- index.html +154 -19
index.html
CHANGED
@@ -1,19 +1,154 @@
|
|
1 |
-
<!
|
2 |
-
<html>
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Vocal Part Generator</title>
|
7 |
+
<style>
|
8 |
+
body {
|
9 |
+
font-family: Arial, sans-serif;
|
10 |
+
display: flex;
|
11 |
+
justify-content: center;
|
12 |
+
align-items: center;
|
13 |
+
height: 100vh;
|
14 |
+
margin: 0;
|
15 |
+
background-color: #f0f0f0;
|
16 |
+
}
|
17 |
+
.container {
|
18 |
+
background-color: white;
|
19 |
+
padding: 20px;
|
20 |
+
border-radius: 10px;
|
21 |
+
box-shadow: 0 0 10px rgba(0,0,0,0.1);
|
22 |
+
max-width: 600px;
|
23 |
+
width: 100%;
|
24 |
+
}
|
25 |
+
textarea, select, button {
|
26 |
+
width: 100%;
|
27 |
+
margin-bottom: 10px;
|
28 |
+
padding: 5px;
|
29 |
+
}
|
30 |
+
textarea {
|
31 |
+
height: 100px;
|
32 |
+
}
|
33 |
+
button {
|
34 |
+
background-color: #4CAF50;
|
35 |
+
color: white;
|
36 |
+
border: none;
|
37 |
+
padding: 10px;
|
38 |
+
cursor: pointer;
|
39 |
+
}
|
40 |
+
</style>
|
41 |
+
</head>
|
42 |
+
<body>
|
43 |
+
<div class="container">
|
44 |
+
<h1>Vocal Part Generator</h1>
|
45 |
+
<textarea id="verse-lyrics" placeholder="Enter verse lyrics..."></textarea>
|
46 |
+
<textarea id="chorus-lyrics" placeholder="Enter chorus lyrics..."></textarea>
|
47 |
+
<select id="voice-select"></select>
|
48 |
+
<button id="generate-button">Generate Vocal Part</button>
|
49 |
+
<button id="play-button" disabled>Play</button>
|
50 |
+
<audio id="audio-output" controls style="width: 100%; margin-top: 10px;"></audio>
|
51 |
+
</div>
|
52 |
+
|
53 |
+
<script>
|
54 |
+
const verseLyrics = document.getElementById('verse-lyrics');
|
55 |
+
const chorusLyrics = document.getElementById('chorus-lyrics');
|
56 |
+
const voiceSelect = document.getElementById('voice-select');
|
57 |
+
const generateButton = document.getElementById('generate-button');
|
58 |
+
const playButton = document.getElementById('play-button');
|
59 |
+
const audioOutput = document.getElementById('audio-output');
|
60 |
+
|
61 |
+
let voices = [];
|
62 |
+
let audioContext;
|
63 |
+
let melody = [];
|
64 |
+
|
65 |
+
function loadVoices() {
|
66 |
+
voices = speechSynthesis.getVoices();
|
67 |
+
voiceSelect.innerHTML = '';
|
68 |
+
voices.forEach((voice, index) => {
|
69 |
+
const option = document.createElement('option');
|
70 |
+
option.value = index;
|
71 |
+
option.textContent = `${voice.name} (${voice.lang})`;
|
72 |
+
voiceSelect.appendChild(option);
|
73 |
+
});
|
74 |
+
}
|
75 |
+
|
76 |
+
function generateMelody() {
|
77 |
+
const notes = [261.63, 293.66, 329.63, 349.23, 392.00, 440.00, 493.88]; // C4 to B4
|
78 |
+
melody = [];
|
79 |
+
for (let i = 0; i < 16; i++) {
|
80 |
+
melody.push(notes[Math.floor(Math.random() * notes.length)]);
|
81 |
+
}
|
82 |
+
}
|
83 |
+
|
84 |
+
async function generateVocalPart() {
|
85 |
+
const verseText = verseLyrics.value;
|
86 |
+
const chorusText = chorusLyrics.value;
|
87 |
+
const voiceIndex = voiceSelect.value;
|
88 |
+
|
89 |
+
if (!verseText || !chorusText) {
|
90 |
+
alert('Please enter both verse and chorus lyrics.');
|
91 |
+
return;
|
92 |
+
}
|
93 |
+
|
94 |
+
generateMelody();
|
95 |
+
audioContext = new (window.AudioContext || window.webkitAudioContext)();
|
96 |
+
|
97 |
+
const verseUtterance = new SpeechSynthesisUtterance(verseText);
|
98 |
+
verseUtterance.voice = voices[voiceIndex];
|
99 |
+
|
100 |
+
const chorusUtterance = new SpeechSynthesisUtterance(chorusText);
|
101 |
+
chorusUtterance.voice = voices[voiceIndex];
|
102 |
+
|
103 |
+
// Генерируем аудио для куплета и припева
|
104 |
+
const verseAudio = await synthesizeAudio(verseUtterance);
|
105 |
+
const chorusAudio = await synthesizeAudio(chorusUtterance);
|
106 |
+
|
107 |
+
// Комбинируем куплет и припев
|
108 |
+
const fullAudio = combineAudio(verseAudio, chorusAudio);
|
109 |
+
|
110 |
+
// Создаем URL для аудио и устанавливаем его как источник для аудио-элемента
|
111 |
+
const audioUrl = URL.createObjectURL(fullAudio);
|
112 |
+
audioOutput.src = audioUrl;
|
113 |
+
|
114 |
+
playButton.disabled = false;
|
115 |
+
}
|
116 |
+
|
117 |
+
async function synthesizeAudio(utterance) {
|
118 |
+
return new Promise((resolve) => {
|
119 |
+
const audioChunks = [];
|
120 |
+
utterance.onboundary = (event) => {
|
121 |
+
const oscillator = audioContext.createOscillator();
|
122 |
+
oscillator.frequency.setValueAtTime(melody[event.charIndex % melody.length], audioContext.currentTime);
|
123 |
+
oscillator.connect(audioContext.destination);
|
124 |
+
oscillator.start();
|
125 |
+
oscillator.stop(audioContext.currentTime + 0.1);
|
126 |
+
};
|
127 |
+
utterance.onend = () => {
|
128 |
+
const audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
|
129 |
+
resolve(audioBlob);
|
130 |
+
};
|
131 |
+
speechSynthesis.speak(utterance);
|
132 |
+
});
|
133 |
+
}
|
134 |
+
|
135 |
+
function combineAudio(verseAudio, chorusAudio) {
|
136 |
+
return new Blob([verseAudio, chorusAudio], { type: 'audio/wav' });
|
137 |
+
}
|
138 |
+
|
139 |
+
function playVocalPart() {
|
140 |
+
audioOutput.play();
|
141 |
+
}
|
142 |
+
|
143 |
+
// Загружаем голоса при их готовности
|
144 |
+
speechSynthesis.onvoiceschanged = loadVoices;
|
145 |
+
|
146 |
+
// Загружаем голоса немедленно, на случай если они уже доступны
|
147 |
+
loadVoices();
|
148 |
+
|
149 |
+
// Обработчики событий
|
150 |
+
generateButton.addEventListener('click', generateVocalPart);
|
151 |
+
playButton.addEventListener('click', playVocalPart);
|
152 |
+
</script>
|
153 |
+
</body>
|
154 |
+
</html>
|