Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions Voice Assistant/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Voice Assistant
## Description
- It is a beginner-friendly script in python, where they can learn about the if-else conditions in python and different libraries.
- Libraries:
- speech_recognition
- playsound
- gTTS
- pyttsx3
- First, we will keep few words in if-else and the system will see the cases accordingly and respond
Example: Hey bot can you share my ppts,
or small coversations

## Setup instructions
- Packages that are to be installed are:
- speech_recognition
- playsound
- gTTS
- pyttsx3

- Run the Script, using following command which is shown below,
````
python test.py
````
- In this only two opearations are kept, Those are to open a files from the path which you specified intitally and one more is to open google.
- You can just play with the code and create as many else-if and understand the concepts very easily.
- You can check the video, for the working of the voice assistant:
```
https://drive.google.com/file/d/1LuHyAsDoX3aOtW5aJPV7cBXgBq7CfFyL/view?usp=sharing
```

93 changes: 93 additions & 0 deletions Voice Assistant/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import os
import time
import speech_recognition as sr
import playsound
from gtts import gTTS
import random
import pyttsx3
import datetime
import time
import webbrowser
from ecapture import ecapture as ec

def speak(text):
r1 = random.randint(1,10000000)
r2 = random.randint(1,10000000)
randfile = str(r2)+"randomtext"+str(r1) +".mp3"
tts = gTTS(text= text, lang='en', slow=False)
tts.save(randfile)

playsound.playsound(randfile)
print(randfile)
os.remove(randfile)

def get_audio():
r = sr.Recognizer()
with sr.Microphone() as source:
r.adjust_for_ambient_noise(source,duration=1)
# r.energy_threshold()
print("say anything : ")
audio= r.listen(source)
try:
said = r.recognize_google(audio)
print(said)
except:
print("sorry, could not recognise")
return said

engine = pyttsx3.init()
engine.say("hello sir!, This is, Robot, Created by ,Sai Harsha , How can help you?")
#engine.setProperty('rate', 120)
engine.runAndWait()
text = get_audio()
if "PPT" or "ppt" or "intro" or "INTRO" in text:
engine = pyttsx3.init()
engine.say("Yes sir y not,")
engine.setProperty('rate', 125)
engine.runAndWait()
os.system(r"d:\image.png")

elif "Google" or "google" or "GOOGLE" in text:
engine = pyttsx3.init()
engine.say("Yes sir y not,")
engine.setProperty('rate', 125)
engine.runAndWait()
os.system("start \"\" https://www.google.com")

elif 'news' in text:
engine = pyttsx3.init()
news = webbrowser.open_new_tab("https://timesofindia.indiatimes.com/home/headlines")
engine.say('Here are some headlines from the Times of India,Happy reading')
time.sleep(6)


elif 'search' in text:
engine = pyttsx3.init()
text = text.replace("search", "")
webbrowser.open_new_tab(text)
time.sleep(5)


elif 'time' in text:
strTime=datetime.datetime.now().strftime("%H:%M:%S")
engine = pyttsx3.init()
engine.say(f"the time is {strTime}")


elif 'open gmail' in text:
webbrowser.open_new_tab("gmail.com")
engine = pyttsx3.init()
engine.say("Google Mail open now")
time.sleep(5)


elif 'open youtube' in text:
webbrowser.open_new_tab("https://www.youtube.com")
engine = pyttsx3.init()
engine.say("youtube is open now")
time.sleep(5)

elif "camera" in text or "take a photo" in text:
ec.capture(0,"robo camera","img.jpg")
engine = pyttsx3.init()
engine.say("ok")