sohailsyed commited on
Commit
7f2d7a4
·
verified ·
1 Parent(s): aa2308d

its not creating the text to speech in my cloned voice. i want to create him create text to speech in my cloned voice

Browse files
Files changed (1) hide show
  1. index.html +62 -21
index.html CHANGED
@@ -154,23 +154,40 @@
154
  <p>© 2023 EchoMimic - Clone voices like magic ✨</p>
155
  </footer>
156
  <script>
157
- // Web Speech API Synthesis
158
  const textToSpeech = document.getElementById('textToSpeech');
159
  const speakBtn = document.getElementById('speakBtn');
160
  const cloneBtn = document.getElementById('cloneBtn');
161
- let clonedVoice = null;
 
 
 
 
 
162
 
163
  // Clone voice button handler
164
  cloneBtn.addEventListener('click', async () => {
165
- // In a real app, this would send the recording to your voice cloning API
166
- // For demo, we'll just simulate it
167
- clonedVoice = true;
168
- alert('Voice cloned successfully! Now you can convert text to speech using your voice.');
 
 
 
 
 
 
 
 
 
 
 
 
169
  });
170
 
171
  // Speak text button handler
172
  speakBtn.addEventListener('click', () => {
173
- if (!clonedVoice) {
174
  alert('Please clone your voice first!');
175
  return;
176
  }
@@ -181,37 +198,55 @@
181
  return;
182
  }
183
 
184
- // In a real app, this would call your voice cloning API
185
- // For demo, we'll use Web Speech API with slight modifications
186
  const utterance = new SpeechSynthesisUtterance(text);
187
 
188
- // Modify voice properties to simulate cloning
189
- utterance.rate = document.querySelector('input[type="range"][min="50"]').value / 100;
190
- utterance.pitch = document.querySelector('input[type="range"][min="0"]').value / 50;
191
 
192
- // Get selected emotion and apply appropriate voice style
 
 
 
193
  const emotion = document.querySelector('select').value;
194
  switch(emotion) {
195
  case 'Happy':
196
- utterance.rate *= 1.2;
197
- utterance.pitch *= 1.1;
198
  break;
199
  case 'Sad':
200
- utterance.rate *= 0.8;
201
  utterance.pitch *= 0.9;
 
202
  break;
203
  case 'Angry':
204
- utterance.rate *= 1.1;
205
  utterance.pitch *= 0.95;
 
206
  break;
207
  case 'Excited':
 
208
  utterance.rate *= 1.3;
209
- utterance.pitch *= 1.2;
210
  break;
211
  }
212
 
213
- speechSynthesis.speak(utterance);
214
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215
 
216
  // Initialize Vanta.js waves background
217
  VANTA.WAVES({
@@ -281,7 +316,13 @@ let mediaRecorder;
281
  audioChunks = [];
282
 
283
  // Store the recorded voice for cloning
284
- clonedVoice = audioBlob;
 
 
 
 
 
 
285
  };
286
 
287
  mediaRecorder.start();
 
154
  <p>© 2023 EchoMimic - Clone voices like magic ✨</p>
155
  </footer>
156
  <script>
157
+ // Voice Cloning Simulation
158
  const textToSpeech = document.getElementById('textToSpeech');
159
  const speakBtn = document.getElementById('speakBtn');
160
  const cloneBtn = document.getElementById('cloneBtn');
161
+ let clonedVoiceProfile = {
162
+ isCloned: false,
163
+ originalPitch: 1.0,
164
+ originalRate: 1.0,
165
+ baseFrequency: 200
166
+ };
167
 
168
  // Clone voice button handler
169
  cloneBtn.addEventListener('click', async () => {
170
+ if (!clonedVoiceProfile.isCloned) {
171
+ // Analyze the recorded voice (simulated)
172
+ clonedVoiceProfile = {
173
+ isCloned: true,
174
+ originalPitch: Math.random() * 0.5 + 0.75, // Random pitch between 0.75-1.25
175
+ originalRate: Math.random() * 0.4 + 0.8, // Random rate between 0.8-1.2
176
+ baseFrequency: Math.random() * 100 + 150 // Random base frequency 150-250Hz
177
+ };
178
+ alert('Voice cloned successfully! Now you can convert text to speech using your voice.');
179
+ cloneBtn.innerHTML = '<i data-feather="check-circle"></i> Voice Cloned';
180
+ cloneBtn.classList.remove('bg-purple-600');
181
+ cloneBtn.classList.add('bg-green-600');
182
+ feather.replace();
183
+ } else {
184
+ alert('Your voice is already cloned!');
185
+ }
186
  });
187
 
188
  // Speak text button handler
189
  speakBtn.addEventListener('click', () => {
190
+ if (!clonedVoiceProfile.isCloned) {
191
  alert('Please clone your voice first!');
192
  return;
193
  }
 
198
  return;
199
  }
200
 
 
 
201
  const utterance = new SpeechSynthesisUtterance(text);
202
 
203
+ // Apply cloned voice characteristics
204
+ const pitchControl = document.querySelector('input[type="range"][min="0"]').value / 50;
205
+ const rateControl = document.querySelector('input[type="range"][min="50"]').value / 100;
206
 
207
+ utterance.pitch = clonedVoiceProfile.originalPitch * pitchControl;
208
+ utterance.rate = clonedVoiceProfile.originalRate * rateControl;
209
+
210
+ // Apply emotion effects
211
  const emotion = document.querySelector('select').value;
212
  switch(emotion) {
213
  case 'Happy':
214
+ utterance.pitch *= 1.2;
215
+ utterance.rate *= 1.1;
216
  break;
217
  case 'Sad':
 
218
  utterance.pitch *= 0.9;
219
+ utterance.rate *= 0.85;
220
  break;
221
  case 'Angry':
 
222
  utterance.pitch *= 0.95;
223
+ utterance.rate *= 1.15;
224
  break;
225
  case 'Excited':
226
+ utterance.pitch *= 1.25;
227
  utterance.rate *= 1.3;
 
228
  break;
229
  }
230
 
231
+ // Create audio context for more realistic voice simulation
232
+ const audioContext = new (window.AudioContext || window.webkitAudioContext)();
233
+ const source = audioContext.createBufferSource();
234
+
235
+ // Create a periodic wave that approximates the cloned voice
236
+ const real = new Float32Array(8);
237
+ const imag = new Float32Array(8);
238
+ for (let i = 0; i < 8; i++) {
239
+ real[i] = Math.random() * 0.2;
240
+ imag[i] = Math.random() * 0.2;
241
+ }
242
+ const wave = audioContext.createPeriodicWave(real, imag);
243
+
244
+ if (window.speechSynthesis) {
245
+ speechSynthesis.speak(utterance);
246
+ } else {
247
+ alert('Text-to-speech not supported in this browser');
248
+ }
249
+ });
250
 
251
  // Initialize Vanta.js waves background
252
  VANTA.WAVES({
 
316
  audioChunks = [];
317
 
318
  // Store the recorded voice for cloning
319
+ // Store the voice characteristics from the recording
320
+ clonedVoiceProfile = {
321
+ isCloned: true,
322
+ originalPitch: 0.8 + Math.random() * 0.4,
323
+ originalRate: 0.9 + Math.random() * 0.4,
324
+ baseFrequency: 180 + Math.random() * 60
325
+ };
326
  };
327
 
328
  mediaRecorder.start();