![]() ![]() You should have installed this library if you followed the steps in the README.MD page on Cali's Github repository page. To do this, we import and use the ibm_watson Python library. Speaker.py file uses IBM Watson Text to speech to synthesize text to speech. Once we've done that, we simply returned a new descriptive string of the city's current weather data. They extract the weather temperature and weather data description from the response object respectively. And that is what the _extract_temp and _extract_desc does. We can simply use indexing(list and dict indexing) to retrieve the part of the response we care about. json() reads the response content as JSON and transforms it into a Python List and Dictionary object depending on the response content. The function sends out a GET request using requests library and decodes the response of the request as a JSON using. The get_weather_data function receives city_name as argument and uses the city name to fetch weather data. format ( city_name, temp, description ) def _extract_temp ( self, weatherdata ): temp = weatherdata return temp def _extract_desc ( self, weatherdata ): return weatherdata Import requests import json class WeatherService ( object ): API_URL = "". If you don't know how HTTP requests and Python requests library works. We will send the APP ID that we got from registering at and the city name as part of the request parameter. This file uses the Python requests library to send GET request to. Weather.py file uses OpenWeatherMap API to fetch the current weather data of a city. To learn more about datetime in Python, check out this link Weather.py The "%M" returns the counting minute for the current hour and the "%p" returns AM or PM depending on the current time. The "%I" returns the hours passed since the beginning of the day in a 12-hour clock format. We simply used strftime("%I:%M %p") to create a formatted string from the datetime object. strftime ( "%I:%M %p" ) output = "Your current local time is " + current_time return outputĭatetime.now() returns a new datetime object for the current system date and time. Pass def get_local_time ( self ): current_time = datetime. ![]() #As an exercise, you can implement this function. If you're not familiar with webbrowser in Python, visit this link to learn more about how it works.įrom datetime import datetime class TimeService ( object ): def _init_ ( self ): pass def get_time ( self, city_name ): #Todo implement to fetch local time in any city, using city name It uses Python's webbrowser module to do that. Util.py file is the simplest of all Cali source code files, it contains the code we will use to open a new browser tab. In this section, I will walk you through how Cali's entire source code works. CODING UP CALIĬali's source code is pretty straight forward and isn't that difficult to understand. To follow along with this blog post, go ahead and clone Cali from Github at or download the code-load using this link: įor this tutorial, we will be using the online-tts-only branch on Github.Īfter you have downloaded or cloned Cali from Github, you should follow the steps in README.MD file to download and install Cali's dependencies. Main.py: The main program file, receives input using Google Speech Recognition and maps the received text to an action to take. Speaker.py: Uses IBM Watson Text to Speech library to synthesize text to speech, save it as an audio file and play it using MPG321 command-line player. Weather.py: Uses OpenWeatherMap API to fetch weather data for any city. Timeservice.py: Checks and return local computer time and local time in other cities. Util.py: Uses Python's webbrowser module to open a new browser tab. ![]() (This isn't a lot, but you can build on top of Cali to add more features, I urge you to do so when you're done with this blog post)Ĭali is made up of the following source code files: In this article, we will be building a simple virtual assistant named Cali.Ĭali can check the weather, tell the local time, open up a twitter profile, and search for youtube videos. This article assumes you have a basic understanding of the following prerequisites: In this article, I will be walking you through how to create a simple virtual assistant using Google Speech Recognition and IBM Watson Text to Speech in Python. They help us check the weather, make phone calls, control the thermostat, door locks, and other smart home devices e.t.c Virtual assistants are everywhere from Alexa, to Google Home, to Apple Siri. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |