Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented CAPTCHA Speech Recognition Enhancement to Distinguish Between Capital and Small Letters #37

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,34 +89,45 @@ function createCaptcha() {
return code;
}

// For speaking the captcha
// For speaking the captcha
function speakCaptcha() {
let text = "";
for (let i = 0; i <= code.textContent.length; i++) {
text += code.textContent.charAt(i) + " ";
for (let i = 0; i < code.textContent.length; i++) {
let char = code.textContent.charAt(i);
if (char >= 'A' && char <= 'Z') {
text += "Capital " + char + " "; // Add "Capital" before uppercase letters
} else if (char >= 'a' && char <= 'z') {
text += "Small " + char + " "; // Add "Lowercase" before lowercase letters
} else {
text += char + " "; // For numbers or special characters
}
}
return text;
}

//TEXT TO SPEECH RECOGNITION
submitbtn.addEventListener("click", () => {
validcaptcha(); // Call the validcaptcha function to check the CAPTCHA validity
});

// to check whether entered captcha is valid
function validcaptcha() {
responsiveVoice.setDefaultVoice("US English Female");
responsiveVoice.setDefaultRate(0.75);
let val = input.value;
if (val == "") {
// alert('Please Enter the Text.');
responsiveVoice.speak("Please Enter the Captcha");
} else if (val == code.textContent) {
// alert('Valid Code');
responsiveVoice.speak("Valid Captcha");
confirm("Captcha is correct! Do you want to proceed?");
} else {
// alert('Invalid Code');
responsiveVoice.speak("Invalid Captcha");
confirm("Captcha is incorrect, please try again.");
}
});
}

// For reading the CAPTCHA aloud with uppercase/lowercase distinctions
readTextBtn.addEventListener("click", () => {
let tex = speakCaptcha();
responsiveVoice.setDefaultVoice("US English Female");
Expand All @@ -125,6 +136,14 @@ readTextBtn.addEventListener("click", () => {
responsiveVoice.speak("Please repeat the captcha");
});

// for keydown===enter case
input.addEventListener('keydown', function(event){
if (event.key === 'Enter') {
validcaptcha();
}
});


// Add an event listener to the 'changeTextBtn' button for the 'click' event
changeTextBtn.addEventListener("click", () => {
// Update the text content of the 'code' element with a new captcha generated by 'createCaptcha'
Expand All @@ -133,3 +152,5 @@ changeTextBtn.addEventListener("click", () => {
input.value = "";
});



74 changes: 41 additions & 33 deletions js/speechrecog.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,60 @@
var speechRecognition = window.webkitSpeechRecognition
var speechRecognition = window.webkitSpeechRecognition;

var recogniton = new speechRecognition();
var recogniton = new speechRecognition();

var textbox =$("#textbox")
var textbox = $("#textbox");

var instructions = $("#instructions")
var instructions = $("#instructions");

var content =''
var content = '';

recogniton.continuous = true
recogniton.continuous = true;

// recognition is started

recogniton.onstart = function()
{
instructions.text("Voice recognition is on")
//responsiveVoice.speak("Voice recognition is on");
recogniton.onstart = function () {
instructions.text("Voice recognition is on");
// responsiveVoice.speak("Voice recognition is on");
}

recogniton.onspeechend = function()
{
instructions.text("No activity")
recogniton.onspeechend = function () {
instructions.text("No activity");
}
recogniton.onerror = function()
{
instructions.text("Try Again")
}
recogniton.onresult = function(event){
var current = event.resultIndex;

var transcript = event.results[current][0].transcript

content += transcript
recogniton.onerror = function () {
instructions.text("Try Again");
}

content = content.toLowerCase();
recogniton.onresult = function (event) {
var current = event.resultIndex;

textbox.val(content)
var transcript = event.results[current][0].transcript;
content += transcript;

// Process each character and specify if it's uppercase or lowercase
var processedContent = '';
for (var i = 0; i < transcript.length; i++) {
var char = transcript[i];

// Check if the character is an alphabet letter
if (char.match(/[a-zA-Z]/)) {
if (char === char.toUpperCase()) {
processedContent += `Capital ${char} `;
} else {
processedContent += `Small ${char} `;
}
} else {
// If it's not a letter, just append it
processedContent += char;
}
}

// Update the content to be displayed in the textbox
textbox.val(processedContent);
}


$("#start-btn").click(function(event)
{
if(content.length)
{
content += ''
$("#start-btn").click(function (event) {
if (content.length) {
content += '';
}
recogniton.start()
})
recogniton.start();
});