File size: 1,372 Bytes
abc40d6
 
 
8494a3e
abc40d6
 
8494a3e
abc40d6
8494a3e
abc40d6
 
8c30780
8494a3e
8c30780
8494a3e
 
 
 
 
 
 
 
 
 
 
 
 
abc40d6
8494a3e
 
 
 
 
abc40d6
 
8494a3e
8c30780
 
abc40d6
 
8494a3e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<!DOCTYPE html>
<html>
<head>
    <title>Reconocimiento de Voz con WebRTC</title>
</head>
<body>
    <button id="startRecording">Iniciar Grabación</button>
    <div id="output"></div>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.1/socket.io.js"></script>
    <script>
        const socket = io.connect('http://' + document.domain + ':' + location.port);
        const startRecordingButton = document.getElementById('startRecording');
        const outputDiv = document.getElementById('output');
        let mediaRecorder;
        let audioChunks = [];
        let recognition;

        startRecordingButton.addEventListener('click', () => {
            if (!recognition) {
                recognition = new webkitSpeechRecognition();
                recognition.lang = 'es-ES';
                recognition.onresult = function (event) {
                    const result = event.results[0][0].transcript;
                    socket.emit('audio_data', result);
                };
            }

            try {
                recognition.start();
            } catch (error) {
                console.error('Error al iniciar el reconocimiento de voz:', error);
            }
        });

        socket.on('transcription', function (data) {
            outputDiv.innerHTML = `Texto reconocido: ${data}`;
        });
    </script>
</body>
</html>