Search This Blog
Exploring the Wonders of Science, Technology, and Human Potential
Featured
- Get link
- X
- Other Apps
Python Code for Basic Assistant
This Python script is a voice-controlled personal assistant that performs various tasks based on voice commands. It utilizes the `speech_recognition` library for speech recognition, `pyttsx3` for text-to-speech functionality, and other modules for performing actions like opening programs, searching Google, shutting down the computer, checking the battery percentage, searching YouTube, and playing music.
Here's a breakdown of the key functions:
1. `speak(text)` function:
- Uses the `pyttsx3` library to convert text into speech.
- Initializes the text-to-speech engine, speaks the given text, and waits for the speech to finish.
2. `open_program(program_name)` function:
- Uses the `subprocess` module to open a specified program.
- Finds the path of the program using `shutil.which`.
- Uses `subprocess.Popen` to open the program in a new process.
3. `search_google(query)` function:
- Opens the default web browser to perform a Google search based on the given query.
4. `shutdown_computer()` function:
- Initiates the shutdown process for the computer using the `subprocess.run` method.
5. `show_battery_percentage()` function:
- Uses the `psutil` library to get information about the battery status.
- Retrieves the battery percentage and speaks it.
6. `search_youtube(query)` function:
- Opens the default web browser to perform a YouTube search based on the given query.
7. `play_music(query)` function:
- Opens the default web browser to search for music on YouTube based on the given query.
8. `main()` function:
- Initializes a speech recognizer from `speech_recognition`.
- Captures audio from the microphone and adjusts for ambient noise.
- Uses Google's speech recognition service to convert the audio into text.
- Parses the recognized text to identify commands and performs corresponding actions.
- Handles unrecognized commands and errors gracefully.
9. Main Block (`__name__ == "__main__"`):
- Calls the `main()` function to start the voice-controlled personal assistant.
- Get link
- X
- Other Apps
Popular Posts
What If India Loses this mindset of Reusing Things?
- Get link
- X
- Other Apps
Polar Bear is Suffering to Find Land Here is Why?
- Get link
- X
- Other Apps
Smarter move through technology revolution
- Get link
- X
- Other Apps
The Role of UX Design in Evolving Technology
- Get link
- X
- Other Apps
Comments
Post a Comment