A.I. for Beginners in python | Artificial Intellingence | using Speech Recognition | 2021
This python Code boosts your interest in making more and more perfect Artificial Intelligence because when you see the code its just an English words which you are using in daily life...
1. You need to install Python in your laptop or system,,
2. After installing python install some libraries using pip command
-pip install pyaudio
-pip install speechrecognition
-pip install pyttsx3
3. Then copy my code and paste it into any text editor like notepad or sublime
import os, pyttsx3
import speech_recognition as sr
def take_commands():
r=sr.Recognizer()
with sr.Microphone() as source:
print('Listening')
r.pause_threshold=0.7
audio=r.listen(source)
try:
print("Recognizing")
Query= r.recognize_google(audio)
print('The query is printed',Query)
except Exception as e:
print(e)
print("Say that again Aniket sir")
return "None"
import time
time.sleep(2)
return Query
def Speak(audio):
engine = pyttsx3.init()
engine.say(audio)
engine.runAndWait()
Speak("Do you want to switch off the computer, Aniket sir")
while True:
command = take_commands()
if "exit" in command:
Speak("Ok sir, let me exit, Aniket Sir")
break
if "yes" in command:
Speak("Ok Aniket Sir thankyou computer will be shutdown now")
os.system("shutdown /s /t 30")
if "no" in command:
Speak("Ok Aniket Sir no problem")
break
4. Then save the code filename.py (filename is anything you want)
5. Open command promt using win_key+R then type "cmd" now go to folder or drive where you save your file using command prompt
6. After that run the file with this command: python filename.py. (for ex. python shutdown.py)
7. Then say yes, no or exit in your sentence then it will work.
Voice: Monika singh thakur
Thankyou for watching
Please like, subscribe and share