Skip to content

Commit 9b9f59c

Browse files
authored
Merge pull request #673 from RaveenaBhasin/shutdown
Shutdown using voice script added
2 parents 404fb49 + 174f3bb commit 9b9f59c

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

voice_shutdown/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Shutdown your pc using voice command using python
2+
3+
## Introduction
4+
If your far from your pc and you want to shutdown your pc, you can automate it by your voice command using this program.
5+
6+
## How to install library
7+
pip install pywin32
8+
pip install SpeechRecognition
9+
10+
## How to use
11+
1. You has to install all the library mentioned above.
12+
2. Run this programme in your command prompt or any terminal.
13+
3. Specify "Shutdown" keyword when you want to shutdown your pc.
14+
4. It will ask confirmation from you.
15+
5. Say "Yes".
16+
6. It will shoutdown your pc in 3 second.

voice_shutdown/automate_shutdown.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from win32com.client import Dispatch
2+
import speech_recognition as sr
3+
import os
4+
import time
5+
6+
7+
def speak(audio):
8+
speak = Dispatch(("sapi.spvoice"))
9+
speak.speak(audio)
10+
11+
12+
speak("Hello, I am your personal assistant")
13+
14+
15+
def TakeCommand():
16+
r = sr.Recognizer()
17+
with sr.Microphone() as source:
18+
print("Listening...")
19+
r.pause_threshold = 1
20+
r.adjust_for_ambient_noise(source, duration=1)
21+
audio = r.listen(source)
22+
try:
23+
print("Recognizing...")
24+
Query = r.recognize_google(audio, language='en-in')
25+
26+
except Exception:
27+
speak("Say that again please")
28+
return "None"
29+
return Query
30+
31+
32+
while(True):
33+
if __name__ == '__main__':
34+
Query = TakeCommand().lower()
35+
36+
if "shut down" or "shutdown" in Query:
37+
speak("Do you want to shutdown your pc ")
38+
Query2 = TakeCommand().lower()
39+
40+
if "yes" in Query2:
41+
speak("ok shutdowning...")
42+
time.sleep(3)
43+
os.system("shutdown /s /t 0")
44+
elif "no" in Query2:
45+
speak("Ok")

0 commit comments

Comments
 (0)