Spaces:
Sleeping
Sleeping
Commit ·
9097688
1
Parent(s): 383cf76
Upload 3 files
Browse files- static/index.html +47 -44
- static/js/app.js +89 -46
- templates/index.html +72 -0
static/index.html
CHANGED
|
@@ -10,54 +10,57 @@
|
|
| 10 |
<button id="startRecording">Start recording</button>
|
| 11 |
<button id="stopRecording" disabled>Stop recording</button>
|
| 12 |
</p>
|
| 13 |
-
</body>
|
| 14 |
-
<script>
|
| 15 |
-
navigator
|
| 16 |
-
.mediaDevices
|
| 17 |
-
.getUserMedia({ audio: true })
|
| 18 |
-
.then(stream => { handlerFunction(stream) });
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
}
|
| 28 |
}
|
| 29 |
-
}
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
|
|
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
</script>
|
|
|
|
| 63 |
</html>
|
|
|
|
| 10 |
<button id="startRecording">Start recording</button>
|
| 11 |
<button id="stopRecording" disabled>Stop recording</button>
|
| 12 |
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
<script>
|
| 15 |
+
navigator
|
| 16 |
+
.mediaDevices
|
| 17 |
+
.getUserMedia({ audio: true })
|
| 18 |
+
.then(stream => { handlerFunction(stream) });
|
| 19 |
+
|
| 20 |
+
function handlerFunction(stream) {
|
| 21 |
+
console.log("html1")
|
| 22 |
+
rec = new MediaRecorder(stream);
|
| 23 |
+
rec.ondataavailable = e => {
|
| 24 |
+
audioChunks.push(e.data);
|
| 25 |
+
if (rec.state == "inactive") {
|
| 26 |
+
let blob = new Blob(audioChunks, { type: 'audio/mpeg-3' });
|
| 27 |
+
sendData(blob);
|
| 28 |
+
}
|
| 29 |
}
|
| 30 |
}
|
|
|
|
| 31 |
|
| 32 |
+
function sendData(data) {
|
| 33 |
+
console.log("html2")
|
| 34 |
+
var form = new FormData();
|
| 35 |
+
form.append('file', data, 'data.mp3');
|
| 36 |
+
form.append('title', 'data.mp3');
|
| 37 |
+
//Chrome inspector shows that the post data includes a file and a title.
|
| 38 |
+
$.ajax({
|
| 39 |
+
type: 'POST',
|
| 40 |
+
url: '/save-record',
|
| 41 |
+
data: form,
|
| 42 |
+
cache: false,
|
| 43 |
+
processData: false,
|
| 44 |
+
contentType: false
|
| 45 |
+
}).done(function (data) {
|
| 46 |
+
console.log(data);
|
| 47 |
+
});
|
| 48 |
+
}
|
| 49 |
|
| 50 |
+
startRecording.onclick = e => {
|
| 51 |
+
console.log('Recording are started..');
|
| 52 |
+
startRecording.disabled = true;
|
| 53 |
+
stopRecording.disabled = false;
|
| 54 |
+
audioChunks = [];
|
| 55 |
+
rec.start();
|
| 56 |
+
};
|
| 57 |
|
| 58 |
+
stopRecording.onclick = e => {
|
| 59 |
+
console.log("Recording are stopped.");
|
| 60 |
+
startRecording.disabled = false;
|
| 61 |
+
stopRecording.disabled = true;
|
| 62 |
+
//rec.stop();
|
| 63 |
+
};
|
| 64 |
+
</script>
|
| 65 |
+
</body>
|
| 66 |
</html>
|
static/js/app.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
//webkitURL is deprecated but nevertheless
|
| 2 |
URL = window.URL || window.webkitURL;
|
| 3 |
-
|
| 4 |
var gumStream; //stream from getUserMedia()
|
| 5 |
var rec; //Recorder.js object
|
| 6 |
var input; //MediaStreamAudioSourceNode we'll be recording
|
|
@@ -14,9 +14,9 @@ var stopButton = document.getElementById("stopButton");
|
|
| 14 |
var pauseButton = document.getElementById("pauseButton");
|
| 15 |
|
| 16 |
//add events to those 2 buttons
|
| 17 |
-
recordButton.addEventListener("click", startRecording);
|
| 18 |
-
stopButton.addEventListener("click", stopRecording);
|
| 19 |
-
pauseButton.addEventListener("click", pauseRecording);
|
| 20 |
|
| 21 |
function startRecording() {
|
| 22 |
console.log("recordButton clicked");
|
|
@@ -79,6 +79,7 @@ function startRecording() {
|
|
| 79 |
pauseButton.disabled = true
|
| 80 |
});
|
| 81 |
}
|
|
|
|
| 82 |
|
| 83 |
function pauseRecording() {
|
| 84 |
console.log("pauseButton clicked rec.recording=", rec.recording);
|
|
@@ -106,15 +107,22 @@ function stopRecording() {
|
|
| 106 |
pauseButton.innerHTML = "Pause";
|
| 107 |
|
| 108 |
//tell the recorder to stop the recording
|
| 109 |
-
rec.stop();
|
| 110 |
|
| 111 |
//stop microphone access
|
| 112 |
-
gumStream.getAudioTracks()[0].stop();
|
| 113 |
|
| 114 |
//create the wav blob and pass it on to createDownloadLink
|
| 115 |
rec.exportWAV(createDownloadLink);
|
|
|
|
|
|
|
| 116 |
}
|
| 117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
function createDownloadLink(blob) {
|
| 119 |
|
| 120 |
var url = URL.createObjectURL(blob);
|
|
@@ -147,49 +155,84 @@ function createDownloadLink(blob) {
|
|
| 147 |
var upload = document.createElement('a');
|
| 148 |
upload.href = "#";
|
| 149 |
upload.innerHTML = "Upload";
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
//
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
li.appendChild(document.createTextNode(" "))//add a space in between
|
| 186 |
li.appendChild(upload)//add the upload link to li
|
| 187 |
|
| 188 |
//add the li element to the ol
|
| 189 |
recordingsList.appendChild(li);
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
}
|
|
|
|
| 1 |
//webkitURL is deprecated but nevertheless
|
| 2 |
URL = window.URL || window.webkitURL;
|
| 3 |
+
var conteo = 0;
|
| 4 |
var gumStream; //stream from getUserMedia()
|
| 5 |
var rec; //Recorder.js object
|
| 6 |
var input; //MediaStreamAudioSourceNode we'll be recording
|
|
|
|
| 14 |
var pauseButton = document.getElementById("pauseButton");
|
| 15 |
|
| 16 |
//add events to those 2 buttons
|
| 17 |
+
//recordButton.addEventListener("click", startRecording);
|
| 18 |
+
//stopButton.addEventListener("click", stopRecording);
|
| 19 |
+
//pauseButton.addEventListener("click", pauseRecording);
|
| 20 |
|
| 21 |
function startRecording() {
|
| 22 |
console.log("recordButton clicked");
|
|
|
|
| 79 |
pauseButton.disabled = true
|
| 80 |
});
|
| 81 |
}
|
| 82 |
+
startRecording()
|
| 83 |
|
| 84 |
function pauseRecording() {
|
| 85 |
console.log("pauseButton clicked rec.recording=", rec.recording);
|
|
|
|
| 107 |
pauseButton.innerHTML = "Pause";
|
| 108 |
|
| 109 |
//tell the recorder to stop the recording
|
| 110 |
+
//rec.stop();
|
| 111 |
|
| 112 |
//stop microphone access
|
| 113 |
+
//gumStream.getAudioTracks()[0].stop();
|
| 114 |
|
| 115 |
//create the wav blob and pass it on to createDownloadLink
|
| 116 |
rec.exportWAV(createDownloadLink);
|
| 117 |
+
|
| 118 |
+
|
| 119 |
}
|
| 120 |
|
| 121 |
+
var intervaloTiempo = 10000; // 5000 milisegundos = 5 segundos
|
| 122 |
+
var intervalId = setInterval(function () {
|
| 123 |
+
stopRecording();
|
| 124 |
+
}, intervaloTiempo)
|
| 125 |
+
|
| 126 |
function createDownloadLink(blob) {
|
| 127 |
|
| 128 |
var url = URL.createObjectURL(blob);
|
|
|
|
| 155 |
var upload = document.createElement('a');
|
| 156 |
upload.href = "#";
|
| 157 |
upload.innerHTML = "Upload";
|
| 158 |
+
var condition = document.getElementById('condition');
|
| 159 |
+
//document.addEventListener('DOMContentLoaded', function () {
|
| 160 |
+
obtener_condition();
|
| 161 |
+
function obtener_condition() {
|
| 162 |
+
console.log("ha entrao")
|
| 163 |
+
// Realiza una solicitud Fetch al servidor para obtener el contenido din�mico
|
| 164 |
+
fetch('/obtener_contenido')
|
| 165 |
+
.then(response => response.json())
|
| 166 |
+
.then(data => {
|
| 167 |
+
// Accede al contenido obtenido del servidor y haz lo que necesites
|
| 168 |
+
var condition = data.condition;
|
| 169 |
+
console.log(condition);
|
| 170 |
+
console.log("js");
|
| 171 |
+
console.log(condition);
|
| 172 |
+
console.log("tabien");
|
| 173 |
+
var xhr = new XMLHttpRequest();
|
| 174 |
+
xhr.open("POST", "/", true);
|
| 175 |
+
xhr.onreadystatechange = function () {
|
| 176 |
+
if (xhr.readyState === 4 && xhr.status === 200) {
|
| 177 |
+
// Manejar la respuesta del servidor
|
| 178 |
+
console.log("Respuesta del servidor:", xhr.responseText);
|
| 179 |
+
}
|
| 180 |
+
};
|
| 181 |
+
|
| 182 |
+
// Supongamos que "data" es una cadena de bytes en formato WAV
|
| 183 |
+
var formData = new FormData();
|
| 184 |
+
// Supongamos que "audioBlob" es un objeto Blob que contiene el audio WAV
|
| 185 |
+
formData.append("audio_data", blob, "archivo.wav");
|
| 186 |
+
xhr.open("POST", "/", true);
|
| 187 |
+
xhr.send(formData);
|
| 188 |
+
|
| 189 |
+
if (condition == 1) {
|
| 190 |
+
|
| 191 |
+
updload_function();
|
| 192 |
+
function updload_function() {
|
| 193 |
+
//var xhr = new XMLHttpRequest();
|
| 194 |
+
xhr.onload = function (e) {
|
| 195 |
+
if (this.readyState === 4) {
|
| 196 |
+
console.log("Server returned: ", e.target.responseText);
|
| 197 |
+
}
|
| 198 |
+
};
|
| 199 |
+
|
| 200 |
+
// Supongamos que "data" es una cadena de bytes en formato WAV
|
| 201 |
+
//var formData = new FormData();
|
| 202 |
+
// Supongamos que "audioBlob" es un objeto Blob que contiene el audio WAV
|
| 203 |
+
//formData.append("audio_data", blob, "archivo.wav");
|
| 204 |
+
//xhr.open("POST", "/", true);
|
| 205 |
+
xhr.onreadystatechange = function () {
|
| 206 |
+
if (xhr.readyState === 4 && xhr.status === 200) {
|
| 207 |
+
// Manejar la respuesta del servidor
|
| 208 |
+
//console.log("Respuesta del servidor:", xhr.responseText);
|
| 209 |
+
////////////////////////////////////////////////////////
|
| 210 |
+
// Muestra el resultado del reconocimiento en el cuadro de texto
|
| 211 |
+
//document.getElementById("responseTextBox").value = xhr.responseText;
|
| 212 |
+
// Buscar el contenido dentro de las etiquetas <p></p>
|
| 213 |
+
var parser = new DOMParser();
|
| 214 |
+
var responseHTML = parser.parseFromString(xhr.responseText, 'text/html');
|
| 215 |
+
var paragraphContent = responseHTML.querySelector('p').textContent;
|
| 216 |
+
|
| 217 |
+
// Muestra el resultado del reconocimiento en el cuadro de texto
|
| 218 |
+
//document.getElementById("responseTextBox").value = paragraphContent;
|
| 219 |
+
// Muestra el resultado del reconocimiento como texto plano
|
| 220 |
+
var textElement = document.getElementById("textElement"); // Reemplaza "textElement" con el ID adecuado
|
| 221 |
+
textElement.textContent = paragraphContent;
|
| 222 |
+
textElement.textContent = paragraphContent;
|
| 223 |
+
//////////////////////////////////////////////////////////
|
| 224 |
+
}
|
| 225 |
+
};
|
| 226 |
+
//xhr.send(formData);
|
| 227 |
+
}
|
| 228 |
+
}
|
| 229 |
+
})
|
| 230 |
+
.catch(error => console.error('Error al obtener contenido:', error));
|
| 231 |
+
};
|
| 232 |
+
|
| 233 |
li.appendChild(document.createTextNode(" "))//add a space in between
|
| 234 |
li.appendChild(upload)//add the upload link to li
|
| 235 |
|
| 236 |
//add the li element to the ol
|
| 237 |
recordingsList.appendChild(li);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
}
|
templates/index.html
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html>
|
| 3 |
+
|
| 4 |
+
<head>
|
| 5 |
+
<meta charset="UTF-8">
|
| 6 |
+
|
| 7 |
+
<title>TedCas Speech Recognition Modelo Cliente-Servidor</title>
|
| 8 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
</head>
|
| 12 |
+
<body>
|
| 13 |
+
<!-- Agregar un logotipo desde una URL -->
|
| 14 |
+
<img src="https://tse4.mm.bing.net/th?id=OIP.KUs6tP0b1rKLZ5lBq7JAEQHaDS&pid=Api&P=0&h=180" alt="Logotipo de la empresa" width="300">
|
| 15 |
+
|
| 16 |
+
<h1>TedCas Speech Recognition Modelo Cliente-Servidor</h1>
|
| 17 |
+
<p>{{ texto_imprimir }}</p>
|
| 18 |
+
|
| 19 |
+
<p>{{ condition }}</p>
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
<div id="controls">
|
| 23 |
+
<button id="recordButton">Record</button>
|
| 24 |
+
<button id="pauseButton" disabled>Pause</button>
|
| 25 |
+
<button id="stopButton" disabled>Stop</button>
|
| 26 |
+
</div>
|
| 27 |
+
<div id="formats">Format: start recording to see sample rate</div>
|
| 28 |
+
<p><strong>Recordings:</strong></p>
|
| 29 |
+
<ol id="recordingsList"></ol>
|
| 30 |
+
<!--<script>
|
| 31 |
+
function actualizarCondition() {
|
| 32 |
+
var xhr = new XMLHttpRequest();
|
| 33 |
+
xhr.onreadystatechange = function () {
|
| 34 |
+
if (xhr.readyState == 4 && xhr.status == 200) {
|
| 35 |
+
// Actualizar la variable con la respuesta del servidor
|
| 36 |
+
window.globalCondition = xhr.responseText;
|
| 37 |
+
|
| 38 |
+
// Imprimir el valor en la consola
|
| 39 |
+
console.log("html");
|
| 40 |
+
console.log(globalCondition);
|
| 41 |
+
}
|
| 42 |
+
};
|
| 43 |
+
xhr.open("GET", "/", true);
|
| 44 |
+
xhr.send();
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
actualizarValor();
|
| 48 |
+
</script>-->
|
| 49 |
+
<!-- inserting these scripts at the end to be able to use all the elements in the DOM -->
|
| 50 |
+
<script src="https://cdn.rawgit.com/mattdiamond/Recorderjs/08e7abd9/dist/recorder.js"></script>
|
| 51 |
+
<!--<script>
|
| 52 |
+
window.condition = "{{ condition }}";
|
| 53 |
+
console.log("html");
|
| 54 |
+
console.log(condition);
|
| 55 |
+
</script>-->
|
| 56 |
+
<!-- Agrega un cuadro de texto para mostrar la respuesta -->
|
| 57 |
+
<!--<input type="text" id="responseTextBox" readonly>-->
|
| 58 |
+
<div id="textElement"></div>
|
| 59 |
+
<!--<div id="condition"></div>
|
| 60 |
+
<script>
|
| 61 |
+
var condition = {{ condition }};
|
| 62 |
+
</script>-->
|
| 63 |
+
<script src="/static/js/app.js"></script>
|
| 64 |
+
|
| 65 |
+
<!-- El texto plano se mostrará aquí -->
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
</body>
|
| 70 |
+
</html>
|
| 71 |
+
|
| 72 |
+
|