def execute(self, operand):
        self.debug("Reminding " + operand)

        cmd = "play " + self.get_resource_path('ding.mp3')
        system.call_silently(cmd, sync=True)

        speech.say("Sir, " + operand, sync=False)
        response = inputs.get_string_timeout(self.get_config('TIME_OUT'))
        if not response:
            self.reschedule(operand)

        if meaning.means(response, "okay"):
            return
        elif meaning.means(response, "not_okay"):
            self.debug("Reminding again in one day.")
            reschedule_str = inputs.get_string("Schedule again in: ")
            try:
                delta = parse.time_delta(reschedule_str)
            except exceptions.PAULAParseException as e:
                outputs.print_error(str(e.__class__))

            # fix bash issues again
            operand = operand.replace("\"", "\\\"")
            operand = operand.replace("\'", "\\\'")
            schedule.schedule_event_with_delta(delta, "paula_remind", operand)
        else:
            self.reschedule(operand)
def say(text, sync=False):
    if conf.SOUND_ON:
        bash_command = conf.SPEAK_SCRIPT + ' "' + text + '"'
        if conf.DEBUG:
            system.call(bash_command, sync=sync)
        else:
            system.call_silently(bash_command, sync=sync)
def download_song(vidid):
    download = system.call_silently(
        "youtube-dl --extract-audio --audio-format mp3 --id http://youtube.com/watch?v=" + vidid, sync=False
    )

    print("Please fill in some info: ")
    artist = inputs.get_string(prompt="Artist: ")
    album = inputs.get_string(prompt="Album: ")
    title = inputs.get_string(prompt="Title: ")

    # heel lelijk, moet veranderd worden
    musicdir = song.get_music_dirs()[0]
    if len(song.get_music_dirs()) > 1:
        musicdir = inputs.get_item_from_list(music_conf.MUSIC_DIRS)

    if not os.path.isdir(musicdir + "/" + artist):
        os.mkdir(musicdir + "/" + artist)
    if not os.path.isdir(musicdir + "/" + artist + "/" + album):
        os.mkdir(musicdir + "/" + artist + "/" + album)

    download.wait()

    file_path = musicdir + "/" + artist + "/" + album + "/" + title + ".mp3"
    os.rename(vidid + ".mp3", file_path)

    audio = EasyID3(file_path)
    audio["title"] = title
    audio["artist"] = artist
    audio["album"] = album
    audio.save()
def go_to_sleep_mode(seconds):
    if seconds == 0:
        if not conf.DEBUG:
            cmd = "pm-suspend"
            system.call_silently(cmd, sudo=True)
        else:
            outputs.print_debug("going to sleep indefinitely")
    else:
        cmd = "sudo rtcwake --mode mem "
        if conf.DEBUG:
            cmd += "--dry-run "
        cmd += "--seconds " + str(seconds)

        if not conf.DEBUG:
            system.call_silently(cmd, sudo=True)
        else:
            system.call(cmd, sudo=True)
    def execute(self, operand):
        CHUNK = 1024
        FORMAT = pyaudio.paInt16
        CHANNELS = 2
        RATE = 16000
        RECORD_SECONDS = 4
        WAVE_OUTPUT_FILENAME = "/tmp/output.wav"

        p = pyaudio.PyAudio()

        stream = p.open(format=FORMAT,
                        channels=CHANNELS,
                        rate=RATE,
                        input=True,
                        frames_per_buffer=CHUNK)

        print("* recording")

        frames = []

        for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
            data = stream.read(CHUNK)
            frames.append(data)

        print("* done recording")

        stream.stop_stream()
        stream.close()
        p.terminate()

        wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
        wf.setnchannels(CHANNELS)
        wf.setsampwidth(p.get_sample_size(FORMAT))
        wf.setframerate(RATE)
        wf.writeframes(b''.join(frames))
        wf.close()

        with open("/tmp/output.wav") as f:
            system.call_silently("flac -f /tmp/output.wav")
            f = open('/tmp/output.flac', 'rb')
            flac_cont = f.read()
            result = self.speech_to_text(flac_cont)
            f.close()

        print("understood: " + result)
def open(url):
    if conf.DEBUG:
        outputs.print_debug("Opening URL in browser: " + url)
    system.call_silently("xdg-open \"" + url + "\"", sync=False)
def set(percent):
    cmd = "amixer set Master " + str(percent) + "%"
    if not conf.DEBUG:
        system.call_silently(cmd)
    else:
        system.call(cmd)