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 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 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:


import as scw
import sounddevice as sd
from time import sleep
from random import randint
import sys

f_sample_rate, full_alarm =

t_sample_rate, truncated_alarm =

def block():


    while True:

                1, 5401))

def wbtb():

    while True:

                1, 5401))

if __name__ == "__main__":


        mode = sys.argv[1]


    except Exception as error:

            "\n" *2, 


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