Python script to login my computer with my own voice recognition

To implement voice recognition for logging into your PC or Computer using Python, you can use libraries like SpeechRecognition and pyttsx3 for speech-to-text and text-to-speech conversion respectively. Follow these simple steps and get to know how you could do it:



1: Install Required Libraries:

pip install SpeechRecognition pyttsx3

2: Write Python Script

import speech_recognition as sr import pyttsx3 import os # Initialize speech recognizer and text-to-speech engine recognizer = sr.Recognizer() engine = pyttsx3.init() def speak(text): engine.say(text) engine.runAndWait() def login(): # Capture audio input with sr.Microphone() as source: speak("Please say your username") print("Please say your username:") audio = recognizer.listen(source) try: # Recognize username username = recognizer.recognize_google(audio) speak("Username recognized as " + username) print("Username recognized as:", username) # Ask for password speak("Please say your password") print("Please say your password:") audio = recognizer.listen(source) # Recognize password password = recognizer.recognize_google(audio) speak("Password recognized") # Check if username and password are correct if username == "your_username" and password == "your_password": speak("Login successful") print("Login successful") # Add code to unlock your PC here else: speak("Login failed. Please try again.") print("Login failed. Please try again.") except sr.UnknownValueError: speak("Sorry, I couldn't understand that.") print("Sorry, I couldn't understand that.") except sr.RequestError: speak("Sorry, I couldn't reach the Google API.") print("Sorry, I couldn't reach the Google API.") if __name__ == "__main__": login()

  1. **Replace "your_username" and "your_password" with your actual username and password respectively.

  2. Security Considerations:

    • Make sure to keep your password secure within the script.
    • Consider adding additional security measures like multi-factor authentication for better security.
  3. Run the Script: Run the Python script and follow the instructions to log in using your voice.




Comments

Popular posts from this blog

Fetching Data from an API in React Native with Expo

State Management in React Native with Expo: A Beginner’s Guide

How to Set Up React Native with Expo 🚀