Here's a sample code for a personal assistant program:
This program uses the speech_recognition library to listen for user input through the microphone, the pyttsx3 library for text-to-speech and wikipedia library for information from Wikipedia.
The program starts by initializing the recognizer, and then defines three main functions: speak(), get_time(), and get_weather(). The speak() function uses the pyttsx3 library to convert text to speech, the get_time() function gets the current time and speaks it out loud and get_weather() function uses OpenWeatherMap API to get the current weather of a specific location and speaks it out loud.The get_information() function uses the wikipedia library to search for information on a specific topic and speaks it out loud.
The main loop of the program uses the sr.Microphone() class to listen for user input, and then uses the recognize_google() method of the recognizer to recognize the speech. Depending on the recognized text, the program calls the appropriate function to perform the task.
No comments:
Post a Comment