-
Notifications
You must be signed in to change notification settings - Fork 519
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.'); | ||
} | ||
} |