import speech_recognition as sr import pyttsx3 import json import sounddevice as sd import numpy as np # Load user credentials (Replace with database if needed) USER_CREDENTIALS = { "john_doe": "hello123", "alice_smith": "welcome456" } # Initialize Text-to-Speech Engine engine = pyttsx3.init() engine.setProperty('rate', 150) def speak(text): """Convert text to speech.""" engine.say(text) engine.runAndWait() def recognize_speech(): """Capture and recognize speech input.""" recognizer = sr.Recognizer() with sr.Microphone() as source: speak("Please say your username and password.") print("Listening...") recognizer.adjust_for_ambient_noise(source) try: audio = recognizer.listen(source) text = recognizer.recognize_google(audio) print(f"Recognized: {text}") return text.lower() except sr.UnknownValueError: speak("Sorry, I didn't catch that. Please try again.") return None except sr.RequestError: speak("Speech service is unavailable. Please check your internet connection.") return None def authenticate(): """Authenticate user based on voice input.""" speech_text = recognize_speech() if not speech_text: return False # Extract username and password for username, password in USER_CREDENTIALS.items(): if username in speech_text and password in speech_text: speak(f"Welcome, {username}. You are now logged in.") return True speak("Authentication failed. Please try again.") return False if __name__ == "__main__": speak("Welcome to the voice login system.") if authenticate(): print("Login Successful!") else: print("Login Failed!")