Skip to content

Commit

Permalink
AddedVoiceSearch
Browse files Browse the repository at this point in the history
  • Loading branch information
ashis2004 committed Jun 26, 2024
1 parent b1a5c34 commit 3825a08
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
15 changes: 15 additions & 0 deletions VoiceSearch/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flipkart Voice Search</title>
</head>
<body>
<h1>Welcome to Flipkart</h1>
<input type="text" id="searchInput" placeholder="Type or speak your search">
<button onclick="startVoiceSearch()">Voice Search</button>

<script src="voice-search.js"></script>
</body>
</html>
29 changes: 29 additions & 0 deletions VoiceSearch/voice-search.js
Original file line number Diff line number Diff line change
@@ -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.');
}
}

0 comments on commit 3825a08

Please sign in to comment.