From 3825a089c2116504eb348abeb763e10625f07678 Mon Sep 17 00:00:00 2001 From: ashis2004 Date: Wed, 26 Jun 2024 14:40:16 +0530 Subject: [PATCH] AddedVoiceSearch --- VoiceSearch/index.html | 15 +++++++++++++++ VoiceSearch/voice-search.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 VoiceSearch/index.html create mode 100644 VoiceSearch/voice-search.js diff --git a/VoiceSearch/index.html b/VoiceSearch/index.html new file mode 100644 index 00000000..bcd55ff3 --- /dev/null +++ b/VoiceSearch/index.html @@ -0,0 +1,15 @@ + + + + + + Flipkart Voice Search + + +

Welcome to Flipkart

+ + + + + + diff --git a/VoiceSearch/voice-search.js b/VoiceSearch/voice-search.js new file mode 100644 index 00000000..6ffd79c3 --- /dev/null +++ b/VoiceSearch/voice-search.js @@ -0,0 +1,29 @@ +function startVoiceSearch() { + if ('webkitSpeechRecognition' in window) { + var recognition = new webkitSpeechRecognition(); + recognition.lang = 'en-US'; + + recognition.onstart = function() { + console.log('Voice search started...'); + }; + + recognition.onresult = function(event) { + var transcript = event.results[0][0].transcript; + document.getElementById('searchInput').value = transcript; + console.log('Voice search result:', transcript); + // Here you can trigger search based on the transcript + }; + + recognition.onerror = function(event) { + console.error('Voice search error:', event.error); + }; + + recognition.onend = function() { + console.log('Voice search ended.'); + }; + + recognition.start(); + } else { + alert('Voice search not supported in your browser.'); + } +}