Felismert szöveg:
recognition.onresult = function(event) { const transcript = event.results[0][0].transcript; outputDiv.textContent = transcript; // Itt tudjuk visszaküldeni az eredményt a VB alkalmazásnak // Például: window.external.ProcessVoiceCommand(transcript); // Vagy beírjuk egy rejtett input mezőbe, amit a VB lekérdezhet if (window.external && typeof window.external.ProcessVoiceCommand === 'function') { window.external.ProcessVoiceCommand(transcript); } else { console.warn("Visual Basic callback function 'ProcessVoiceCommand' not found."); } };
recognition.onerror = function(event) { console.error('Speech recognition error:', event.error); outputDiv.textContent = `Hiba: ${event.error}`; startButton.textContent = 'Indítsa a mikrofont!'; startButton.disabled = false; };
recognition.onend = function() { startButton.textContent = 'Indítsa a mikrofont!'; startButton.disabled = false; if (!outputDiv.textContent.startsWith('Hiba:')) { outputDiv.textContent = 'Beszéd vége. Várja a parancsot...'; } };
startButton.addEventListener('click', () => { if (startButton.textContent.includes('Indítsa')) { recognition.start(); } else { recognition.stop(); } });
} else { outputDiv.textContent = 'Sajnáljuk, a böngészője nem támogatja a Web Speech API-t.'; startButton.disabled = true; }