Esempio n. 1
0
class VoiceCommand:
    """
	distributes jobs to an appropriate action in the actions folder. 
	"""

    def __init__(self, speaker):
        self.speaker = speaker
        self.controller = webbrowser.get()

        # initialize action class instances
        self.Youtube = Youtube(self.speaker)
        self.Wolfram = Wolfram(self.speaker, os.environ.get("WOLFRAM_API_KEY"))
        self.Music = Music(self.speaker)
        self.Screenshot = Screenshot(self.speaker)
        self.News = News(self.speaker)
        self.Webpage = Webpage(self.speaker)

    def accidental_recording(self):
        print "---Accidental recording---"
        print "Saying: Oops, sorry."
        self.speaker.play_wav("./wav/sorry.wav")

    def open_webpage(self, job):
        self.Webpage.process(job, self.controller)

    def google(self, job):
        self.speaker.say("searching...")
        google_url = "http://www.google.com/search?q="
        phrase = job.query
        url = google_url + phrase.replace(" ", "+")
        self.controller.open(url)

    def search_youtube(self, job):
        self.Youtube.search(job, self.controller)

    def play_youtube(self, job):
        self.Youtube.process(job, self.controller)

    def take_screenshot(self):
        self.Screenshot.take()

    def ai_respond(self, job, AI, memory):
        response = AI.respond(job.query, memory)
        self.speaker.say(response)

    def get_news(self, job):
        self.News.process(job, self.controller)

    def change_news_source(self, job):
        self.News.set_news_url()

    def ask_wolfram(self, job):
        self.Wolfram.process(job, self.controller)

    def play_music(self, job):
        self.Music.process(job, self.controller)
Esempio n. 2
0
	def __init__(self, speaker):
		self.speaker = speaker
		self.controller = webbrowser.get()
		
		# initialize action classes
		self.Youtube = Youtube(self.speaker)
		self.Wolfram = Wolfram(self.speaker, os.environ.get('WOLFRAM_API_KEY'))
		self.Music = Music(self.speaker)
		self.Screenshot = Screenshot(self.speaker)
		self.News = News(self.speaker)
		self.Webpage = Webpage(self.speaker)
Esempio n. 3
0
class VoiceCommand:
	def __init__(self, speaker):
		self.speaker = speaker
		self.controller = webbrowser.get()
		
		# initialize action classes
		self.Youtube = Youtube(self.speaker)
		self.Wolfram = Wolfram(self.speaker, os.environ.get('WOLFRAM_API_KEY'))
		self.Music = Music(self.speaker)
		self.Screenshot = Screenshot(self.speaker)
		self.News = News(self.speaker)
		self.Webpage = Webpage(self.speaker)

	def accidental_recording(self):
		print "---Accidental recording---"
		print "Saying: Oops, sorry."
		self.speaker.play_wav("./wav/sorry.wav")

	def open_webpage(self, job):
		self.Webpage.process(job, self.controller)

	def google(self, job):
		self.speaker.say("searching...")
		google_url = "http://www.google.com/search?q="
		phrase = job.recorded()[job.recorded().find(' ') + 1:]
		url = google_url + phrase.replace(" ", "+")
		self.controller.open(url)

	def search_youtube(self, job):
		self.Youtube.search(job, self.controller)

	def play_youtube(self, job):
		self.Youtube.process(job, self.controller)

	def take_screenshot(self):
		self.Screenshot.take()

	def ai_respond(self, job, AI, memory):
		response = AI.respond(job.recorded()[8:], memory)
		self.speaker.say(response)

	def get_news(self, job):
		self.News.process(job, self.controller)

	def ask_wolfram(self, job):
		self.Wolfram.process(job, self.controller)

	def play_music(self, job):
		self.Music.process(job, self.controller)
Esempio n. 4
0
    def __init__(self, speaker):
        self.speaker = speaker
        self.controller = webbrowser.get()

        # initialize action class instances
        self.Youtube = Youtube(self.speaker)
        self.Wolfram = Wolfram(self.speaker, os.environ.get("WOLFRAM_API_KEY"))
        self.Music = Music(self.speaker)
        self.Screenshot = Screenshot(self.speaker)
        self.News = News(self.speaker)
        self.Webpage = Webpage(self.speaker)
