generated from cepdnaclk/eYY-3yp-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b5617d
commit 4dec006
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import pyttsx3 | ||
import time | ||
|
||
# Initialize Text-to-Speech Engine | ||
engine = pyttsx3.init() | ||
|
||
def speak(text): | ||
"""Speak the given text.""" | ||
engine.say(text) | ||
engine.runAndWait() | ||
|
||
def respond_to_emotion(emotion): | ||
"""Respond based on the detected emotion.""" | ||
if emotion.lower() == "happy": | ||
print("\n💖Stay happy!😊") | ||
speak("You look so happy! What made your day so great?") | ||
|
||
elif emotion.lower() == "sad": | ||
print("\n💙I'm here for you❤️") | ||
speak("I’m here to listen. Do you want to talk about what’s making you sad?") | ||
|
||
elif emotion.lower() == "angry": | ||
print("\n❤️Take a deep breath!🤗") | ||
speak("Don't let anger take over. I'm here for you. Want to talk about it?") | ||
|
||
else: | ||
print("\n sorry") | ||
speak("I didn't understand whats your feeling.") | ||
|
||
# Main Loop | ||
while True: | ||
emotion = input("\nEnter an emotion (happy, sad, angry) or 'exit' to quit: ").strip() | ||
|
||
if emotion.lower() == "exit": | ||
print("\n👋 Goodbye! Take care!") | ||
speak("Goodbye! Take care!") | ||
break | ||
|
||
respond_to_emotion(emotion) | ||
time.sleep(1) # Small delay before next input |