Update index.html
Browse files- index.html +9 -3
index.html
CHANGED
|
@@ -34,6 +34,7 @@
|
|
| 34 |
let audioChunks = [];
|
| 35 |
let mediaRecorder;
|
| 36 |
let audioBlob;
|
|
|
|
| 37 |
|
| 38 |
// Cargar voces y seleccionar "Google espa帽ol" si est谩 disponible
|
| 39 |
window.speechSynthesis.onvoiceschanged = () => {
|
|
@@ -57,19 +58,24 @@
|
|
| 57 |
// Inicializamos el MediaRecorder para capturar el audio
|
| 58 |
async function initMediaRecorder() {
|
| 59 |
const audioContext = new AudioContext();
|
| 60 |
-
|
| 61 |
-
const utteranceStream = audioContext.createMediaStreamSource(destination.stream);
|
| 62 |
-
mediaRecorder = new MediaRecorder(destination.stream);
|
| 63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
tts.onstart = () => {
|
| 65 |
mediaRecorder.start();
|
| 66 |
audioChunks = [];
|
| 67 |
};
|
| 68 |
|
|
|
|
| 69 |
mediaRecorder.ondataavailable = (event) => {
|
| 70 |
audioChunks.push(event.data);
|
| 71 |
};
|
| 72 |
|
|
|
|
| 73 |
mediaRecorder.onstop = () => {
|
| 74 |
audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
|
| 75 |
const audioUrl = URL.createObjectURL(audioBlob);
|
|
|
|
| 34 |
let audioChunks = [];
|
| 35 |
let mediaRecorder;
|
| 36 |
let audioBlob;
|
| 37 |
+
let streamDestination;
|
| 38 |
|
| 39 |
// Cargar voces y seleccionar "Google espa帽ol" si est谩 disponible
|
| 40 |
window.speechSynthesis.onvoiceschanged = () => {
|
|
|
|
| 58 |
// Inicializamos el MediaRecorder para capturar el audio
|
| 59 |
async function initMediaRecorder() {
|
| 60 |
const audioContext = new AudioContext();
|
| 61 |
+
streamDestination = audioContext.createMediaStreamDestination();
|
|
|
|
|
|
|
| 62 |
|
| 63 |
+
// Conectamos el SpeechSynthesisUtterance al MediaStreamDestination
|
| 64 |
+
const utteranceSource = audioContext.createMediaStreamSource(streamDestination.stream);
|
| 65 |
+
mediaRecorder = new MediaRecorder(streamDestination.stream);
|
| 66 |
+
|
| 67 |
+
// Empezamos a grabar cuando empieza el habla
|
| 68 |
tts.onstart = () => {
|
| 69 |
mediaRecorder.start();
|
| 70 |
audioChunks = [];
|
| 71 |
};
|
| 72 |
|
| 73 |
+
// Guardamos los datos de audio en chunks
|
| 74 |
mediaRecorder.ondataavailable = (event) => {
|
| 75 |
audioChunks.push(event.data);
|
| 76 |
};
|
| 77 |
|
| 78 |
+
// Al finalizar la grabaci贸n, generamos el archivo .wav
|
| 79 |
mediaRecorder.onstop = () => {
|
| 80 |
audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
|
| 81 |
const audioUrl = URL.createObjectURL(audioBlob);
|