I'm running a testing script that runs over a website over and over again that runs hundreds of times over the course of several hours. I would like for ruby to starting playing a loud song/mp3 for example, to alert me while I'm in a different part of my fairly small apartment.
I've found THE solution for all Mac OSX users. Credits to this blog post: http://www.mitchchn.me/2014/os-x-terminal/ for showing it to me:
Mac terminals have a command called say
. say
functions exactly like one might hope:
say "I'm done master"
does just that from the terminal.
Inside of a ruby script (in my case) this is easy to implement.
`say "I'm done master"`
works like a charm.
OK, I'd rather it be a female voice by default, but this is great.
To switch the voice go to System Preferences > Dictation and Speech > Text to Speech > System Voice
Vicki is probably the best sounding female voice
edit: oh yes, I wanted the computer to make a noise when it crashed. To do that in ruby:
def go(x)
begin# starts rescue block
puts "5/#{x} = #{5/x}"
rescue
`say "something is wrong, master."`
end
end
go(0)
#=> ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With