This repository was archived by the owner on May 25, 2022. It is now read-only. 
 -   Notifications  You must be signed in to change notification settings 
- Fork 5.7k
Voice Assistance in Python #471
   Open  
  Mr-Broken wants to merge 3 commits into Python-World:master       Choose a base branch                                                 from Mr-Broken:patch-1                
 base: master
Could not load branches
    Branch not found: {{ refName }} 
     Loading  
 Could not load tags
   Nothing to show
        Loading  
 Are you sure you want to change the base?
 Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated. 
    Open  
 Changes from all commits
 Commits 
  Show all changes 
  3 commits   Select commit Hold shift + click to select a range 
  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
There are no files selected for viewing
   This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters   
        This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters   
     | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| # Simple_voice_AI | ||
|  | ||
| A simple Voice Assistance code you. Must try to execute this code | ||
|  | ||
| #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") | ||
|  | ||
|  | ||
|  | ||
|  | ||
 Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.    
 
Uh oh!
There was an error while loading. Please reload this page.