Spaces:
Sleeping
Sleeping
Update templates/index.html
Browse files- templates/index.html +24 -18
templates/index.html
CHANGED
@@ -1,35 +1,41 @@
|
|
1 |
<!DOCTYPE html>
|
2 |
<html>
|
3 |
<head>
|
4 |
-
<title>Reconocimiento de Voz
|
5 |
</head>
|
6 |
<body>
|
7 |
-
<button id="
|
8 |
<div id="output"></div>
|
|
|
9 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.1/socket.io.js"></script>
|
10 |
<script>
|
11 |
const socket = io.connect('http://' + document.domain + ':' + location.port);
|
12 |
-
const
|
13 |
const outputDiv = document.getElementById('output');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
socket.emit('recognize_speech', result);
|
21 |
-
};
|
22 |
-
recognition.start();
|
23 |
});
|
24 |
|
25 |
-
socket.on('
|
26 |
outputDiv.innerHTML = `Texto reconocido: ${data}`;
|
27 |
});
|
28 |
</script>
|
29 |
</body>
|
30 |
-
</html>
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
1 |
<!DOCTYPE html>
|
2 |
<html>
|
3 |
<head>
|
4 |
+
<title>Reconocimiento de Voz con WebRTC</title>
|
5 |
</head>
|
6 |
<body>
|
7 |
+
<button id="startRecording">Iniciar Grabación</button>
|
8 |
<div id="output"></div>
|
9 |
+
|
10 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.1/socket.io.js"></script>
|
11 |
<script>
|
12 |
const socket = io.connect('http://' + document.domain + ':' + location.port);
|
13 |
+
const startRecordingButton = document.getElementById('startRecording');
|
14 |
const outputDiv = document.getElementById('output');
|
15 |
+
let mediaRecorder;
|
16 |
+
let audioChunks = [];
|
17 |
+
let recognition;
|
18 |
+
|
19 |
+
startRecordingButton.addEventListener('click', () => {
|
20 |
+
if (!recognition) {
|
21 |
+
recognition = new webkitSpeechRecognition();
|
22 |
+
recognition.lang = 'es-ES';
|
23 |
+
recognition.onresult = function (event) {
|
24 |
+
const result = event.results[0][0].transcript;
|
25 |
+
socket.emit('audio_data', result);
|
26 |
+
};
|
27 |
+
}
|
28 |
|
29 |
+
try {
|
30 |
+
recognition.start();
|
31 |
+
} catch (error) {
|
32 |
+
console.error('Error al iniciar el reconocimiento de voz:', error);
|
33 |
+
}
|
|
|
|
|
|
|
34 |
});
|
35 |
|
36 |
+
socket.on('transcription', function (data) {
|
37 |
outputDiv.innerHTML = `Texto reconocido: ${data}`;
|
38 |
});
|
39 |
</script>
|
40 |
</body>
|
41 |
+
</html>
|
|
|
|
|
|
|
|
|
|