Esempio n. 5
0
class VoiceCommand:
	"""
	Distribute jobs to the appropriate action.

	"""
	def __init__(self, speaker):
		self.speaker = speaker
		self.controller = webbrowser.get()

		# initialize action class instances
		self.Chatbot = Chatbot(self.speaker)
		self.Youtube = Youtube(self.speaker)

		self.Helper = ActionsHelper(self.speaker)
		self.Webpage = Webpage(self.speaker, self.Helper)
		self.News = News(self.speaker, self.Helper)
		self.Search = Search(self.speaker, self.Helper)
		self.Screenshot = Screenshot(self.speaker, self.Helper)
		self.Music = Music(self.speaker, self.Helper)

		self.Wolfram = Wolfram(self.speaker, os.environ.get('WOLFRAM_API_KEY'))

	def accidental_recording(self):
		"""Started recording by accident, just post message."""
		print "---Accidental recording---"
		print "Saying: Oops, sorry."
		self.speaker.play_wav("./wav/sorry.wav")

	def open_webpage(self, job):
		"""Send to open webpage action; if no page found, search."""
		if self.Webpage.process(job, self.controller) != True:
			self.Search.process(job, self.controller)

	def search(self, job):
		"""Send to web search action."""
		self.Search.process(job, self.controller)

	def search_youtube(self, job):
		"""Send to search youtube action."""
		self.Youtube.search(job, self.controller)

	def play_youtube(self, job):
		"""Send to play first youtube video from search action."""
		self.Youtube.process(job, self.controller)

	def take_screenshot(self):
		"""Send to take screenshot action."""
		self.Screenshot.take()

	def chatbot_respond(self, job):
		"""Send to chatbot to respond action."""
		self.Chatbot.process(job)

	def get_news(self, job):
		"""Send to open news action."""
		self.News.process(job, self.controller)

	def ask_wolfram(self, job):
		"""
		Send to WolframAlpha for a response. 
		If no response is found, send to chatbot for response.

		"""
		if not self.Wolfram.process(job, self.controller):
			self.chatbot_respond(job)

	def play_music(self, job):
		"""Send to play radio action."""
		self.Music.process(job, self.controller)
Esempio n. 6
0
class VoiceCommand:
    """
	Distribute jobs to the appropriate action.

	"""

    def __init__(self, speaker):
        self.speaker = speaker
        self.controller = webbrowser.get()

        # initialize action class instances
        self.Chatbot = Chatbot(self.speaker)
        self.Youtube = Youtube(self.speaker)

        self.Helper = ActionsHelper(self.speaker)
        self.Webpage = Webpage(self.speaker, self.Helper)
        self.News = News(self.speaker, self.Helper)
        self.Search = Search(self.speaker, self.Helper)
        self.Screenshot = Screenshot(self.speaker, self.Helper)
        self.Music = Music(self.speaker, self.Helper)

        self.Wolfram = Wolfram(self.speaker, os.environ.get("WOLFRAM_API_KEY"))

    def accidental_recording(self):
        """Started recording by accident, just post message."""
        print "---Accidental recording---"
        print "Saying: Oops, sorry."
        self.speaker.play_wav("./wav/sorry.wav")

    def open_webpage(self, job):
        """Send to open webpage action; if no page found, search."""
        if self.Webpage.process(job, self.controller) != True:
            self.Search.process(job, self.controller)

    def search(self, job):
        """Send to web search action."""
        self.Search.process(job, self.controller)

    def search_youtube(self, job):
        """Send to search youtube action."""
        self.Youtube.search(job, self.controller)

    def play_youtube(self, job):
        """Send to play first youtube video from search action."""
        self.Youtube.process(job, self.controller)

    def take_screenshot(self):
        """Send to take screenshot action."""
        self.Screenshot.take()

    def chatbot_respond(self, job):
        """Send to chatbot to respond action."""
        self.Chatbot.process(job)

    def get_news(self, job):
        """Send to open news action."""
        self.News.process(job, self.controller)

    def ask_wolfram(self, job):
        """
		Send to WolframAlpha for a response. 
		If no response is found, send to chatbot for response.

		"""
        if not self.Wolfram.process(job, self.controller):
            self.chatbot_respond(job)

    def play_music(self, job):
        """Send to play radio action."""
        self.Music.process(job, self.controller)
Esempio n. 7
0
    def listen(self):
        try:
            audioInput = Microphone()
            audioInput.listen()

            speech_to_text = stt.Google(audioInput)
            recorded_text = speech_to_text.get_text()
            job = Job(recorded_text)

            controller = webbrowser.get(
            )  # initialize controller for web browser

            # parse first and second words in command
            first_word = (recorded_text.split(' ')[0]).lower()
            if recorded_text.find(' ') >= 1:
                second_word = (recorded_text.split(' ')[1]).lower()
            else:
                second_word = ""

            # execute commands based on first word in query
            if first_word == "stop" or first_word == "no" \
              or recorded_text.find('no stop') != -1:
                print "---Accidental recording---"
                print "Saying: Oops, sorry."
                self.speaker.play_wav("./wav/sorry.wav")

            elif first_word == "open":
                if second_word != "":  # open webpage
                    phrase = recorded_text[recorded_text.find(' ') + 1:]
                    url = self.make_url(phrase)

                    if url != "":
                        self.speaker.say("opening " + url[12:])
                        controller.open(url)

                    else:
                        self.speaker.say("sorry, I didn't find the web page.")

                else:
                    self.speaker.say("no webpage specified.")

            elif first_word == "google" or first_word == "search":
                if second_word != "":  # pull up query results
                    self.speaker.say("searching...")
                    google_url = "http://www.google.com/search?q="
                    phrase = recorded_text[recorded_text.find(' ') + 1:]
                    url = google_url + phrase.replace(" ", "+")
                    controller.open(url)

                else:  # no query provided, just open google
                    self.speaker.say("opening google.com.")
                    url = "http://www.google.com"
                    controller.open(url)

            elif recorded_text.find('news') != -1:
                self.speaker.say("getting the world news.")

                r = praw.Reddit(user_agent='evebot v1.0 by /u/tw334')
                submissions = r.get_subreddit('worldnews').get_new(limit=10)
                # TODO make titles spoken
                for submission in submissions:
                    print ">>> " + submission.title

            elif first_word == "youtube":
                if second_word != "":
                    if second_word == "search":  # return youtube search results
                        self.speaker.say("Pulling up youtube results.")
                        y_url = "http://www.youtube.com/results?search_query="
                        phrase = recorded_text[recorded_text.find(' ') + 1:]
                        phrase = phrase[recorded_text.find(' ') + 1:]
                        url = y_url + phrase.replace(" ", "+")
                        controller.open(url)

                    else:  # open first youtube video associated with query
                        self.speaker.say("Playing video.")
                        Youtube(self.speaker).process(job)

                else:
                    self.speaker.say("Opening youtube.com.")
                    url = "http://www.youtube.com"
                    controller.open(url)

            elif first_word == "play" or first_word == "grooveshark":
                self.speaker.say("opening Grooveshark.")

                if second_word != "":  # pull up Grooveshark search results
                    # TODO auto play first music item from search results
                    grooveshark_url = "http://grooveshark.com/#!/search?q="
                    phrase = recorded_text[recorded_text.find(' ') + 1:]
                    url = grooveshark_url + phrase.replace(" ", "+")
                    controller.open(url)

                else:
                    url = "http://grooveshark.com"
                    controller.open(url)

            elif recorded_text.lower().find('screenshot') != -1:
                Screenshot(self.speaker).take()

            elif first_word == "computer":  # AI responds
                response = self.AI.respond(recorded_text[8:], "Thomas")
                self.speaker.say(response)

            else:
                Wolfram(self.speaker,
                        os.environ.get('WOLFRAM_API_KEY')).process(job)

            if not job.get_is_processed:
                self.speaker.say("Sorry, I didn't find any results.")

        except NotUnderstoodException:
            print "Sorry, I didn't understand what you said."
            self.speaker.play_wav("./wav/didntget.wav")