Skip to content

Commit 06fcb92

Browse files
authored
Merge pull request #158 from HarshallSonawane/main
Added voice assistant project under Directory V
2 parents 45cc021 + 216748f commit 06fcb92

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

V/voice-assistant/Readme.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Voice Assistant in Python
2+
3+
## Description
4+
5+
This is a Python-based voice assistant that can perform various tasks, such as playing songs on YouTube, telling system time and date, and providing information about a topic from Wikipedia. The voice assistant uses popular Python packages like `speech_recognition`, `pyttsx3`, and `wikipedia`.
6+
7+
## Features
8+
9+
- Speech recognition for voice commands
10+
- Text-to-speech (TTS) capabilities for providing responses
11+
- Integration with YouTube for playing songs
12+
- Wikipedia integration for information retrieval
13+
- System time and date retrieval
14+
15+
## Dependencies
16+
17+
- Python 3.6+
18+
- Required Python packages:
19+
- `speech_recognition` for voice recognition
20+
- `pyttsx3` for text-to-speech
21+
- Other packages for specific functionalities (if applicable)
22+
23+
## Installation
24+
25+
1. Clone the repository to your local machine:
26+
27+
```bash
28+
git clone https://github.com/Techiral/A-Z-Python-Projects.git
29+
30+
```bash
31+
cd V/voice-assistant
32+
33+
```bash
34+
python voice_assistant.py
35+
36+
##Usage
37+
38+
- The voice assistant will listen for your commands. You can trigger specific actions, such as:
39+
40+
- "Play [songname]"
41+
- "What's the time?"
42+
- "Who/What is [topic]."
43+
44+
- The assistant will respond to your voice commands accordingly.
45+
46+
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import speech_recognition as sr
2+
import pyttsx3
3+
import pywhatkit
4+
import datetime
5+
import wikipedia
6+
import pyjokes
7+
8+
listener = sr.Recognizer()
9+
engine = pyttsx3.init()
10+
voices = engine.getProperty('voices')
11+
engine.setProperty('voice', voices[1].id)
12+
13+
14+
def talk(text):
15+
engine.say(text)
16+
engine.runAndWait()
17+
18+
19+
def take_command():
20+
try:
21+
with sr.Microphone() as source:
22+
print('listening...')
23+
voice = listener.listen(source, None, 10)
24+
command = listener.recognize_google(voice)
25+
command = command.lower()
26+
if 'thinkBot' in command:
27+
command = command.replace('thinkBot', '')
28+
print(command)
29+
except:
30+
pass
31+
return command
32+
33+
34+
def run_thinkBot():
35+
command = take_command()
36+
print(command)
37+
if 'play' in command:
38+
song = command.replace('play', '')
39+
talk('playing ' + song)
40+
pywhatkit.playonyt(song)
41+
elif 'time' in command:
42+
time = datetime.datetime.now().strftime('%I:%M %p')
43+
talk('Current time is ' + time)
44+
elif 'who is' in command:
45+
person = command.replace('who is', '')
46+
info = wikipedia.summary(person, 1)
47+
print(info)
48+
talk(info)
49+
elif 'date' in command:
50+
talk('sorry, I have a headache')
51+
elif 'are you single' in command:
52+
talk('I am in a relationship with wifi')
53+
elif 'joke' in command:
54+
talk(pyjokes.get_joke())
55+
else:
56+
talk('Please say the command again.')
57+
58+
while True:
59+
try:
60+
run_thinkBot()
61+
except UnboundLocalError:
62+
print("No command detected! ThinkBot has stopped working ")
63+
break

0 commit comments

Comments
 (0)