Spaces:
Runtime error
Runtime error
Update templates/escuchar_trauma1.html
Browse files- templates/escuchar_trauma1.html +8 -155
templates/escuchar_trauma1.html
CHANGED
@@ -21,12 +21,12 @@
|
|
21 |
<!---------------------------------------------------------------------------------------->
|
22 |
|
23 |
<div id="controls">
|
24 |
-
<button id="recordButton">
|
25 |
-
|
26 |
-
<button id="stopButton" disabled>
|
27 |
</div>
|
28 |
-
<div id="formats">
|
29 |
-
<p><strong>
|
30 |
<ol id="recordingsList"></ol>
|
31 |
|
32 |
|
@@ -43,156 +43,9 @@
|
|
43 |
<!-- El texto plano se mostrar谩 aqu铆 -->
|
44 |
<!--</div>-->
|
45 |
<!--<h1>Grabaci贸n de Audio</h1>
|
46 |
-
<
|
47 |
-
<
|
48 |
-
|
49 |
-
|
50 |
-
<audio id="audio-player" controls style="display: none;"></audio>
|
51 |
-
|
52 |
-
<script>
|
53 |
-
let audioChunks = [];
|
54 |
-
let mediaRecorder;
|
55 |
-
let audioContext;
|
56 |
-
|
57 |
-
const startRecordingButton = document.getElementById('start-recording');
|
58 |
-
const stopRecordingButton = document.getElementById('stop-recording');
|
59 |
-
const playAudioButton = document.getElementById('play-audio');
|
60 |
-
const audioPlayer = document.getElementById('audio-player');
|
61 |
-
|
62 |
-
startRecordingButton.addEventListener('click', startRecording);
|
63 |
-
stopRecordingButton.addEventListener('click', stopRecording);
|
64 |
-
stopRecordingButton.addEventListener('click', () => {
|
65 |
-
stopRecording();
|
66 |
-
sendAudioToServer();
|
67 |
-
});
|
68 |
-
playAudioButton.addEventListener('click', playAudio);
|
69 |
-
|
70 |
-
function startRecording() {
|
71 |
-
startRecordingButton.style.display = 'none';
|
72 |
-
stopRecordingButton.style.display = 'block';
|
73 |
-
//playAudioButton.style.display = 'none';
|
74 |
-
|
75 |
-
navigator.mediaDevices.getUserMedia({ audio: true })
|
76 |
-
.then(stream => {
|
77 |
-
audioContext = new AudioContext();
|
78 |
-
mediaRecorder = new MediaRecorder(stream);
|
79 |
-
mediaRecorder.ondataavailable = event => {
|
80 |
-
if (event.data.size > 0) {
|
81 |
-
audioChunks.push(event.data);
|
82 |
-
}
|
83 |
-
};
|
84 |
-
mediaRecorder.onstop = () => {
|
85 |
-
playAudioButton.style.display = 'block';
|
86 |
-
};
|
87 |
-
mediaRecorder.start();
|
88 |
-
})
|
89 |
-
.catch(error => {
|
90 |
-
console.error('Error al acceder al micr贸fono: ' + error);
|
91 |
-
});
|
92 |
-
}
|
93 |
-
|
94 |
-
function stopRecording() {
|
95 |
-
startRecordingButton.style.display = 'block';
|
96 |
-
stopRecordingButton.style.display = 'none';
|
97 |
-
mediaRecorder.stop();
|
98 |
-
}
|
99 |
-
|
100 |
-
function playAudio() {
|
101 |
-
const audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
|
102 |
-
const audioUrl = URL.createObjectURL(audioBlob);
|
103 |
-
audioPlayer.src = audioUrl;
|
104 |
-
audioPlayer.style.display = 'block';
|
105 |
-
audioPlayer.play();
|
106 |
-
}-->
|
107 |
-
<!--// function sendAudioToServer() {
|
108 |
-
// const formData = new FormData();
|
109 |
-
// const audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
|
110 |
-
// formData.append('audio', audioBlob);
|
111 |
-
|
112 |
-
// fetch("/escuchar_trauma", {
|
113 |
-
// method: "POST",
|
114 |
-
// body: formData
|
115 |
-
// })
|
116 |
-
// .then(response => response.json())
|
117 |
-
// .then(data => {
|
118 |
-
// console.log(data.result);
|
119 |
-
// })
|
120 |
-
// .catch(error => {
|
121 |
-
// console.error(error);
|
122 |
-
// });
|
123 |
-
//}
|
124 |
-
|
125 |
-
//function sendAudioToServer() {
|
126 |
-
// // Agrega el archivo de audio al formulario
|
127 |
-
// const audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
|
128 |
-
// const audioFormData = new FormData();
|
129 |
-
// audioFormData.append('audio', audioBlob);
|
130 |
-
|
131 |
-
// // Env铆a el formulario con el archivo al servidor
|
132 |
-
// fetch("/escuchar_trauma", {
|
133 |
-
// method: "POST",
|
134 |
-
// body: audioFormData
|
135 |
-
// })
|
136 |
-
// .then(response => response.json())
|
137 |
-
// .then(data => {
|
138 |
-
// console.log(data.result);
|
139 |
-
// })
|
140 |
-
// .catch(error => {
|
141 |
-
// console.error(error);
|
142 |
-
// });
|
143 |
-
//}-->
|
144 |
-
<!--function sendAudioToServer() {
|
145 |
-
|
146 |
-
var xhr = new XMLHttpRequest();
|
147 |
-
xhr.onload = function (e) {
|
148 |
-
if (this.readyState === 4) {
|
149 |
-
console.log("Server returned: ", e.target.responseText);
|
150 |
-
}
|
151 |
-
};
|
152 |
-
const audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
|
153 |
-
const audioUrl = URL.createObjectURL(audioBlob);
|
154 |
-
// Supongamos que "data" es una cadena de bytes en formato WAV
|
155 |
-
var formData = new FormData();
|
156 |
-
// Supongamos que "audioBlob" es un objeto Blob que contiene el audio WAV
|
157 |
-
formData.append("audio_data", audioBlob, "archivo.wav");
|
158 |
-
xhr.open("POST", "/escuchar_trauma", true);
|
159 |
-
xhr.onreadystatechange = function () {
|
160 |
-
if (xhr.readyState === 4 && xhr.status === 200) {
|
161 |
-
// Manejar la respuesta del servidor
|
162 |
-
console.log("Respuesta del servidor:", xhr.responseText);
|
163 |
-
////////////////////////////////////////////////////////
|
164 |
-
// Muestra el resultado del reconocimiento en el cuadro de texto
|
165 |
-
//document.getElementById("responseTextBox").value = xhr.responseText;
|
166 |
-
// Buscar el contenido dentro de las etiquetas <p></p>
|
167 |
-
var parser = new DOMParser();
|
168 |
-
var responseHTML = parser.parseFromString(xhr.responseText, 'text/html');
|
169 |
-
var paragraphContent = responseHTML.querySelector('p').textContent;
|
170 |
-
|
171 |
-
// Muestra el resultado del reconocimiento en el cuadro de texto
|
172 |
-
//document.getElementById("responseTextBox").value = paragraphContent;
|
173 |
-
// Muestra el resultado del reconocimiento como texto plano
|
174 |
-
var textElement = document.getElementById("textElement"); // Reemplaza "textElement" con el ID adecuado
|
175 |
-
textElement.textContent = paragraphContent;-->
|
176 |
-
<!--//////////////////////////////////////////////////////////
|
177 |
-
}
|
178 |
-
};
|
179 |
-
xhr.send(formData);
|
180 |
-
}
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
</script>-->
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
<br>
|
193 |
-
<br>
|
194 |
-
|
195 |
-
<!--<b style="font-size: 1.4rem;font-family: Arial, Helvetica, sans-serif;">{{prediction_text}}</b>-->
|
196 |
|
197 |
<br>
|
198 |
<br>
|
|
|
21 |
<!---------------------------------------------------------------------------------------->
|
22 |
|
23 |
<div id="controls">
|
24 |
+
<button id="recordButton">Grabar Voz</button>
|
25 |
+
<!--<button id="pauseButton" disabled>Pause</button>-->
|
26 |
+
<button id="stopButton" disabled>Parar grabacion y buscar</button>
|
27 |
</div>
|
28 |
+
<div id="formats">Dele al bot贸n "Grabar Voz". Cuando acabe, dele al bot贸n "Parar grabaci贸n..." y obtendr谩 el resultado de la b煤squeda</div>
|
29 |
+
<p><strong>Grabaci贸n:</strong></p>
|
30 |
<ol id="recordingsList"></ol>
|
31 |
|
32 |
|
|
|
43 |
<!-- El texto plano se mostrar谩 aqu铆 -->
|
44 |
<!--</div>-->
|
45 |
<!--<h1>Grabaci贸n de Audio</h1>
|
46 |
+
<br>
|
47 |
+
<br>
|
48 |
+
<!--<b style="font-size: 1.4rem;font-family: Arial, Helvetica, sans-serif;">{{prediction_text}}</b>-->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
<br>
|
51 |
<br>
|