Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions Voice Assistant for Movies/voiceassistant.py
Original file line number Diff line number Diff line change
@@ -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()
29 changes: 29 additions & 0 deletions rockpaperscissor/rockpaperscissor.py
Original file line number Diff line number Diff line change
@@ -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