Exemplo n.º 1
0
def lst(user):
    db.log_action("todoist", "list tasks")
    tasks = user.get_project('Inbox').get_tasks()
    talker.say("You have " + str(len(tasks)) + " open tasks.")
    for task in user.get_project('Inbox').get_tasks():
        talker.say(task.content)
    go()
Exemplo n.º 2
0
def add(user):
    talker.say("Speak new task")
    task = getVoice.getVoice(prompt=False)
    user.get_project('Inbox').add_task(task)
    user.get_project('Inbox').update()
    db.log_action("todoist", "added task " + task)
    go()
Exemplo n.º 3
0
def select(choices, selector="Option"):
    talker.say("Select a " + selector)
    index = 0
    for choice in choices:
        talker.say(str(index))
        talker.say(choice)
        index = index + 1
    voice = getVoice(prompt=False)
    if "repeat" in voice:
        return select(choices, selector)
    else:
        try:
            res_index = int(voice)
        except ValueError:
            nums = {
                'zero': 0,
                'one': 1,
                'two': 2,
                'to': 2,
                'too': 2,
                'three': 3,
                'four': 4,
                'for': 4,
                'five': 5,
                'six': 6,
                'seven': 7,
                'eight': 8,
                'nine': 9,
                'ten': 10
            }
            res_index = nums[voice]
        db.log_action("voice", choices[res_index])
        return choices[res_index]
Exemplo n.º 4
0
def getVoice(prompt=True):
    print "getting voice..."
    r = sr.Recognizer()

    with sr.Microphone() as source:
        print "in microphone"
        r.adjust_for_ambient_noise(source, duration=1)
        if prompt:
            talker.say("How can I help you")
        else:
            ding_wav = wave.open("/home/pi/BrYOUno/utils/ding.wav", 'rb')
            ding_data = ding_wav.readframes(ding_wav.getnframes())
            audio = pyaudio.PyAudio()
            stream_out = audio.open(format=audio.get_format_from_width(
                ding_wav.getsampwidth()),
                                    channels=ding_wav.getnchannels(),
                                    rate=ding_wav.getframerate(),
                                    input=False,
                                    output=True)
            stream_out.start_stream()
            stream_out.write(ding_data)
            time.sleep(0.2)
            stream_out.stop_stream()
            stream_out.close()
        print "listening"
        audio = r.listen(source)
    print "out of microphone"
    speech = r.recognize_google(audio)
    db.log_action("voice", speech.lower())
    return speech.lower()
Exemplo n.º 5
0
def check(user):
    tasks = user.get_project('Inbox').get_tasks()
    option = getVoice.select(map(lambda x: x.content, tasks), selector="task")
    for task in tasks:
        if task.content == option:
            db.log_action("todoist", "checked off task " + task.content)
            task.complete()
            talker.say("Task completed")
    user.get_project('Inbox').update()
    go()
Exemplo n.º 6
0
def search(option):
    global player
    url = "http://0.0.0.0:9999/get_by_search?type=" + option
    talker.say("Speak search query:")
    query = getVoice.getVoice(prompt=False)
    if option == "song":
        url += "&title=" + urllib.quote(query)
        db.log_action("gplaymusic", "played song " + query)
        player = setPlayer(["mplayer", url + "&num_tracks=1"])

    elif option == "artist":
        url += "&artist=" + urllib.quote(query)
        db.log_action("gplaymusic", "played artist " + query)
        player = setPlayer(["mplayer", "-playlist", url])
Exemplo n.º 7
0
def playlist():
    global player
    talker.say("Say playlist keyword:")
    query = getVoice.getVoice(prompt=False)
    playlists_text = requests.get(
        "http://pi.ryanhecht.net:9999/get_all_playlists?format=text").text[:-1]
    all_playlists = playlists_text.split("\n")
    index = 0
    playlist_url = ""
    for pl in all_playlists:
        if query in pl[0:pl.index("|")].lower():
            to_trim = pl.index("|") + 1
            playlist_url = pl[to_trim:]
            break
        index = index + 1
    if playlist_url == "":
        talker.say("Playlist not found. Sorry.")
    else:
        db.log_action("gplaymusic", "played playlist " + query)
        player = setPlayer(["mplayer", "-shuffle", "-playlist", playlist_url])
Exemplo n.º 8
0
def food():
    db.log_action("food", "")
    brown_dining.go()
Exemplo n.º 9
0
def todoist():
    db.log_action("todoist", "")
    todoistcmd.go()
Exemplo n.º 10
0
def stop_music():
    db.log_action("gplaymusic", "stopped")
    google_music.stop()
    return "stopped"
Exemplo n.º 11
0
def start_music():
    db.log_action("gplaymusic", "started")
    google_music.play()
    return "started"
Exemplo n.º 12
0
def stop_mcpr():
    db.log_action("mcpradio", "stopped")
    mcpradio.stop()
    return "stopped"
Exemplo n.º 13
0
def start_mcpr():
    db.log_action("mcpradio", "started")
    mcpradio.start()
    return "started"
Exemplo n.º 14
0
def lights():
    lightswitch.toggle()
    db.log_action("lights", "")
    return "toggled lights"