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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 7 |
+
|
| 8 |
+
// shim for AudioContext when it's not avb.
|
| 9 |
+
var AudioContext = window.AudioContext || window.webkitAudioContext;
|
| 10 |
+
var audioContext //audio context to help us record
|
| 11 |
+
|
| 12 |
+
var recordButton = document.getElementById("recordButton");
|
| 13 |
+
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");
|
| 23 |
+
|
| 24 |
+
/*
|
| 25 |
+
Simple constraints object, for more advanced audio features see
|
| 26 |
+
https://addpipe.com/blog/audio-constraints-getusermedia/
|
| 27 |
+
*/
|
| 28 |
+
|
| 29 |
+
var constraints = { audio: true, video: false }
|
| 30 |
+
|
| 31 |
+
/*
|
| 32 |
+
Disable the record button until we get a success or fail from getUserMedia()
|
| 33 |
+
*/
|
| 34 |
+
|
| 35 |
+
recordButton.disabled = true;
|
| 36 |
+
stopButton.disabled = false;
|
| 37 |
+
//pauseButton.disabled = false
|
| 38 |
+
|
| 39 |
+
/*
|
| 40 |
+
We're using the standard promise based getUserMedia()
|
| 41 |
+
https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia
|
| 42 |
+
*/
|
| 43 |
+
|
| 44 |
+
navigator.mediaDevices.getUserMedia(constraints).then(function (stream) {
|
| 45 |
+
console.log("getUserMedia() success, stream created, initializing Recorder.js ...");
|
| 46 |
+
|
| 47 |
+
/*
|
| 48 |
+
create an audio context after getUserMedia is called
|
| 49 |
+
sampleRate might change after getUserMedia is called, like it does on macOS when recording through AirPods
|
| 50 |
+
the sampleRate defaults to the one set in your OS for your playback device
|
| 51 |
+
*/
|
| 52 |
+
audioContext = new AudioContext();
|
| 53 |
+
|
| 54 |
+
//update the format
|
| 55 |
+
document.getElementById("formats").innerHTML = "Format: 1 channel pcm @ " + audioContext.sampleRate / 1000 + "kHz"
|
| 56 |
+
|
| 57 |
+
/* assign to gumStream for later use */
|
| 58 |
+
gumStream = stream;
|
| 59 |
+
|
| 60 |
+
/* use the stream */
|
| 61 |
+
input = audioContext.createMediaStreamSource(stream);
|
| 62 |
+
|
| 63 |
+
/*
|
| 64 |
+
Create the Recorder object and configure to record mono sound (1 channel)
|
| 65 |
+
Recording 2 channels will double the file size
|
| 66 |
+
*/
|
| 67 |
+
rec = new Recorder(input, { numChannels: 1 })
|
| 68 |
+
|
| 69 |
+
//start the recording process
|
| 70 |
+
rec.record()
|
| 71 |
+
|
| 72 |
+
console.log("Recording started");
|
| 73 |
+
|
| 74 |
+
}).catch(function (err) {
|
| 75 |
+
//enable the record button if getUserMedia() fails
|
| 76 |
+
recordButton.disabled = false;
|
| 77 |
+
stopButton.disabled = true;
|
| 78 |
+
//pauseButton.disabled = true
|
| 79 |
+
});
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
//function pauseRecording() {
|
| 83 |
+
// console.log("pauseButton clicked rec.recording=", rec.recording);
|
| 84 |
+
// if (rec.recording) {
|
| 85 |
+
// //pause
|
| 86 |
+
// rec.stop();
|
| 87 |
+
// pauseButton.innerHTML = "Resume";
|
| 88 |
+
// } else {
|
| 89 |
+
// //resume
|
| 90 |
+
// rec.record()
|
| 91 |
+
// pauseButton.innerHTML = "Pause";
|
| 92 |
+
|
| 93 |
+
// }
|
| 94 |
+
//}
|
| 95 |
+
|
| 96 |
+
function stopRecording() {
|
| 97 |
+
console.log("stopButton clicked");
|
| 98 |
+
|
| 99 |
+
//disable the stop button, enable the record too allow for new recordings
|
| 100 |
+
stopButton.disabled = true;
|
| 101 |
+
recordButton.disabled = false;
|
| 102 |
+
//pauseButton.disabled = true;
|
| 103 |
+
|
| 104 |
+
//reset button just in case the recording is stopped while paused
|
| 105 |
+
//pauseButton.innerHTML = "Pause";
|
| 106 |
+
|
| 107 |
+
//tell the recorder to stop the recording
|
| 108 |
+
rec.stop();
|
| 109 |
+
|
| 110 |
+
//stop microphone access
|
| 111 |
+
gumStream.getAudioTracks()[0].stop();
|
| 112 |
+
|
| 113 |
+
//create the wav blob and pass it on to createDownloadLink
|
| 114 |
+
//rec.exportWAV(createDownloadLink);
|
| 115 |
+
// Exportar los datos de audio como un Blob una vez que la grabaci n haya finalizado
|
| 116 |
+
rec.exportWAV(function (blob) {
|
| 117 |
+
// La funci n de devoluci n de llamada se llama con el Blob que contiene los datos de audio en formato WAV
|
| 118 |
+
// Puedes utilizar este Blob como desees, por ejemplo, crear una URL para descargarlo
|
| 119 |
+
var url = URL.createObjectURL(blob);
|
| 120 |
+
|
| 121 |
+
// Puedes utilizar audioUrl para reproducir o descargar el archivo de audio
|
| 122 |
+
/////////////////////////////////////////////////////////////////////////
|
| 123 |
+
//var url = URL.createObjectURL(blob);
|
| 124 |
+
var au = document.createElement('audio');
|
| 125 |
+
var li = document.createElement('li');
|
| 126 |
+
var link = document.createElement('a');
|
| 127 |
+
|
| 128 |
+
//name of .wav file to use during upload and download (without extendion)
|
| 129 |
+
var filename = new Date().toISOString();
|
| 130 |
+
|
| 131 |
+
//add controls to the <audio> element
|
| 132 |
+
au.controls = true;
|
| 133 |
+
au.src = url;
|
| 134 |
+
|
| 135 |
+
//save to disk link
|
| 136 |
+
link.href = url;
|
| 137 |
+
link.download = filename + ".wav"; //download forces the browser to donwload the file using the filename
|
| 138 |
+
link.innerHTML = "Save to disk";
|
| 139 |
+
|
| 140 |
+
//add the new audio element to li
|
| 141 |
+
li.appendChild(au);
|
| 142 |
+
|
| 143 |
+
//add the filename to the li
|
| 144 |
+
li.appendChild(document.createTextNode(filename + ".wav "))
|
| 145 |
+
|
| 146 |
+
//add the save to disk link to li
|
| 147 |
+
li.appendChild(link);
|
| 148 |
+
|
| 149 |
+
//upload link
|
| 150 |
+
var upload = document.createElement('a');
|
| 151 |
+
upload.href = "#";
|
| 152 |
+
upload.innerHTML = "Upload";
|
| 153 |
+
//upload.addEventListener("click", function (event) {
|
| 154 |
+
var xhr = new XMLHttpRequest();
|
| 155 |
+
xhr.onload = function (e) {
|
| 156 |
+
if (this.readyState === 4) {
|
| 157 |
+
console.log("Server returned: ", e.target.responseText);
|
| 158 |
+
}
|
| 159 |
+
};
|
| 160 |
+
|
| 161 |
+
// Supongamos que "data" es una cadena de bytes en formato WAV
|
| 162 |
+
var formData = new FormData();
|
| 163 |
+
// Supongamos que "audioBlob" es un objeto Blob que contiene el audio WAV
|
| 164 |
+
formData.append("audio_data", blob, "archivo.wav");
|
| 165 |
+
xhr.open("POST", "/escuchar_trauma", true);
|
| 166 |
+
xhr.onreadystatechange = function () {
|
| 167 |
+
if (xhr.readyState === 4 && xhr.status === 200) {
|
| 168 |
+
// Manejar la respuesta del servidor
|
| 169 |
+
console.log("Respuesta del servidor:", xhr.responseText);
|
| 170 |
+
////////////////////////////////////////////////////////
|
| 171 |
+
// Muestra el resultado del reconocimiento en el cuadro de texto
|
| 172 |
+
//document.getElementById("responseTextBox").value = xhr.responseText;
|
| 173 |
+
// Buscar el contenido dentro de las etiquetas <p></p>
|
| 174 |
+
//var parser = new DOMParser();
|
| 175 |
+
//var responseHTML = parser.parseFromString(xhr.responseText, 'text/html');
|
| 176 |
+
/*var paragraphContent = responseHTML.querySelector('p').textContent;*/
|
| 177 |
+
|
| 178 |
+
// Muestra el resultado del reconocimiento en el cuadro de texto
|
| 179 |
+
//document.getElementById("responseTextBox").value = paragraphContent;
|
| 180 |
+
// Muestra el resultado del reconocimiento como texto plano
|
| 181 |
+
//var textElement = document.getElementById("textElement"); // Reemplaza "textElement" con el ID adecuado
|
| 182 |
+
//textElement.textContent = paragraphContent;
|
| 183 |
+
//////////////////////////////////////////////////////////
|
| 184 |
+
}
|
| 185 |
+
};
|
| 186 |
+
xhr.send(formData);
|
| 187 |
+
|
| 188 |
+
//////////////////////////////////////////
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
// 4. This will be called after the response is received
|
| 192 |
+
xhr.onload = function () {
|
| 193 |
+
if (xhr.status != 200) {
|
| 194 |
+
// analyze HTTP status of the response
|
| 195 |
+
alert(`Error ${xhr.status}: ${xhr.statusText}`);
|
| 196 |
+
// e.g. 404: Not Found
|
| 197 |
+
} else { // show the result
|
| 198 |
+
$('body').html(xhr.response)
|
| 199 |
+
}
|
| 200 |
+
};
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
///////////////////////////////////////////
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
//});
|
| 211 |
+
//li.appendChild(document.createTextNode(" "))//add a space in between
|
| 212 |
+
//li.appendChild(upload)//add the upload link to li
|
| 213 |
+
|
| 214 |
+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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 7 |
+
|
| 8 |
+
// shim for AudioContext when it's not avb.
|
| 9 |
+
var AudioContext = window.AudioContext || window.webkitAudioContext;
|
| 10 |
+
var audioContext //audio context to help us record
|
| 11 |
+
|
| 12 |
+
var recordButton = document.getElementById("recordButton");
|
| 13 |
+
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");
|
| 23 |
+
|
| 24 |
+
/*
|
| 25 |
+
Simple constraints object, for more advanced audio features see
|
| 26 |
+
https://addpipe.com/blog/audio-constraints-getusermedia/
|
| 27 |
+
*/
|
| 28 |
+
|
| 29 |
+
var constraints = { audio: true, video: false }
|
| 30 |
+
|
| 31 |
+
/*
|
| 32 |
+
Disable the record button until we get a success or fail from getUserMedia()
|
| 33 |
+
*/
|
| 34 |
+
|
| 35 |
+
recordButton.disabled = true;
|
| 36 |
+
stopButton.disabled = false;
|
| 37 |
+
//pauseButton.disabled = false
|
| 38 |
+
|
| 39 |
+
/*
|
| 40 |
+
We're using the standard promise based getUserMedia()
|
| 41 |
+
https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia
|
| 42 |
+
*/
|
| 43 |
+
|
| 44 |
+
navigator.mediaDevices.getUserMedia(constraints).then(function (stream) {
|
| 45 |
+
console.log("getUserMedia() success, stream created, initializing Recorder.js ...");
|
| 46 |
+
|
| 47 |
+
/*
|
| 48 |
+
create an audio context after getUserMedia is called
|
| 49 |
+
sampleRate might change after getUserMedia is called, like it does on macOS when recording through AirPods
|
| 50 |
+
the sampleRate defaults to the one set in your OS for your playback device
|
| 51 |
+
*/
|
| 52 |
+
audioContext = new AudioContext();
|
| 53 |
+
|
| 54 |
+
//update the format
|
| 55 |
+
document.getElementById("formats").innerHTML = "Format: 1 channel pcm @ " + audioContext.sampleRate / 1000 + "kHz"
|
| 56 |
+
|
| 57 |
+
/* assign to gumStream for later use */
|
| 58 |
+
gumStream = stream;
|
| 59 |
+
|
| 60 |
+
/* use the stream */
|
| 61 |
+
input = audioContext.createMediaStreamSource(stream);
|
| 62 |
+
|
| 63 |
+
/*
|
| 64 |
+
Create the Recorder object and configure to record mono sound (1 channel)
|
| 65 |
+
Recording 2 channels will double the file size
|
| 66 |
+
*/
|
| 67 |
+
rec = new Recorder(input, { numChannels: 1 })
|
| 68 |
+
|
| 69 |
+
//start the recording process
|
| 70 |
+
rec.record()
|
| 71 |
+
|
| 72 |
+
console.log("Recording started");
|
| 73 |
+
|
| 74 |
+
}).catch(function (err) {
|
| 75 |
+
//enable the record button if getUserMedia() fails
|
| 76 |
+
recordButton.disabled = false;
|
| 77 |
+
stopButton.disabled = true;
|
| 78 |
+
//pauseButton.disabled = true
|
| 79 |
+
});
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
//function pauseRecording() {
|
| 83 |
+
// console.log("pauseButton clicked rec.recording=", rec.recording);
|
| 84 |
+
// if (rec.recording) {
|
| 85 |
+
// //pause
|
| 86 |
+
// rec.stop();
|
| 87 |
+
// pauseButton.innerHTML = "Resume";
|
| 88 |
+
// } else {
|
| 89 |
+
// //resume
|
| 90 |
+
// rec.record()
|
| 91 |
+
// pauseButton.innerHTML = "Pause";
|
| 92 |
+
|
| 93 |
+
// }
|
| 94 |
+
//}
|
| 95 |
+
|
| 96 |
+
function stopRecording() {
|
| 97 |
+
console.log("stopButton clicked");
|
| 98 |
+
|
| 99 |
+
//disable the stop button, enable the record too allow for new recordings
|
| 100 |
+
stopButton.disabled = true;
|
| 101 |
+
recordButton.disabled = false;
|
| 102 |
+
//pauseButton.disabled = true;
|
| 103 |
+
|
| 104 |
+
//reset button just in case the recording is stopped while paused
|
| 105 |
+
//pauseButton.innerHTML = "Pause";
|
| 106 |
+
|
| 107 |
+
//tell the recorder to stop the recording
|
| 108 |
+
rec.stop();
|
| 109 |
+
|
| 110 |
+
//stop microphone access
|
| 111 |
+
gumStream.getAudioTracks()[0].stop();
|
| 112 |
+
|
| 113 |
+
//create the wav blob and pass it on to createDownloadLink
|
| 114 |
+
//rec.exportWAV(createDownloadLink);
|
| 115 |
+
// Exportar los datos de audio como un Blob una vez que la grabaci n haya finalizado
|
| 116 |
+
rec.exportWAV(function (blob) {
|
| 117 |
+
// La funci n de devoluci n de llamada se llama con el Blob que contiene los datos de audio en formato WAV
|
| 118 |
+
// Puedes utilizar este Blob como desees, por ejemplo, crear una URL para descargarlo
|
| 119 |
+
var url = URL.createObjectURL(blob);
|
| 120 |
+
|
| 121 |
+
// Puedes utilizar audioUrl para reproducir o descargar el archivo de audio
|
| 122 |
+
/////////////////////////////////////////////////////////////////////////
|
| 123 |
+
//var url = URL.createObjectURL(blob);
|
| 124 |
+
var au = document.createElement('audio');
|
| 125 |
+
var li = document.createElement('li');
|
| 126 |
+
var link = document.createElement('a');
|
| 127 |
+
|
| 128 |
+
//name of .wav file to use during upload and download (without extendion)
|
| 129 |
+
var filename = new Date().toISOString();
|
| 130 |
+
|
| 131 |
+
//add controls to the <audio> element
|
| 132 |
+
au.controls = true;
|
| 133 |
+
au.src = url;
|
| 134 |
+
|
| 135 |
+
//save to disk link
|
| 136 |
+
link.href = url;
|
| 137 |
+
link.download = filename + ".wav"; //download forces the browser to donwload the file using the filename
|
| 138 |
+
link.innerHTML = "Save to disk";
|
| 139 |
+
|
| 140 |
+
//add the new audio element to li
|
| 141 |
+
li.appendChild(au);
|
| 142 |
+
|
| 143 |
+
//add the filename to the li
|
| 144 |
+
li.appendChild(document.createTextNode(filename + ".wav "))
|
| 145 |
+
|
| 146 |
+
//add the save to disk link to li
|
| 147 |
+
li.appendChild(link);
|
| 148 |
+
|
| 149 |
+
//upload link
|
| 150 |
+
var upload = document.createElement('a');
|
| 151 |
+
upload.href = "#";
|
| 152 |
+
upload.innerHTML = "Upload";
|
| 153 |
+
//upload.addEventListener("click", function (event) {
|
| 154 |
+
var xhr = new XMLHttpRequest();
|
| 155 |
+
xhr.onload = function (e) {
|
| 156 |
+
if (this.readyState === 4) {
|
| 157 |
+
console.log("Server returned: ", e.target.responseText);
|
| 158 |
+
}
|
| 159 |
+
};
|
| 160 |
+
|
| 161 |
+
// Supongamos que "data" es una cadena de bytes en formato WAV
|
| 162 |
+
var formData = new FormData();
|
| 163 |
+
// Supongamos que "audioBlob" es un objeto Blob que contiene el audio WAV
|
| 164 |
+
formData.append("audio_data", blob, "archivo.wav");
|
| 165 |
+
xhr.open("POST", "/escuchar_admision", true);
|
| 166 |
+
xhr.onreadystatechange = function () {
|
| 167 |
+
if (xhr.readyState === 4 && xhr.status === 200) {
|
| 168 |
+
// Manejar la respuesta del servidor
|
| 169 |
+
console.log("Respuesta del servidor:", xhr.responseText);
|
| 170 |
+
////////////////////////////////////////////////////////
|
| 171 |
+
// Muestra el resultado del reconocimiento en el cuadro de texto
|
| 172 |
+
//document.getElementById("responseTextBox").value = xhr.responseText;
|
| 173 |
+
// Buscar el contenido dentro de las etiquetas <p></p>
|
| 174 |
+
//var parser = new DOMParser();
|
| 175 |
+
//var responseHTML = parser.parseFromString(xhr.responseText, 'text/html');
|
| 176 |
+
/*var paragraphContent = responseHTML.querySelector('p').textContent;*/
|
| 177 |
+
|
| 178 |
+
// Muestra el resultado del reconocimiento en el cuadro de texto
|
| 179 |
+
//document.getElementById("responseTextBox").value = paragraphContent;
|
| 180 |
+
// Muestra el resultado del reconocimiento como texto plano
|
| 181 |
+
//var textElement = document.getElementById("textElement"); // Reemplaza "textElement" con el ID adecuado
|
| 182 |
+
//textElement.textContent = paragraphContent;
|
| 183 |
+
//////////////////////////////////////////////////////////
|
| 184 |
+
}
|
| 185 |
+
};
|
| 186 |
+
xhr.send(formData);
|
| 187 |
+
|
| 188 |
+
//////////////////////////////////////////
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
// 4. This will be called after the response is received
|
| 192 |
+
xhr.onload = function () {
|
| 193 |
+
if (xhr.status != 200) {
|
| 194 |
+
// analyze HTTP status of the response
|
| 195 |
+
alert(`Error ${xhr.status}: ${xhr.statusText}`);
|
| 196 |
+
// e.g. 404: Not Found
|
| 197 |
+
} else { // show the result
|
| 198 |
+
$('body').html(xhr.response)
|
| 199 |
+
}
|
| 200 |
+
};
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
///////////////////////////////////////////
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
//});
|
| 211 |
+
//li.appendChild(document.createTextNode(" "))//add a space in between
|
| 212 |
+
//li.appendChild(upload)//add the upload link to li
|
| 213 |
+
|
| 214 |
+
//add the li element to the ol
|
| 215 |
+
recordingsList.appendChild(li);
|
| 216 |
+
});
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
//function createDownloadLink(blob) {
|
| 224 |
+
|
| 225 |
+
// var url = URL.createObjectURL(blob);
|
| 226 |
+
// var au = document.createElement('audio');
|
| 227 |
+
// var li = document.createElement('li');
|
| 228 |
+
// var link = document.createElement('a');
|
| 229 |
+
|
| 230 |
+
// //name of .wav file to use during upload and download (without extendion)
|
| 231 |
+
// var filename = new Date().toISOString();
|
| 232 |
+
|
| 233 |
+
// //add controls to the <audio> element
|
| 234 |
+
// au.controls = true;
|
| 235 |
+
// au.src = url;
|
| 236 |
+
|
| 237 |
+
// //save to disk link
|
| 238 |
+
// link.href = url;
|
| 239 |
+
// link.download = filename + ".wav"; //download forces the browser to donwload the file using the filename
|
| 240 |
+
// link.innerHTML = "Save to disk";
|
| 241 |
+
|
| 242 |
+
// //add the new audio element to li
|
| 243 |
+
// li.appendChild(au);
|
| 244 |
+
|
| 245 |
+
// //add the filename to the li
|
| 246 |
+
// li.appendChild(document.createTextNode(filename + ".wav "))
|
| 247 |
+
|
| 248 |
+
// //add the save to disk link to li
|
| 249 |
+
// li.appendChild(link);
|
| 250 |
+
|
| 251 |
+
// //upload link
|
| 252 |
+
// var upload = document.createElement('a');
|
| 253 |
+
// upload.href = "#";
|
| 254 |
+
// upload.innerHTML = "Upload";
|
| 255 |
+
// upload.addEventListener("click", function (event) {
|
| 256 |
+
// var xhr = new XMLHttpRequest();
|
| 257 |
+
// xhr.onload = function (e) {
|
| 258 |
+
// if (this.readyState === 4) {
|
| 259 |
+
// console.log("Server returned: ", e.target.responseText);
|
| 260 |
+
// }
|
| 261 |
+
// };
|
| 262 |
+
|
| 263 |
+
// // Supongamos que "data" es una cadena de bytes en formato WAV
|
| 264 |
+
// var formData = new FormData();
|
| 265 |
+
// // Supongamos que "audioBlob" es un objeto Blob que contiene el audio WAV
|
| 266 |
+
// formData.append("audio_data", blob, "archivo.wav");
|
| 267 |
+
// xhr.open("POST", "/escuchar_trauma", true);
|
| 268 |
+
// xhr.onreadystatechange = function () {
|
| 269 |
+
// if (xhr.readyState === 4 && xhr.status === 200) {
|
| 270 |
+
// // Manejar la respuesta del servidor
|
| 271 |
+
// console.log("Respuesta del servidor:", xhr.responseText);
|
| 272 |
+
// ////////////////////////////////////////////////////////
|
| 273 |
+
// // Muestra el resultado del reconocimiento en el cuadro de texto
|
| 274 |
+
// //document.getElementById("responseTextBox").value = xhr.responseText;
|
| 275 |
+
// // Buscar el contenido dentro de las etiquetas <p></p>
|
| 276 |
+
// //var parser = new DOMParser();
|
| 277 |
+
// //var responseHTML = parser.parseFromString(xhr.responseText, 'text/html');
|
| 278 |
+
// /*var paragraphContent = responseHTML.querySelector('p').textContent;*/
|
| 279 |
+
|
| 280 |
+
// // Muestra el resultado del reconocimiento en el cuadro de texto
|
| 281 |
+
// //document.getElementById("responseTextBox").value = paragraphContent;
|
| 282 |
+
// // Muestra el resultado del reconocimiento como texto plano
|
| 283 |
+
// //var textElement = document.getElementById("textElement"); // Reemplaza "textElement" con el ID adecuado
|
| 284 |
+
// //textElement.textContent = paragraphContent;
|
| 285 |
+
// //////////////////////////////////////////////////////////
|
| 286 |
+
// }
|
| 287 |
+
// };
|
| 288 |
+
// xhr.send(formData);
|
| 289 |
+
|
| 290 |
+
// //////////////////////////////////////////
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
// // 4. This will be called after the response is received
|
| 294 |
+
// xhr.onload = function () {
|
| 295 |
+
// if (xhr.status != 200) {
|
| 296 |
+
// // analyze HTTP status of the response
|
| 297 |
+
// alert(`Error ${xhr.status}: ${xhr.statusText}`);
|
| 298 |
+
// // e.g. 404: Not Found
|
| 299 |
+
// } else { // show the result
|
| 300 |
+
// $('body').html(xhr.response)
|
| 301 |
+
// }
|
| 302 |
+
// };
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
|
| 306 |
+
|
| 307 |
+
// ///////////////////////////////////////////
|
| 308 |
+
|
| 309 |
+
|
| 310 |
+
|
| 311 |
+
|
| 312 |
+
// })
|
| 313 |
+
// li.appendChild(document.createTextNode(" "))//add a space in between
|
| 314 |
+
// li.appendChild(upload)//add the upload link to li
|
| 315 |
+
|
| 316 |
+
// //add the li element to the ol
|
| 317 |
+
// recordingsList.appendChild(li);
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
|
| 321 |
+
|
| 322 |
+
|
| 323 |
+
//}
|
static/js/appuro.js
ADDED
|
@@ -0,0 +1,323 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 7 |
+
|
| 8 |
+
// shim for AudioContext when it's not avb.
|
| 9 |
+
var AudioContext = window.AudioContext || window.webkitAudioContext;
|
| 10 |
+
var audioContext //audio context to help us record
|
| 11 |
+
|
| 12 |
+
var recordButton = document.getElementById("recordButton");
|
| 13 |
+
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");
|
| 23 |
+
|
| 24 |
+
/*
|
| 25 |
+
Simple constraints object, for more advanced audio features see
|
| 26 |
+
https://addpipe.com/blog/audio-constraints-getusermedia/
|
| 27 |
+
*/
|
| 28 |
+
|
| 29 |
+
var constraints = { audio: true, video: false }
|
| 30 |
+
|
| 31 |
+
/*
|
| 32 |
+
Disable the record button until we get a success or fail from getUserMedia()
|
| 33 |
+
*/
|
| 34 |
+
|
| 35 |
+
recordButton.disabled = true;
|
| 36 |
+
stopButton.disabled = false;
|
| 37 |
+
//pauseButton.disabled = false
|
| 38 |
+
|
| 39 |
+
/*
|
| 40 |
+
We're using the standard promise based getUserMedia()
|
| 41 |
+
https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia
|
| 42 |
+
*/
|
| 43 |
+
|
| 44 |
+
navigator.mediaDevices.getUserMedia(constraints).then(function (stream) {
|
| 45 |
+
console.log("getUserMedia() success, stream created, initializing Recorder.js ...");
|
| 46 |
+
|
| 47 |
+
/*
|
| 48 |
+
create an audio context after getUserMedia is called
|
| 49 |
+
sampleRate might change after getUserMedia is called, like it does on macOS when recording through AirPods
|
| 50 |
+
the sampleRate defaults to the one set in your OS for your playback device
|
| 51 |
+
*/
|
| 52 |
+
audioContext = new AudioContext();
|
| 53 |
+
|
| 54 |
+
//update the format
|
| 55 |
+
document.getElementById("formats").innerHTML = "Format: 1 channel pcm @ " + audioContext.sampleRate / 1000 + "kHz"
|
| 56 |
+
|
| 57 |
+
/* assign to gumStream for later use */
|
| 58 |
+
gumStream = stream;
|
| 59 |
+
|
| 60 |
+
/* use the stream */
|
| 61 |
+
input = audioContext.createMediaStreamSource(stream);
|
| 62 |
+
|
| 63 |
+
/*
|
| 64 |
+
Create the Recorder object and configure to record mono sound (1 channel)
|
| 65 |
+
Recording 2 channels will double the file size
|
| 66 |
+
*/
|
| 67 |
+
rec = new Recorder(input, { numChannels: 1 })
|
| 68 |
+
|
| 69 |
+
//start the recording process
|
| 70 |
+
rec.record()
|
| 71 |
+
|
| 72 |
+
console.log("Recording started");
|
| 73 |
+
|
| 74 |
+
}).catch(function (err) {
|
| 75 |
+
//enable the record button if getUserMedia() fails
|
| 76 |
+
recordButton.disabled = false;
|
| 77 |
+
stopButton.disabled = true;
|
| 78 |
+
//pauseButton.disabled = true
|
| 79 |
+
});
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
//function pauseRecording() {
|
| 83 |
+
// console.log("pauseButton clicked rec.recording=", rec.recording);
|
| 84 |
+
// if (rec.recording) {
|
| 85 |
+
// //pause
|
| 86 |
+
// rec.stop();
|
| 87 |
+
// pauseButton.innerHTML = "Resume";
|
| 88 |
+
// } else {
|
| 89 |
+
// //resume
|
| 90 |
+
// rec.record()
|
| 91 |
+
// pauseButton.innerHTML = "Pause";
|
| 92 |
+
|
| 93 |
+
// }
|
| 94 |
+
//}
|
| 95 |
+
|
| 96 |
+
function stopRecording() {
|
| 97 |
+
console.log("stopButton clicked");
|
| 98 |
+
|
| 99 |
+
//disable the stop button, enable the record too allow for new recordings
|
| 100 |
+
stopButton.disabled = true;
|
| 101 |
+
recordButton.disabled = false;
|
| 102 |
+
//pauseButton.disabled = true;
|
| 103 |
+
|
| 104 |
+
//reset button just in case the recording is stopped while paused
|
| 105 |
+
//pauseButton.innerHTML = "Pause";
|
| 106 |
+
|
| 107 |
+
//tell the recorder to stop the recording
|
| 108 |
+
rec.stop();
|
| 109 |
+
|
| 110 |
+
//stop microphone access
|
| 111 |
+
gumStream.getAudioTracks()[0].stop();
|
| 112 |
+
|
| 113 |
+
//create the wav blob and pass it on to createDownloadLink
|
| 114 |
+
//rec.exportWAV(createDownloadLink);
|
| 115 |
+
// Exportar los datos de audio como un Blob una vez que la grabaci n haya finalizado
|
| 116 |
+
rec.exportWAV(function (blob) {
|
| 117 |
+
// La funci n de devoluci n de llamada se llama con el Blob que contiene los datos de audio en formato WAV
|
| 118 |
+
// Puedes utilizar este Blob como desees, por ejemplo, crear una URL para descargarlo
|
| 119 |
+
var url = URL.createObjectURL(blob);
|
| 120 |
+
|
| 121 |
+
// Puedes utilizar audioUrl para reproducir o descargar el archivo de audio
|
| 122 |
+
/////////////////////////////////////////////////////////////////////////
|
| 123 |
+
//var url = URL.createObjectURL(blob);
|
| 124 |
+
var au = document.createElement('audio');
|
| 125 |
+
var li = document.createElement('li');
|
| 126 |
+
var link = document.createElement('a');
|
| 127 |
+
|
| 128 |
+
//name of .wav file to use during upload and download (without extendion)
|
| 129 |
+
var filename = new Date().toISOString();
|
| 130 |
+
|
| 131 |
+
//add controls to the <audio> element
|
| 132 |
+
au.controls = true;
|
| 133 |
+
au.src = url;
|
| 134 |
+
|
| 135 |
+
//save to disk link
|
| 136 |
+
link.href = url;
|
| 137 |
+
link.download = filename + ".wav"; //download forces the browser to donwload the file using the filename
|
| 138 |
+
link.innerHTML = "Save to disk";
|
| 139 |
+
|
| 140 |
+
//add the new audio element to li
|
| 141 |
+
li.appendChild(au);
|
| 142 |
+
|
| 143 |
+
//add the filename to the li
|
| 144 |
+
li.appendChild(document.createTextNode(filename + ".wav "))
|
| 145 |
+
|
| 146 |
+
//add the save to disk link to li
|
| 147 |
+
li.appendChild(link);
|
| 148 |
+
|
| 149 |
+
//upload link
|
| 150 |
+
var upload = document.createElement('a');
|
| 151 |
+
upload.href = "#";
|
| 152 |
+
upload.innerHTML = "Upload";
|
| 153 |
+
//upload.addEventListener("click", function (event) {
|
| 154 |
+
var xhr = new XMLHttpRequest();
|
| 155 |
+
xhr.onload = function (e) {
|
| 156 |
+
if (this.readyState === 4) {
|
| 157 |
+
console.log("Server returned: ", e.target.responseText);
|
| 158 |
+
}
|
| 159 |
+
};
|
| 160 |
+
|
| 161 |
+
// Supongamos que "data" es una cadena de bytes en formato WAV
|
| 162 |
+
var formData = new FormData();
|
| 163 |
+
// Supongamos que "audioBlob" es un objeto Blob que contiene el audio WAV
|
| 164 |
+
formData.append("audio_data", blob, "archivo.wav");
|
| 165 |
+
xhr.open("POST", "/escuchar_uro", true);
|
| 166 |
+
xhr.onreadystatechange = function () {
|
| 167 |
+
if (xhr.readyState === 4 && xhr.status === 200) {
|
| 168 |
+
// Manejar la respuesta del servidor
|
| 169 |
+
console.log("Respuesta del servidor:", xhr.responseText);
|
| 170 |
+
////////////////////////////////////////////////////////
|
| 171 |
+
// Muestra el resultado del reconocimiento en el cuadro de texto
|
| 172 |
+
//document.getElementById("responseTextBox").value = xhr.responseText;
|
| 173 |
+
// Buscar el contenido dentro de las etiquetas <p></p>
|
| 174 |
+
//var parser = new DOMParser();
|
| 175 |
+
//var responseHTML = parser.parseFromString(xhr.responseText, 'text/html');
|
| 176 |
+
/*var paragraphContent = responseHTML.querySelector('p').textContent;*/
|
| 177 |
+
|
| 178 |
+
// Muestra el resultado del reconocimiento en el cuadro de texto
|
| 179 |
+
//document.getElementById("responseTextBox").value = paragraphContent;
|
| 180 |
+
// Muestra el resultado del reconocimiento como texto plano
|
| 181 |
+
//var textElement = document.getElementById("textElement"); // Reemplaza "textElement" con el ID adecuado
|
| 182 |
+
//textElement.textContent = paragraphContent;
|
| 183 |
+
//////////////////////////////////////////////////////////
|
| 184 |
+
}
|
| 185 |
+
};
|
| 186 |
+
xhr.send(formData);
|
| 187 |
+
|
| 188 |
+
//////////////////////////////////////////
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
// 4. This will be called after the response is received
|
| 192 |
+
xhr.onload = function () {
|
| 193 |
+
if (xhr.status != 200) {
|
| 194 |
+
// analyze HTTP status of the response
|
| 195 |
+
alert(`Error ${xhr.status}: ${xhr.statusText}`);
|
| 196 |
+
// e.g. 404: Not Found
|
| 197 |
+
} else { // show the result
|
| 198 |
+
$('body').html(xhr.response)
|
| 199 |
+
}
|
| 200 |
+
};
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
///////////////////////////////////////////
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
//});
|
| 211 |
+
//li.appendChild(document.createTextNode(" "))//add a space in between
|
| 212 |
+
//li.appendChild(upload)//add the upload link to li
|
| 213 |
+
|
| 214 |
+
//add the li element to the ol
|
| 215 |
+
recordingsList.appendChild(li);
|
| 216 |
+
});
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
//function createDownloadLink(blob) {
|
| 224 |
+
|
| 225 |
+
// var url = URL.createObjectURL(blob);
|
| 226 |
+
// var au = document.createElement('audio');
|
| 227 |
+
// var li = document.createElement('li');
|
| 228 |
+
// var link = document.createElement('a');
|
| 229 |
+
|
| 230 |
+
// //name of .wav file to use during upload and download (without extendion)
|
| 231 |
+
// var filename = new Date().toISOString();
|
| 232 |
+
|
| 233 |
+
// //add controls to the <audio> element
|
| 234 |
+
// au.controls = true;
|
| 235 |
+
// au.src = url;
|
| 236 |
+
|
| 237 |
+
// //save to disk link
|
| 238 |
+
// link.href = url;
|
| 239 |
+
// link.download = filename + ".wav"; //download forces the browser to donwload the file using the filename
|
| 240 |
+
// link.innerHTML = "Save to disk";
|
| 241 |
+
|
| 242 |
+
// //add the new audio element to li
|
| 243 |
+
// li.appendChild(au);
|
| 244 |
+
|
| 245 |
+
// //add the filename to the li
|
| 246 |
+
// li.appendChild(document.createTextNode(filename + ".wav "))
|
| 247 |
+
|
| 248 |
+
// //add the save to disk link to li
|
| 249 |
+
// li.appendChild(link);
|
| 250 |
+
|
| 251 |
+
// //upload link
|
| 252 |
+
// var upload = document.createElement('a');
|
| 253 |
+
// upload.href = "#";
|
| 254 |
+
// upload.innerHTML = "Upload";
|
| 255 |
+
// upload.addEventListener("click", function (event) {
|
| 256 |
+
// var xhr = new XMLHttpRequest();
|
| 257 |
+
// xhr.onload = function (e) {
|
| 258 |
+
// if (this.readyState === 4) {
|
| 259 |
+
// console.log("Server returned: ", e.target.responseText);
|
| 260 |
+
// }
|
| 261 |
+
// };
|
| 262 |
+
|
| 263 |
+
// // Supongamos que "data" es una cadena de bytes en formato WAV
|
| 264 |
+
// var formData = new FormData();
|
| 265 |
+
// // Supongamos que "audioBlob" es un objeto Blob que contiene el audio WAV
|
| 266 |
+
// formData.append("audio_data", blob, "archivo.wav");
|
| 267 |
+
// xhr.open("POST", "/escuchar_trauma", true);
|
| 268 |
+
// xhr.onreadystatechange = function () {
|
| 269 |
+
// if (xhr.readyState === 4 && xhr.status === 200) {
|
| 270 |
+
// // Manejar la respuesta del servidor
|
| 271 |
+
// console.log("Respuesta del servidor:", xhr.responseText);
|
| 272 |
+
// ////////////////////////////////////////////////////////
|
| 273 |
+
// // Muestra el resultado del reconocimiento en el cuadro de texto
|
| 274 |
+
// //document.getElementById("responseTextBox").value = xhr.responseText;
|
| 275 |
+
// // Buscar el contenido dentro de las etiquetas <p></p>
|
| 276 |
+
// //var parser = new DOMParser();
|
| 277 |
+
// //var responseHTML = parser.parseFromString(xhr.responseText, 'text/html');
|
| 278 |
+
// /*var paragraphContent = responseHTML.querySelector('p').textContent;*/
|
| 279 |
+
|
| 280 |
+
// // Muestra el resultado del reconocimiento en el cuadro de texto
|
| 281 |
+
// //document.getElementById("responseTextBox").value = paragraphContent;
|
| 282 |
+
// // Muestra el resultado del reconocimiento como texto plano
|
| 283 |
+
// //var textElement = document.getElementById("textElement"); // Reemplaza "textElement" con el ID adecuado
|
| 284 |
+
// //textElement.textContent = paragraphContent;
|
| 285 |
+
// //////////////////////////////////////////////////////////
|
| 286 |
+
// }
|
| 287 |
+
// };
|
| 288 |
+
// xhr.send(formData);
|
| 289 |
+
|
| 290 |
+
// //////////////////////////////////////////
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
// // 4. This will be called after the response is received
|
| 294 |
+
// xhr.onload = function () {
|
| 295 |
+
// if (xhr.status != 200) {
|
| 296 |
+
// // analyze HTTP status of the response
|
| 297 |
+
// alert(`Error ${xhr.status}: ${xhr.statusText}`);
|
| 298 |
+
// // e.g. 404: Not Found
|
| 299 |
+
// } else { // show the result
|
| 300 |
+
// $('body').html(xhr.response)
|
| 301 |
+
// }
|
| 302 |
+
// };
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
|
| 306 |
+
|
| 307 |
+
// ///////////////////////////////////////////
|
| 308 |
+
|
| 309 |
+
|
| 310 |
+
|
| 311 |
+
|
| 312 |
+
// })
|
| 313 |
+
// li.appendChild(document.createTextNode(" "))//add a space in between
|
| 314 |
+
// li.appendChild(upload)//add the upload link to li
|
| 315 |
+
|
| 316 |
+
// //add the li element to the ol
|
| 317 |
+
// recordingsList.appendChild(li);
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
|
| 321 |
+
|
| 322 |
+
|
| 323 |
+
//}
|