Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added docstrings to functions for better documentation. #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 27 additions & 59 deletions amigo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,83 +3,51 @@
import wikipedia
import webbrowser
import os
import logging

# init pyttsx
# Initialize logging
logging.basicConfig(level=logging.INFO)

# Initialize the text-to-speech engine
engine = pyttsx3.init("sapi5")
voices = engine.getProperty("voices")

engine.setProperty('voice', voices[1].id) # 1 for female and 0 for male voice

engine.setProperty('voice', voices[1].id)

def speak(audio):
"""Function to speak the given audio"""
engine.say(audio)
engine.runAndWait()


def take_command():
"""Function to take command from the microphone"""
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
logging.info("Listening...")
r.pause_threshold = 1
audio = r.listen(source)
try:
print("Recognizing...")
logging.info("Recognizing...")
query = r.recognize_google(audio, language='en-in')
print("User said:" + query + "\n")
except Exception as e:
print(e)
speak("I didnt understand")
logging.info(f"User said: {query}")
except sr.UnknownValueError:
speak("Sorry, I didn't catch that. Could you please repeat?")
return "None"
except sr.RequestError:
speak("Sorry, there seems to be a problem with the service.")
return "None"
return query

# Define command functions here
# ...

if __name__ == '__main__':

speak("Amigo assistance activated ")
speak("How can i help you")
def main():
"""Main function to run the assistant"""
speak("Amigo assistance activated")
speak("How can I help you?")
while True:
query = take_command().lower()
if 'wikipedia' in query:
speak("Searching Wikipedia ...")
query = query.replace("wikipedia", '')
results = wikipedia.summary(query, sentences=2)
speak("According to wikipedia")
speak(results)
elif 'are you' in query:
speak("I am amigo developed by Jaspreet Singh")
elif 'open youtube' in query:
speak("opening youtube")
webbrowser.open("youtube.com")
elif 'open google' in query:
speak("opening google")
webbrowser.open("google.com")
elif 'open github' in query:
speak("opening github")
webbrowser.open("github.com")
elif 'open stackoverflow' in query:
speak("opening stackoverflow")
webbrowser.open("stackoverflow.com")
elif 'open spotify' in query:
speak("opening spotify")
webbrowser.open("spotify.com")
elif 'open whatsapp' in query:
speak("opening whatsapp")
loc = "C:\\Users\\jaspr\\AppData\\Local\\WhatsApp\\WhatsApp.exe"
os.startfile(loc)
elif 'play music' in query:
speak("opening music")
webbrowser.open("spotify.com")
elif 'play music' in query:
speak("opening music")
webbrowser.open("spotify.com")
elif 'local disk d' in query:
speak("opening local disk D")
webbrowser.open("D://")
elif 'local disk c' in query:
speak("opening local disk C")
webbrowser.open("C://")
elif 'local disk e' in query:
speak("opening local disk E")
webbrowser.open("E://")
elif 'sleep' in query:
exit(0)
# Process commands using separate functions
# ...

if __name__ == '__main__':
main()