Skip to main content

Sutdown Computer With Voice


There are three requirements- 
1. PyAudio — to install pyaudio, go to terminal and type, 
pip install pyaudio
2. SpeechRecognition — to install SpeechRecognition, go to terminal and type,
pip install speechrecognition
3. Pyttsx3 — to install Pyttsx3, go to terminal and type,
pip install pyttsx3

# Importing required modules # importing pyttsx3 import pyttsx3 # importing speech_recognition import speech_recognition as sr # importing os module import os # creating take_commands() function which # can take some audio, Recognize and return # if there are not any errors def take_commands(): # initializing speech_recognition r = sr.Recognizer() # opening physical microphone of computer with sr.Microphone() as source: print('Listening') r.pause_threshold = 0.7 # storing audio/sound to audio variable audio = r.listen(source) try: print("Recognizing") # Recognizing audio using google api Query = r.recognize_google(audio) print("the query is printed='", Query, "'") except Exception as e: print(e) print("Say that again sir") # returning none if there are errors return "None" # returning audio as text import time time.sleep(2) return Query # creating Speak() function to giving Speaking power # to our voice assistant def Speak(audio): # initializing pyttsx3 module engine = pyttsx3.init() # anything we pass inside engine.say(), # will be spoken by our voice assistant engine.say(audio) engine.runAndWait() Speak("Do you want to shutdown your computer sir?") while True: command = take_commands() if "no" in command: Speak("Thank u sir I will not shut down the computer") break if "yes" in command: # Shutting down Speak("Shutting the computer")
os.system("shutdown /s /t 30") break Speak("Say that again sir")





Comments

Popular posts from this blog

Drawing A Design In Python

 Code :  from turtle import *  from random import randint  bgcolor('black')  x = 1  speed(0)  while x < 400:      r = randint(0,255)   g = randint(0,255)    b = randint(0,255)      colormode(255)    pencolor(r,g,b)   fd(50 + x)   rt(90.991)   x = x+1     exitonclick() Result : 

PIKACHU

CODE FOR DRAWING THIS PIKACHU IS BELOW: import turtle def getPosition(x, y): turtle.setx(x) turtle.sety(y) print(x, y) class Pikachu: def __init__(self): self.t = turtle.Turtle() t = self.t t.pensize(3) t.speed(9) t.ondrag(getPosition) def noTrace_goto(self, x, y): self.t.penup() self.t.goto(x, y) self.t.pendown() def leftEye(self, x, y): self.noTrace_goto(x, y) t = self.t t.seth(0) t.fillcolor('#333333') t.begin_fill() t.circle(22) t.end_fill() self.noTrace_goto(x, y+10) t.fillcolor('#000000') t.begin_fill() t.circle(10) t.end_fill() self.noTrace_goto(x+6, y + 22) t.fillcolor('#ffffff') t.begin_fill() t.circle(10) t.end_fill() def rightEye(self, x, y): self.noTrace_goto(x, y) t = self.t ...

Flip Tiles. Memory Game!

CODE : Check Out Our Instagram Page : Instagram.com/Python.Coderss   # import modules from random import * from turtle import * # set the screen screen = Screen() #choose background color screen.bgcolor("yellow") # define the function # for creating a square section # for the game def Square(x, y): up() goto(x, y) down() color('white', 'green') begin_fill() for count in range(4): forward(50) left(90) end_fill() # define functionn to # keep a check of index number def Numbering(x, y): return int((x + 200) // 50 + ((y + 200) // 50) * 8) # define function def Coordinates(count): return (count % 8) * 50 - 200, (count // 8) * 50 - 200 # define function # to make it interactive # user click def click(x, y): spot = Numbering(x, y) mark = state['mark'] if mark is None or mark == spot or tiles[mark] != tiles[spot]: state['mark'] = spot else: hide[spot] = False hide[mark] = False state[...