Spaces:
Sleeping
Sleeping
<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('https://' + document.domain + ':' + location.port, {secure: true}); | |
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> |