User:Sudhiksha v/text2voicetoggle.js

//Text to Voice TOGGLE FEATURE (PRESS ENTER)

// Create container for toggle button var toggleContainer = document.createElement('div'); toggleContainer.id = 'toggleContainer'; toggleContainer.style.position = 'fixed'; toggleContainer.style.bottom = '55px'; toggleContainer.style.right = '15px'; toggleContainer.style.zIndex = '9999';

// Create toggle button (as an image) var toggleButton = document.createElement('img'); toggleButton.src = 'https://upload.wikimedia.org/wikipedia/commons/thumb/2/21/Speaker_Icon.svg/800px-Speaker_Icon.svg.png'; toggleButton.alt = 'Toggle Speech'; toggleButton.id = 'toggleSpeech'; toggleButton.style.width = '20px'; // Set width toggleButton.style.height = '20px'; // Set height toggleButton.style.borderRadius = '25%'; // Make it circular toggleButton.style.backgroundColor = 'transparent'; // Transparent initially toggleButton.style.cursor = 'pointer'; toggleButton.style.boxShadow = '0px 4px 8px rgba(0, 0, 0, 0.1)'; // Shadow effect toggleButton.style.transition = 'background-color 0.3s'; // Smooth transition

// Add event listener for button hover toggleButton.addEventListener('mouseenter', function {   toggleButton.style.backgroundColor = '#cfcfcf'; // Change background color on hover });

// Add event listener for button mouseout toggleButton.addEventListener('mouseleave', function {   toggleButton.style.backgroundColor = 'transparent'; // Reset background color on mouseout });

// Append toggle button to toggle container toggleContainer.appendChild(toggleButton);

// Append toggle container to the document body document.body.appendChild(toggleContainer);

var enterPressed = false; var timer;

// Function to handle key press event function handleKeyPress(event) { if (event.keyCode === 13) { // Check if Enter key is pressed if (!enterPressed) { enterPressed = true; timer = setTimeout(function {               enterPressed = false; // Reset after a delay if no second Enter key press            }, 300); // Adjust the delay as needed } else { clearTimeout(timer); toggleSpeech; // Activate the action when Enter is pressed twice enterPressed = false; // Reset after action is triggered }   } }

// Add event listener for key press document.addEventListener('keypress', handleKeyPress);

// Function to toggle speech synthesis function toggleSpeech { if (window.speechSynthesis.speaking) { window.speechSynthesis.cancel; } else { var textToSpeak = document.body.innerText; var utterance = new SpeechSynthesisUtterance(textToSpeak); window.speechSynthesis.speak(utterance); } }