Shoimport nltk
from nltk.chat.util import Chat, reflections
import speech_recognition as sr
# Define patterns and responses for the chatbot
patterns = [
    (r'hi|hello|hey', ['Hello!', 'Hi there!', 'Hey!']),
    (r'how are you', ['I am good, thank you!', 'I am doing well, how about you?']),
    # Add more patterns and responses based on your requirements
]
# Create the chatbot
chatbot = Chat(patterns, reflections)
# Function to handle speech recognition
def recognize_speech():
    recognizer = sr.Recognizer()
    with sr.Microphone() as source:
        print("Say something:")
        audio = recognizer.listen(source)
        try:
            text = recognizer.recognize_google(audio)
            return text.lower()
        except sr.UnknownValueError:
            return "Sorry, I couldn't understand that."
        except sr.RequestError as e:
            return f"Could not request results from Google Speech Recognition service; {e}"
# Main conversation loop
print("OmniBot: Hello! I'm OmniBot. How can I help you today?")
while True:
    user_input = input("You: ")
    
    # Allow user to exit the conversation
    if user_input.lower() in ['exit', 'bye', 'quit']:
        print("OmniBot: Goodbye! Have a great day.")
        break
    
    # Use speech recognition if the user input starts with 'listen'
    if user_input.lower().startswith('listen'):
        user_input = recognize_speech()
        print(f"You (Speech): {user_input}")
    # Get response from the chatbot based on user input
    response = chatbot.respond(user_input)
    print(f"OmniBot: {response}")
wcase innovation and commitment to user experience with cutting-edge technology, positioning your brand at the forefront of digital advancement.