Created
August 4, 2024 21:38
-
-
Save johncf/c53b4f9118fd13c3e287d5166a03822d to your computer and use it in GitHub Desktop.
A simple timer with audio alerts to run during an interview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env python3 | |
import time | |
from datetime import datetime as dt | |
import numpy as np | |
import simpleaudio as sa | |
from scipy.signal import savgol_filter | |
from tqdm import tqdm | |
def beep_beep(freq_hz=330, seconds=0.16): | |
SAMPLE_RATE = 44100 # 44100 samples per second | |
nsamples = int(seconds * SAMPLE_RATE) | |
t = np.linspace(0, seconds, num=nsamples, endpoint=False) | |
silence1 = np.zeros(int(nsamples * 0.2)) | |
sine1 = np.sin(freq_hz * t * 2 * np.pi) | |
silence2 = np.zeros(int(nsamples * 0.6)) | |
sine2 = sine1[:silence2.size] | |
note = np.concatenate([silence1, sine1, silence2, sine2, silence1]) | |
note = savgol_filter(note, nsamples // 16, 3) # smoothen | |
# adjust volume | |
audio = (330 / freq_hz) ** 1.6 * note * (2**14 - 1) / np.max(np.abs(note)) | |
audio = audio.astype(np.int16) | |
play_obj = sa.play_buffer(audio, 1, 2, SAMPLE_RATE) | |
play_obj.wait_done() | |
def wait_and_beep(duration, freq): | |
for _ in tqdm(range(duration - 1), ncols=50): | |
time.sleep(1) | |
beep_beep(freq) | |
def main(): | |
start = dt.now() | |
elapsed = lambda: str(dt.now() - start)[2:7] | |
MINUTE = 60 | |
print(elapsed(), "introductions") | |
wait_and_beep(4 * MINUTE, 220) | |
print(elapsed(), "requirements") | |
wait_and_beep(3 * MINUTE, 420) | |
print(elapsed(), "capacity estimates") | |
wait_and_beep(4 * MINUTE, 480) | |
print(elapsed(), "high-level") | |
wait_and_beep(8 * MINUTE, 330) | |
print(elapsed(), "deep-dive") | |
wait_and_beep(15 * MINUTE, 330) | |
print(elapsed(), "conclude") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment