File size: 1,820 Bytes
c8833d3
 
 
f4fce69
 
c8833d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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!")