diff --git a/Voice Assistant for Movies/voiceassistant.py b/Voice Assistant for Movies/voiceassistant.py new file mode 100644 index 0000000..b860628 --- /dev/null +++ b/Voice Assistant for Movies/voiceassistant.py @@ -0,0 +1,100 @@ +# importing all required libraries +import imdb +import pyttsx3 +import speech_recognition as sr +import datetime + + +# Function for speaking +def speak(text): + engine = pyttsx3.init() + voices = engine.getProperty('voices') + engine.setProperty('voice', voices[1].id) + rate = engine.getProperty('rate') + + engine.setProperty('rate', rate-20) + + engine.say(text) + engine.runAndWait() + + +# calling the speak() function +speak("Say the movie name") + + +# Function to get input in the audio format +def get_audio(): + r = sr.Recognizer() + with sr.Microphone() as source: + r.pause_threshold = 1 + r.adjust_for_ambient_noise(source, duration=1) + audio = r.listen(source) + said = "" + + try: + + # will recognize the input + said = r.recognize_google(audio) + print(said) + + except: + speak("Didn't get that") + # will return the input in lowercase + return said.lower() + + +# Function for searching movie +def search_movie(): + + # gathering information from IMDb + moviesdb = imdb.IMDb() + + # search for title + text = get_audio() + + # passing input for searching movie + movies = moviesdb.search_movie(text) + + speak("Searching for " + text) + if len(movies) == 0: + speak("No result found") + else: + + speak("I found these:") + + for movie in movies: + + title = movie['title'] + year = movie['year'] + # speaking title with releasing year + speak(f'{title}-{year}') + + info = movie.getID() + movie = moviesdb.get_movie(info) + + title = movie['title'] + year = movie['year'] + rating = movie['rating'] + plot = movie['plot outline'] + + # the below if-else is for past and future release + if year < int(datetime.datetime.now().strftime("%Y")): + speak( + f'{title}was released in {year} has IMDB rating of {rating}.\ + The plot summary of movie is{plot}') + print( + f'{title}was released in {year} has IMDB rating of {rating}.\ + The plot summary of movie is{plot}') + break + + else: + speak( + f'{title}will release in {year} has IMDB rating of {rating}.\ + The plot summary of movie is{plot}') + print( + f'{title}will release in {year} has IMDB rating of {rating}.\ + The plot summary of movie is{plot}') + break + + +search_movie() diff --git a/rockpaperscissor/rockpaperscissor.py b/rockpaperscissor/rockpaperscissor.py new file mode 100644 index 0000000..cd6e979 --- /dev/null +++ b/rockpaperscissor/rockpaperscissor.py @@ -0,0 +1,29 @@ +import random + +while True: + user_action = input("Enter a choice (rock, paper, scissors): ") + possible_actions = ["rock", "paper", "scissors"] + computer_action = random.choice(possible_actions) + print(f"\nYou chose {user_action}, computer chose {computer_action}.\n") + + if user_action == computer_action: + print(f"Both players selected {user_action}. It's a tie!") + elif user_action == "rock": + if computer_action == "scissors": + print("Rock smashes scissors! You win!") + else: + print("Paper covers rock! You lose.") + elif user_action == "paper": + if computer_action == "rock": + print("Paper covers rock! You win!") + else: + print("Scissors cuts paper! You lose.") + elif user_action == "scissors": + if computer_action == "paper": + print("Scissors cuts paper! You win!") + else: + print("Rock smashes scissors! You lose.") + + play_again = input("Play again? (y/n): ") + if play_again.lower() != "y": + break \ No newline at end of file