User:Sudhiksha v/talktowikie.js

window.SpeechRecognition = window.webkitSpeechRecognition || window.SpeechRecognition;

if (!window.SpeechRecognition) { console.error("Your browser does not support speech recognition."); return; }

let finalTranscript = ''; let recognition = new window.SpeechRecognition;

recognition.interimResults = true; recognition.maxAlternatives = 10; recognition.continuous = true;

recognition.onresult = (event) => { let interimTranscript = ''; for (let i = event.resultIndex, len = event.results.length; i < len; i++) { let transcript = event.results[i][0].transcript; if (event.results[i].isFinal) { finalTranscript += transcript;

// Perform search on Wikipedia let searchTerm = finalTranscript.trim; if (searchTerm) { window.location.href = `https://en.wikipedia.org/wiki/${searchTerm}`; }

recognition.stop; // Stop listening after final transcript } else { interimTranscript += transcript; } }

// Update displayed transcript (optional) // document.querySelector('body').innerHTML = finalTranscript + '' + interimTranscript + ''; };

recognition.start;

// Check for Text-to-Speech support if (!window.speechSynthesis) { console.error("Your browser does not support text-to-speech."); return; }

// Function for future Text-to-Speech implementation (replace with your logic) function textToSpeech { console.log("Text-to-Speech functionality not yet implemented."); }