Voice countdown ruby script for interval training
README
This is a simple script used for interval training. (Mac only)
It’s helpful when you do stationary bike exercise and watch TV at the same time. The voice alert will tell you when to sprint or relax. So you don’t have to keep watch on timer. Just enjoy the TV show, and the training.
The time period is suggested by WebMD: Interval Training Burns More Calories in Less Time. Which are:
- 2 minutes warm up
- (30 seconds sprint + 4 minutes relax) x 5 iterations
But you can change it. they are between line 22 and 28.
Sorucecode
# interval_training.rb
# by Bruce Li 2013-04-21
class Fixnum
alias_method :minute, :minutes
alias_method :second, :seconds
def minutes
self*60
end
def seconds
self
end
end
def say(msg, options = {})
voice = options[:v]
if voice and not voice.empty?
system("say -v #{voice} '#{msg}' &")
else
system("say '#{msg}' &")
end
end
# === configs ===
warm_up_duration = 2.minutes
sprint_duration = 30.seconds
relax_duration = 4.minutes
iterations = 5
voice = "" # leave blank or nil to use the default
# ===============
say "warm-up", :v => voice
sleep warm_up_duration
iterations.times.each do |idx|
say "sprint", :v => voice
sleep sprint_duration
if idx != iterations - 1
say "relax", :v => voice
sleep relax_duration
end
end
say "cooling down", :v => voice
Run ruby interval_training.rb
Configuration
voice
: Run say -v ?
in terminal to get a full list of available voices.
喜歡這篇文章嗎?你可能也會喜歡我的學習電子報,我會分享經過篩選的優質內容 + 學習心得
📚 訂閱我的學習電子報
📖 涵蓋主題:
🧑💻 軟體工程
🎯 生產力
💰 商業理財
🧳 創業
🐱 奇怪的知識增加了
💭 思考人生心得
🎁 現在訂閱就送我個人非常愛用「學習任何領域皮毛的 AI Prompt」!
立即免費訂閱 →
✨ 不浪費你的時間,只分享達到我標準的優質內容