
- Google assistant play music from my library install#
- Google assistant play music from my library code#
- Google assistant play music from my library free#
To open any website, firstly we need to import a module called as webbrowser. If Wikipedia is found in the user’s search query, then five sentences (which you can change by changing the number of sentences from 5 to any number you want) from the summary of the Wikipedia page will be converted to speech with the help of the speak function. In the above code, we have used an if statement to check whether Wikipedia is in the search query of the user or not. if _name_ = "_main_": wishMe() while True: query = takeCommand().lower() #Converting user query into lower case # Logic for executing tasks based on query if 'wikipedia' in query: #if wikipedia found in the query then this block will be executed speak('Searching Wikipedia.') query = query.replace("wikipedia", "") results = wikipedia.summary(query, sentences=5) speak("According to Wikipedia") print(results) speak(results)

Google assistant play music from my library install#
To do Wikipedia searches, we need to install and import the wikipedia module into our program.Ĭommand for installing wikipedia module is as follows: pip install wikipediaĪfter successfully installing wikipedia module, import the wikipedia module into the program by writing an import statement. Task 1: To search something on Wikipedia: Now we can finally start defining our tasks and get desired input from them. voice assistant will also be able to return a string output by taking input from us through our microphone.īut, before defining the takeCommand() function, we need to install a module called speechRecognition, and the command is as follows: pip install speechRecognition With the help of our takeCommand() function, our A.I.
Google assistant play music from my library code#
So, let’s begin to code our takeCommand() function. The next most important thing for our voice assistant is, it should be able to take command with the help of microphone of our system. Please tell me how may I help you') Defining takeCommand() function: def wishMe(): hour = int(().hour) if hour>=0 and hour=12 and hour<18: speak("Good Afternoon!") else: speak("Good Evening!") speak('Hello Sir, I am Friday, your Artificial intelligence assistant. Now, we will use this hour value inside an if-else loop. Here, we have stored the integer value of the current hour or time into a variable named hour. Now, let’s start coding our wishme() function: def wishme(): hour = int(().hour) Import this module to your program, by using the following command : import datetime To provide the current time to our assistant, we need to import a module called datetime. Now, we are going to code a wishme() function, due to which our voice assistant will wish or greet us according to the time on the computer. Congratulations! With this, our voice assistant has its own voice, and it is ready to speak ! Coding the wishme() function: Whatever you will write inside this speak() function will be completely converted into speech. I have given my voice assistant a name - Friday 😁 if _name_="_main_" : speak('Hello Sir, I am Friday, your Artificial intelligence assistant. Now, we will create a main() function, and inside this main() function, we will define our customized speak function. Writing our own speak() function: def speak(audio): engine.say(audio) nAndWait() #Without this command, speech will not be audible to us. Voice id helps us to select different voices.


It usually helps in synthesis and recognition of voice.Microsoft Speech API ( SAPI5) is the technology for voice recognition and synthesis, provided by Microsoft.Usage: import pyttsx3 engine = pyttsx3.init('sapi5') voices = engine.getProperty('voices') #gets you the details of the current voice tProperty('voice', voice.id) # 0-male voice, 1-female voice And, it also works offline, and it is also compatible with Python 2 as well Python 3.Īfter successfully installing pyttsx3, import this module in your program.It is a Python library which will help us to convert text format into speech format.So, we are going to install a module named pyttsx3. Now, we need audio in order to achieve proper communication between user and the assistant. To make our bot speak, we will code a speak() function which takes audio as an input, and pronounces it, as an output.ĭef speak(audio): pass #for now, we will write the conditions later.
Google assistant play music from my library free#
I used Pycharm to code this up, but please feel free to use any other IDE you are comfortable with.įirstly, we will import/install the necessary libraries : Now let’s get into the actual building of our voice assistant 😎Īnd also yes, don’t forget to decide a name for your voice assistant beforehand :P Setting up the environment to code:
