Skip to content
This repository was archived by the owner on May 25, 2022. It is now read-only.
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Added 3 exiting python projects
  • Loading branch information
Mr-Broken committed Oct 8, 2021
commit e0a905906f9415ac324c1c155ea22377b5ff49e4
92 changes: 92 additions & 0 deletions projects/Simple_AI/Voice_assistant.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Simple_voice_AI

A simple Voice Assistance code you. Must try to execute this code
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in single PR create a single project

don't combine multiple scripts


#importing essential modules

import datetime
import speech_recognition as sr
import pyttsx3
import wikipedia
import webbrowser, os, sys, bs4 ,requests

#setup the main engine to work the rest of the code

engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
print(voices[1].id)
engine.setProperty('voice', voices[1].id)

#Setup the Audio command

def speak(audio):
engine.say(audio)
engine.runAndWait()

def wishMe():
hour = int(datetime.datetime.now().hour)
if hour>=0 and hour<12:
speak("good morning sir!")
elif hour>=12 and hour<12:
speak("Good afternoon sir")
else:
speak("Good evening Sir")

speak("I am Riya")

def takecommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening....")
r.pause_threshold = 1
audio = r.listen(source)
try:
print("Recongnizing.....")
query = r.recognize_google(audio, language='en-in')
print(f"User Said: {query}\n\n")
except Exception as e:
speak("Say this again please...")
return "None"
return query



if __name__ == "__main__":
wishMe()
speak("I'm Online Boss, What can i do for you")
while True:
query = takecommand().lower()


if 'wikipedia' in query:
speak("searching on wikipedia....")
query = query.replace("wikipedia", "")
results = wikipedia.summary(query, sentences=2)
speak("according to wikipedia ")
print(f"\n-----{results}-----\n")
speak(results)
elif 'play music' in query:
music_dir = "C:\\Users\\as\\Music\\Videoder"
songs = os.listdir(music_dir)
print(songs)
os.startfile(os.path.join(music_dir, songs[1]))


elif 'open google' in query:
webbrowser.open('www.google.com')
elif 'open youtube' in query:
webbrowser.open("www.youtube.com")
elif 'open facebook' in query:
webbrowser.open('www.facebook.com')
elif 'open github' in query:
webbrowser.open('www.github.com')
elif 'open instagram' in query:
webbrowser.open('www.instagram.com')
elif 'great work' in query:
speak("thank you Boss")

elif 'bye' or 'good bye', or 'ok bye' or 'exit' or 'quit' in query:
speak("Good bye Boss. Have a nice Day")