Voice Assistant for Movies using Python
In this article, we will see how a voice assistant can be made for searching for movies or films. After giving input as movie name in audio format and it will give the information about that movie in audio format as well.
As we know the greatest searching website for movies is IMDb. IMDb is an online database of information related to films, television programs, home videos, video games, and streaming content online including cast, production crew, and personal biographies, plot summaries, trivia, ratings, and fan, and critical reviews.
- IMDbPY: It is a Python package useful to retrieve and manage the data of the IMDb movie database about movies, people, characters, and companies. It can be installed using the below command:
pip install IMDbPY
- pyttsx3: It is a text-to-speech conversion library in Python. Unlike alternative libraries, it works offline and is compatible with both Python 2 and 3. It can be installed using the below command:
pip install pyttsx3
- SpeechRecognition: Library for performing speech recognition, with support for several engines and APIs, online and offline. It can be installed using the below command:
pip install SpeechRecognition
- Datetime: Encapsulation of date/time values. It can be installed using the below command:
pip install DateTime
- Import required modules.
- Create the below functions:
- speak( ): This function will help our assistant to speak up.
- get_audio( ): This function will help the assistant to get input from the user.
- get_movies( ): This function will help the assistant to search for the movie that is given as input.
- Create a new function search_movie( ) to search a movie by using the above function calls.
- Call the above-created function.
Below is the Implementation.
The above code will speak the information about the film as the user gave the input and also print about it.
Parasitewas released in 2019 has IMDB rating of 8.6.
The plot summary of movie isThe Kims – mother and father Chung-sook and Ki-taek, and their young adult offspring, son Ki-woo and daughter Ki-jung – are a poor family living in a shabby and cramped half basement apartment in a busy lower working class commercial district of Seoul.
Without even knowing it, they, especially Mr. and Mrs. Kim, literally smell of poverty. Often as a collective, they perpetrate minor scams to get by, and even when they have jobs, they do the minimum work required. Ki-woo is the one who has dreams of getting out of poverty by one day going to university.
Despite not having that university education, Ki-woo is chosen by his university student friend Min, who is leaving to go to school, to take over his tutoring job to Park Da-hye, who Min plans to date once he returns to Seoul and she herself is in university.
The Parks are a wealthy family who for four years have lived in their modernistic house designed by and the former residence of famed architect Namgoong. While Mr. and Mrs. Park are all about status, Mrs. Park has a flighty, simpleminded mentality and temperament,
which Min tells Ki-woo to feel comfortable in lying to her about his education to get the job. In getting the job, Ki-woo further learns that Mrs. Park is looking for an art therapist for the Parks’ adolescent son, Da-song, Ki-woo quickly recommending his professional art therapist friend “Jessica”,
really Ki-jung who he knows can pull off the scam in being the easiest liar of the four Kims. In Ki-woo also falling for Da-hye, he begins to envision himself in that house, and thus the Kims as a collective start a plan for all the Kims, like Ki-jung using assumed names, to replace existing servants in the Parks’ employ in orchestrating reasons for them to be fired.
The most difficult to get rid of may be Moon-gwang, the Parks’ housekeeper who literally came with the house – she Namgoong’s housekeeper when he lived there – and thus knows all the little nooks and crannies of it better than the Parks themselves. The question then becomes how far the Kims can take this scam in their quest to become their version of the Parks.
- The code first creates a new instance of the sr.Recognizer class.
- This class allows the programmer to access all of the features of the Google Speech Recognition engine.
- Next, the code sets up some basic parameters for the microphone.
- The first parameter is called pause_threshold and it tells the recognizer how much noise to ignore before pausing to listen for speech.
- The second parameter is called adjust_for_ambient_noise and it helps to compensate for background noise in the room.
- The next step is to get input from the microphone into an audio object.
- The code uses the sr.listen method to capture any sound that comes out of the microphone.
- Once a sound has been captured, it can be stored in a variable named audio .
- The next line of code will recognize any spoken words that are captured by the microphone using Google’s speech recognition engine.
- If everything goes according to plan, then said will contain a string containing recognized text from Google’s speech recognition engine.
- If something goes wrong during this process, then speak() will be called with an error message as its only argument ( Didnt get that ).
- The code will open a Recognizer object and set the pause_threshold to 1.
- This will allow the user to hear any audio they are inputting in, but it won’t stop until they hit the pause_threshold.
- Next, the code will adjust for ambient noise and listen for input from the microphone.
- Once it has detected an audio signal, it will print out what was recognized.
- If there is an error, the code will speak an error message instead.
Please Login to comment...