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()
**Replace "your_username"
and "your_password"
with your actual username and password respectively.
Security Considerations:
- Make sure to keep your password secure within the script.
- Consider adding additional security measures like multi-factor authentication for better security.
Run the Script:
Run the Python script and follow the instructions to log in using your voice.
Comments
Post a Comment