Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0feb2af

Browse files
Merge pull request avinashkranjan#359 from saiharsha-22/master
Script for Voice Assistant
2 parents 351a1f3 + 5f342e2 commit 0feb2af

File tree

2 files changed

+123
-0
lines changed

2 files changed

+123
-0
lines changed

‎Voice Assistant/README.md‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Voice Assistant
2+
## Description
3+
- It is a beginner-friendly script in python, where they can learn about the if-else conditions in python and different libraries.
4+
- Libraries:
5+
- speech_recognition
6+
- playsound
7+
- gTTS
8+
- pyttsx3
9+
- First, we will keep few words in if-else and the system will see the cases accordingly and respond
10+
Example: Hey bot can you share my ppts,
11+
or small coversations
12+
13+
## Setup instructions
14+
- Packages that are to be installed are:
15+
- speech_recognition
16+
- playsound
17+
- gTTS
18+
- pyttsx3
19+
20+
- Run the Script, using following command which is shown below,
21+
````
22+
python test.py
23+
````
24+
- 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.
25+
- You can just play with the code and create as many else-if and understand the concepts very easily.
26+
- You can check the video, for the working of the voice assistant:
27+
```
28+
https://drive.google.com/file/d/1LuHyAsDoX3aOtW5aJPV7cBXgBq7CfFyL/view?usp=sharing
29+
```
30+

‎Voice Assistant/test.py‎

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import os
2+
import time
3+
import speech_recognition as sr
4+
import playsound
5+
from gtts import gTTS
6+
import random
7+
import pyttsx3
8+
import datetime
9+
import time
10+
import webbrowser
11+
from ecapture import ecapture as ec
12+
13+
def speak(text):
14+
r1 = random.randint(1,10000000)
15+
r2 = random.randint(1,10000000)
16+
randfile = str(r2)+"randomtext"+str(r1) +".mp3"
17+
tts = gTTS(text= text, lang='en', slow=False)
18+
tts.save(randfile)
19+
20+
playsound.playsound(randfile)
21+
print(randfile)
22+
os.remove(randfile)
23+
24+
def get_audio():
25+
r = sr.Recognizer()
26+
with sr.Microphone() as source:
27+
r.adjust_for_ambient_noise(source,duration=1)
28+
# r.energy_threshold()
29+
print("say anything : ")
30+
audio= r.listen(source)
31+
try:
32+
said = r.recognize_google(audio)
33+
print(said)
34+
except:
35+
print("sorry, could not recognise")
36+
return said
37+
38+
engine = pyttsx3.init()
39+
engine.say("hello sir!, This is, Robot, Created by ,Sai Harsha , How can help you?")
40+
#engine.setProperty('rate', 120)
41+
engine.runAndWait()
42+
text = get_audio()
43+
if "PPT" or "ppt" or "intro" or "INTRO" in text:
44+
engine = pyttsx3.init()
45+
engine.say("Yes sir y not,")
46+
engine.setProperty('rate', 125)
47+
engine.runAndWait()
48+
os.system(r"d:\image.png")
49+
50+
elif "Google" or "google" or "GOOGLE" in text:
51+
engine = pyttsx3.init()
52+
engine.say("Yes sir y not,")
53+
engine.setProperty('rate', 125)
54+
engine.runAndWait()
55+
os.system("start \"\" https://www.google.com")
56+
57+
elif 'news' in text:
58+
engine = pyttsx3.init()
59+
news = webbrowser.open_new_tab("https://timesofindia.indiatimes.com/home/headlines")
60+
engine.say('Here are some headlines from the Times of India,Happy reading')
61+
time.sleep(6)
62+
63+
64+
elif 'search' in text:
65+
engine = pyttsx3.init()
66+
text = text.replace("search", "")
67+
webbrowser.open_new_tab(text)
68+
time.sleep(5)
69+
70+
71+
elif 'time' in text:
72+
strTime=datetime.datetime.now().strftime("%H:%M:%S")
73+
engine = pyttsx3.init()
74+
engine.say(f"the time is {strTime}")
75+
76+
77+
elif 'open gmail' in text:
78+
webbrowser.open_new_tab("gmail.com")
79+
engine = pyttsx3.init()
80+
engine.say("Google Mail open now")
81+
time.sleep(5)
82+
83+
84+
elif 'open youtube' in text:
85+
webbrowser.open_new_tab("https://www.youtube.com")
86+
engine = pyttsx3.init()
87+
engine.say("youtube is open now")
88+
time.sleep(5)
89+
90+
elif "camera" in text or "take a photo" in text:
91+
ec.capture(0,"robo camera","img.jpg")
92+
engine = pyttsx3.init()
93+
engine.say("ok")

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /