コード例 #1
0
    def get_top_tracks(self):
        tracks = self.sp.artist_top_tracks(self.artist["uri"])['tracks']
        if len(tracks) > 0:
            say("Here's what I think are their best works.")
            count = 0

            playlist = {}

            for track in tracks:
                print("[%d] Song: %s Album: %s" %
                      (count + 1, track['name'], track['album']['name']))
                say("%s from the album %s" %
                    (track['name'], track['album']['name']))
                count += 1

                playlist[str(count)] = (self.artist['name'], track['name'],
                                        track['album']['name'], track['uri'])

            say("Please type the index of the song you would like to hear")
            choice = raw_input("reply: ")

            say("Playing %s from the album %s." %
                (playlist[choice][1], playlist[choice][2]))

            subprocess.call([
                'osascript', '-e',
                'tell app "Spotify" to play track "%s"' % playlist[choice][3]
            ])
        else:
            say("Sorry, Although I know %s but I can't find any songs. Weird" %
                (self.artist['name']))
コード例 #2
0
ファイル: play_music.py プロジェクト: rajatguptarg/jeeves
    def get_top_tracks(self):
        tracks = self.sp.artist_top_tracks(self.artist["uri"])['tracks']
        if len(tracks) > 0:
            say("Here's what I think are the top 3 songs of %s." % self.artist["name"])

            playlist = {}

            for track in tracks[:3]:
                print("Song: %s Album: %s" % (track['name'], track['album']['name']))
                say("%s from the album %s" % (track['name'], track['album']['name']))

                playlist[track['name'].lower()] = track['uri']

            say("Tell me the name of the song you would like to hear")
            choice = user_input()

            for song in playlist.keys():
                if choice in song:
                    say("Playing %s" % choice)
                    subprocess.call([
                        'osascript',
                        '-e',
                        'tell app "Spotify" to play track "%s"' % playlist[song]
                    ])
                    break
        else:
            say("Sorry, Although I know %s but I can't find any songs. Weird" % (self.artist['name']))
コード例 #3
0
ファイル: strategist.py プロジェクト: sudhamshk/jeeves
    def get_strategy_for(self, stemmed_mental_state, action_type):
        try:
            strategies = self.strategies[stemmed_mental_state][action_type]

            if len(strategies) > 1:
                say("Okay, what would you like to do?")
                count = 0
                plans = {}

                for strategy in strategies:
                    if strategy.describe():
                        say(strategy.describe())

                    plans[str(count)] = strategy

                reply = user_input("reply:")
                if not reply:
                    return

                action = reply.split(' ')
                strategy = self.strategies[action[0]][action[1]][0]
            else:
                strategy = strategies[0]

            strategy.react()
            strategy.perform()
        except KeyError:
            print("I don't know what do. Yet, hum nahi phate na!")
コード例 #4
0
ファイル: play_music.py プロジェクト: sudhamshk/jeeves
    def get_top_tracks(self):
        tracks = self.sp.artist_top_tracks(self.artist["uri"])['tracks']
        if len(tracks) > 0:
            say("Here's what I think are the top 3 songs of %s." %
                self.artist["name"])

            playlist = {}

            for track in tracks[:3]:
                print("Song: %s Album: %s" %
                      (track['name'], track['album']['name']))
                say("%s from the album %s" %
                    (track['name'], track['album']['name']))

                playlist[track['name'].lower()] = track['uri']

            say("Tell me the name of the song you would like to hear")
            choice = user_input()

            for song in playlist.keys():
                if choice in song:
                    say("Playing %s" % choice)
                    subprocess.call([
                        'osascript', '-e',
                        'tell app "Spotify" to play track "%s"' %
                        playlist[song]
                    ])
                    break
        else:
            say("Sorry, Although I know %s but I can't find any songs. Weird" %
                (self.artist['name']))
コード例 #5
0
ファイル: play_music.py プロジェクト: Arduino-Projects/jeeves
    def get_top_tracks(self):
        tracks = self.sp.artist_top_tracks(self.artist["uri"])['tracks']
        if len(tracks) > 0:
            say("Here's what I think are their best works.")
            count = 0

            playlist = {}

            for track in tracks:
                print("[%d] Song: %s Album: %s" % (count + 1, track['name'], track['album']['name']))
                say("%s from the album %s" % (track['name'], track['album']['name']))
                count += 1

                playlist[str(count)] = (self.artist['name'], track['name'], track['album']['name'], track['uri'])

            say("Please type the index of the song you would like to hear")
            choice = user_input("reply: ")

            say("Playing %s from the album %s." % (playlist[choice][1], playlist[choice][2]))

            subprocess.call([
                'osascript',
                '-e',
                'tell app "Spotify" to play track "%s"' % playlist[choice][3]
            ])
        else:
            say("Sorry, Although I know %s but I can't find any songs. Weird" % (self.artist['name']))
コード例 #6
0
    def get_strategy_for(self, stemmed_mental_state, action_type):
        try:
            strategies = self.strategies[stemmed_mental_state][action_type]

            if len(strategies) > 1:
                say("Okay, what would you like to do?")
                count = 0
                plans = {}

                for strategy in strategies:
                    print("[%d] %s" % (count + 1, strategy.describe()))
                    if strategy.describe():
                        say(strategy.describe())
                    count += 1

                    plans[str(count)] = strategy

                index = raw_input("reply: ")
                strategy = plans[index]
            else:
                strategy = strategies[0]

            strategy.react()
            strategy.perform()
        except KeyError:
            print("I don't know what do. Yet, hum nahi phate na Behenchod!")
コード例 #7
0
ファイル: segregator.py プロジェクト: JyotsnaGorle/jeeves
 def command_exists(self, sentence):
     command = "ok jeeves"
     if command in sentence:
         sentence = sentence.replace(command, "")
     elif 1 == 1:
         say("please include the command.")
         sentence = ""
     return sentence
コード例 #8
0
ファイル: segregator.py プロジェクト: rahul080327/jeeves
 def command_exists(self, sentence):
     command = "ok jeeves"
     if command in sentence:
         sentence = sentence.replace(command, "")
     elif 1 == 1:
         say("please include the command.")
         sentence = ""
     return sentence
コード例 #9
0
ファイル: play_animal_game.py プロジェクト: sudhamshk/jeeves
def check():
    say("Think of an animal and when you're ready say ok.")
    user_input('reply:')

    if not os.path.exists("brains"):
        say("I guess we are playing this game for the first time, so pardon my ignorance.")
        mem_walker(False)
    else:
        mem_walker(True)
コード例 #10
0
def check():
    say("Think of an animal and when you're ready hit the enter key.")
    raw_input()

    if not os.path.exists("brains"):
        say("I guess we are playing this game for the first time, so pardon my ignorance.")
        mem_walker(False)
    else:
        mem_walker(True)
コード例 #11
0
    def perform(self):
        global responses

        for response_type in responses.keys():
            if self.action == response_type:
                say(responses[response_type])
                break
        else:
            say("Sorry, I cannot help you with that")
コード例 #12
0
ファイル: speech_response.py プロジェクト: sudhamshk/jeeves
    def perform(self):
        global responses

        for response_type in responses.keys():
            if self.action == response_type:
                say(responses[response_type])
                break
        else:
            say("Sorry, I cannot help you with that")
コード例 #13
0
ファイル: make_coffee.py プロジェクト: sudhamshk/jeeves
    def react(self):
        time_of_day = datetime.now().hour

        if time_of_day < 12:
            say("sure, while I make coffee let me update you with today's news and weather")
            news_reader = ReadNewsAndWeather()
            news_reader.read_news()
        else:
            say("sure, give me some time")
コード例 #14
0
ファイル: play_animal_game.py プロジェクト: sudhamshk/jeeves
    def perform(self):
        reply = "yes"

        while reply in ["yes", "y"]:
            check()

            say("Shall we play again?")
            reply = user_input("reply: ").lower()

        say("It was nice playing with you!")
コード例 #15
0
ファイル: play_music.py プロジェクト: sudhamshk/jeeves
    def find_artist(self, name):
        results = self.sp.search(q='artist:' + name, type='artist')
        items = results['artists']['items']

        if len(items) > 0:
            self.artist = items[0]
            say("Curating the best from %s..." % self.artist['name'])
            return True

        return False
コード例 #16
0
    def perform(self):
        reply = "yes"

        while reply in ["yes", "y"]:
            check()

            say("Shall we play again?")
            reply = raw_input("reply: ").lower()

        say("It was nice playing with you!")
コード例 #17
0
ファイル: segregator.py プロジェクト: Arduino-Projects/jeeves
    def react(self, greeting):
        time_of_day = datetime.now().hour

        if time_of_day not in times[greeting]:
            say("Actually, its...")

        for key in times.keys():
            if time_of_day in times[key]:
                say("Good %s" % key)
                break
コード例 #18
0
ファイル: play_music.py プロジェクト: Arduino-Projects/jeeves
    def find_artist(self, name):
        results = self.sp.search(q='artist:' + name, type='artist')
        items = results['artists']['items']

        if len(items) > 0:
            self.artist = items[0]
            say("Curating the best from %s..." % self.artist['name'])
            return True

        return False
コード例 #19
0
    def react(self, greeting):
        time_of_day = datetime.now().hour

        if time_of_day not in times[greeting]:
            say("Actually, its...")

        for key in times.keys():
            if time_of_day in times[key]:
                say("Good %s" % key)
                break
コード例 #20
0
ファイル: recognizer.py プロジェクト: Arduino-Projects/jeeves
def recognize():
    r = sr.Recognizer()

    with sr.Microphone() as source:
        audio = r.listen(source)

    try:
        return r.recognize_google(audio)
    except sr.UnknownValueError:
        say("Sorry, I could not understand that.")
    except sr.RequestError:
        say("Sorry, could not connect to the speech service. Check the internet connection.")
コード例 #21
0
    def read_news(self):
        sources = data_sources['news_urls']

        say("I can read news from...")
        for source in sources.keys():
            say(source)
        say("please tell me where would you like to hear it from?")
        feed = feedparser.parse(sources[user_input()])

        say("So, the top 3 stories are...")
        for entry in feed.entries[:count]:
            news_to_read = entry["description"]
            say(re.sub('<[^<]+?>', '', news_to_read.split('.')[0]))
コード例 #22
0
    def read_mails(self):
        user_id = 'me'
        label = 'UNREAD'
        credentials = self.get_credentials()
        http = credentials.authorize(httplib2.Http())
        service = discovery.build('gmail', 'v1', http=http)
        response = service.users().messages().list(userId=user_id,
                                                   labelIds=label).execute()
        messages = []

        if 'messages' in response:
            messages.extend(response['messages'])

        say('you have %d unread emails; and how many would you like me to read?'
            % response['resultSizeEstimate'])
        limit = int(raw_input("reply: "))

        count = 0
        for message in messages[:limit]:
            count += 1
            message_content = service.users().messages().get(
                userId=user_id,
                id=message['id'],
                format='metadata',
                metadataHeaders=['From', 'Subject']).execute()
            say('message %d' % count)
            metadata_list = message_content['payload']['headers']

            for metadata in metadata_list:
                say(metadata['name'])
                say(metadata['value'])
コード例 #23
0
    def read_mails(self):
        user_id = 'me'
        label = 'UNREAD'
        credentials = self.get_credentials()
        http = credentials.authorize(httplib2.Http())
        service = discovery.build('gmail', 'v1', http=http)
        response = service.users().messages().list(userId=user_id, labelIds=label).execute()
        messages = []

        if 'messages' in response:
            messages.extend(response['messages'])

        say('you have %d unread emails; and how many would you like me to read?' % response['resultSizeEstimate'])
        limit = int(raw_input("reply: "))

        count = 0
        for message in messages[:limit]:
            count += 1
            message_content = service.users().messages().get(userId=user_id, id=message['id'],
                                                             format='metadata',
                                                             metadataHeaders=['From', 'Subject']).execute()
            say('message %d' % count)
            metadata_list = message_content['payload']['headers']

            for metadata in metadata_list:
                say(metadata['name'])
                say(metadata['value'])
コード例 #24
0
def recognize():
    r = sr.Recognizer()
    r.energy_threshold = 4000

    with sr.Microphone() as source:
        audio = r.listen(source)

    try:
        return r.recognize_google(audio)
    except sr.UnknownValueError:
        say("Sorry, I could not understand that.")
    except sr.RequestError:
        say("Sorry, could not connect to the speech service. Check the internet connection."
            )
コード例 #25
0
ファイル: play_music.py プロジェクト: Arduino-Projects/jeeves
    def perform(self):
        self.start_spotify()
        say("Please type the artist you want to hear: ")
        name = user_input("reply: ")

        if not self.find_artist(name):
            say("That's weird. All this knowledge and still I couldn't find anything. I'll try to learn more.")
            say("My sincere apologies for that.")
            return

        self.get_top_tracks()
コード例 #26
0
ファイル: play_music.py プロジェクト: sudhamshk/jeeves
    def perform(self):
        self.start_spotify()
        say("Please tell me the artist or band you want to hear: ")
        name = user_input()

        if not self.find_artist(name):
            say("That's weird. All this knowledge and still I couldn't find anything. I'll try to learn more."
                )
            say("My sincere apologies for that.")
            return

        self.get_top_tracks()
コード例 #27
0
ファイル: play_music.py プロジェクト: Arduino-Projects/jeeves
 def react(self):
     say("Okay, lets find some awesome music just for you...")
コード例 #28
0
ファイル: play_animal_game.py プロジェクト: sudhamshk/jeeves
 def react(self):
     say("Okay, Lets play a game...")
コード例 #29
0
 def react(self):
     say("unfortunately I cannot feed you, but I can help you find some food")
コード例 #30
0
ファイル: segregator.py プロジェクト: Arduino-Projects/jeeves
 def react_casually(self, casual_greeting):
     say(casual_greeting)
コード例 #31
0
 def react(self):
     say("Fetching today's news and weather for you...")
コード例 #32
0
 def react(self):
     say("reading today's unread emails")
コード例 #33
0
ファイル: play_music.py プロジェクト: sudhamshk/jeeves
 def react(self):
     say("Okay, lets find some awesome music just for you...")
コード例 #34
0
def mem_walker(brains_found):
    flag1, flag2 = False, False

    if not brains_found:
        block = MemBlock()
        block.question = "Is it 4 legged?"
        block.guess = "Dog"

        write_memory(block)
        mem_walker(True)
    else:
        block = read_memory()
        current_block = block

        while True:
            print("[Jeeves] %s" % current_block.question)
            say(current_block.question)
            reply = raw_input("reply: ").lower()

            if reply in ["yes", "y"]:
                print("[Jeeves] %s" % current_block.guess)
                say("So, Is it a %s?" % current_block.guess)
                reply = raw_input("reply: ").lower()

                if reply in ["yes", "y"]:
                    say("Awesome!! I'm getting good at this!")
                    break
                else:
                    if not current_block.no2:
                        flag2 = True
                        break
                    else:
                        current_block = current_block.no2
            else:
                if not current_block.no1:
                    flag1 = True
                    break
                else:
                    current_block = current_block.no1

        if flag1 or flag2:
            temp = MemBlock()

            say("Okay, I give up!")
            say("I want to learn from you now...")
            say("Type a question related to the animal you thought.")
            say("For example: Does it have stripes? Or does it run fast?")
            temp.question = raw_input("reply: ")

            say("Okay, tell me the creature you thought of")
            temp.guess = raw_input("reply: ")

            say("Awesome. Assuming what you taught me is correct, I'll definitely remember it!")

            if flag1:
                current_block.no1 = temp
            else:
                current_block.no2 = temp

            write_memory(block)
コード例 #35
0
ファイル: play_animal_game.py プロジェクト: sudhamshk/jeeves
def mem_walker(brains_found):
    flag1, flag2 = False, False

    if not brains_found:
        block = MemBlock()
        block.question = "Is it 4 legged?"
        block.guess = "Dog"

        write_memory(block)
        mem_walker(True)
    else:
        block = read_memory()
        current_block = block

        while True:
            print("[Jeeves] %s" % current_block.question)
            say(current_block.question)
            reply = user_input("reply: ").lower()

            if reply in ["yes", "y"]:
                print("[Jeeves] %s" % current_block.guess)
                say("So, Is it a %s?" % current_block.guess)
                reply = user_input("reply: ").lower()

                if reply in ["yes", "y"]:
                    say("Awesome!! I'm getting good at this!")
                    break
                else:
                    if not current_block.no2:
                        flag2 = True
                        break
                    else:
                        current_block = current_block.no2
            else:
                if not current_block.no1:
                    flag1 = True
                    break
                else:
                    current_block = current_block.no1

        if flag1 or flag2:
            temp = MemBlock()

            say("Okay, I give up!")
            say("I want to learn from you now...")
            say("Type a question related to the animal you thought.")
            say("For example: Does it have stripes? Or does it run fast?")
            temp.question = user_input("reply: ")

            say("Okay, tell me the creature you thought of")
            temp.guess = user_input("reply: ")

            say("Awesome. Assuming what you taught me is correct, I'll definitely remember it!")

            if flag1:
                current_block.no1 = temp
            else:
                current_block.no2 = temp

            write_memory(block)
コード例 #36
0
 def react(self):
     say("awwww... don't be sad, let me help you here")
コード例 #37
0
 def react(self):
     say("reading today's unread emails")
コード例 #38
0
    def read_news(self):
        indexed_source = []

        sources = data_sources['news_urls']

        say("I can read news from...")
        for source in sources.keys():
            say(source)
            indexed_source.append(sources[source])

        say("And, very soon i will be able to hear you. For now please type the choice from 1 to %d" % len(sources))
        choice = int(raw_input("choice[1-%d]: " % len(sources)))
        say("And, how many headlines would you like to hear?")
        count = int(raw_input("how many: "))

        feed = feedparser.parse(indexed_source[choice - 1])

        say("So, the top stories are...")
        for entry in feed.entries:
            news_to_read = entry["description"]
            say(re.sub('<[^<]+?>', '', news_to_read.split('.')[0]))
            count -= 1
            if count == 0:
                break
コード例 #39
0
ファイル: grammifier.py プロジェクト: rajatguptarg/jeeves
 def speak(self, what):
     say(what)
コード例 #40
0
 def react(self):
     say("Okay, Lets play a game...")
コード例 #41
0
ファイル: grammifier.py プロジェクト: sudhamshk/jeeves
 def speak(self, what):
     say(what)
コード例 #42
0
ファイル: open_facebook.py プロジェクト: sudhamshk/jeeves
 def react(self):
     say("awwww... don't be sad, let me help you here")
コード例 #43
0
 def react_casually(self, casual_greeting):
     say(casual_greeting)
コード例 #44
0
    "--input", help="specify the input source mic/stdin, default is stdin")
parser.add_argument("--host",
                    help="specify julius' host, default is localhost")
parser.add_argument("--port",
                    help="specify julius' port, default is 10500",
                    type=int)
args = parser.parse_args()

if not os.path.exists(".CHAT_SERVER_PID"):
    process = subprocess.Popen([sys.executable, "chat_ui/chat_ui_server.py"])

    with open(".CHAT_SERVER_PID", "w") as pid:
        pid.write(str(process.pid))
else:
    with open(".CHAT_SERVER_PID") as pid:
        subprocess.call(['kill', pid.readlines()[0].strip()])

    os.remove(".CHAT_SERVER_PID")

src = "mic" if (args.input and args.input == "mic") else "stdin"

say("Hello. I'm at your service.")
while True:
    if src == "stdin":
        sentence = raw_input("Type something: ")
    else:
        sentence = user_input("Say something: ")

    segregator = Segregator(sentence)
    segregator.segregate_and_react()