This is a quick Python script I wrote to aid with the CANWILD lucid dreaming method. The program is an alarm clock with a randomized snooze function that prevents the sleeper subconsciously learning the snooze schedule.

The alarms automatically turn themselves off so the sleeper doesn’t have to move after being awakened. Snooze time is fully random, and can be anywhere from a few seconds to 90 minutes.

It’s run from the command line in one of two modes:

  1. python sleep.py block

This mode allows four hours of sleep before setting off an initial alarm, then it begins the randomized snooze schedule. It is designed to be run at the begining of the night, when first going to bed.

  1. python sleep.py wbtb

This mode is for when you wake up for whatever reason, and you want to immediately go into the randomized snooze schedule. It’s basically the first mode without the initial four hour sleep allowance. “wbtb” stands for “wake-back-to-bed.”

There are two alarm wav files included in the repo. One is a full length alarm for waking the sleeper after four hours. The other is a truncated alarm to be played during the snooze schedule.

If you still don’t get what this is all about, please read the linked article above to learn about CANWILD and lucid dreaming in general.

Below is the actual code:

 

sleep.py

  1 
   
  2 
    import scipy.io.wavfile as scw
  3 
    import sounddevice as sd
  4 
    from time import sleep
  5 
    from random import randint
  6 
    import sys
  7 
 
  8 
 
  9 
 
 10 
 
 11 
    f_sample_rate, full_alarm = scw.read(
 12 
        "full_alarm.wav")
 13 
 
 14 
    t_sample_rate, truncated_alarm = scw.read(
 15 
        "truncated_alarm.wav")
 16 
 
 17 
 
 18 
 
 19 
 
 20 
    def block():
 21 
 
 22 
        sleep(14400)
 23 
 
 24 
        sd.play(full_alarm)
 25 
        sd.wait()
 26 
 
 27 
        while True:
 28 
 
 29 
            sleep(
 30 
                randint(
 31 
                    1, 5401))
 32 
 
 33 
            sd.play(truncated_alarm)
 34 
            sd.wait()
 35 
 
 36 
 
 37 
 
 38 
 
 39 
    def wbtb():
 40 
 
 41 
        while True:
 42 
 
 43 
            sleep(
 44 
                randint(
 45 
                    1, 1501))
 46 
 
 47 
            sd.play(truncated_alarm)
 48 
            sd.wait()
 49 
 
 50 
 
 51 
 
 52 
 
 53 
    if __name__ == "__main__":
 54 
 
 55 
        try:
 56 
 
 57 
            mode = sys.argv[1]
 58 
 
 59 
            globals()[mode]()
 60 
 
 61 
        except Exception as error:
 62 
 
 63 
            print(
 64 
                "ERROR",
 65 
                "\n" *2,
 66 
                error)
 67 
 
 68 
 
 69 
 
 70 
 

   

Full code repo available on Github

 

Related posts:

Speculative Fuction Bot

EXP-RTL: Exponential Retaliation In Iterated Prisoner’s Dilemma Games

Interleaved Neighborhood Algorithm: Fully Exploratory Optimization

 

About Me