Forwarding Forwarding - 1 year ago 63
Ruby Question

How can I make my Ruby script announce values as it runs?

Say I have captured two values,

(and let's pretend that today is

How can I make Ruby convert the string
"one thousand for 30 days"
to audible speech within the console as it runs?

Answer Source

You could use the gem humanize to convert the int 1000 to its name in english,

and you'd also nee something like date1 - date2 to get the difference in days.

Something like:

number.humanize + ' for ' + ( - myDate).to_i.to_s

In order to make the bash speak this string out loud, you could use the very say command you mentioned; ruby allows for easily calling bash commands from within the language, just do something like this:

str = number.humanize + ' for ' + ( - myDate).to_i.to_s
`say #{str}`

Otherwise, if you want a more native solution, you can use the espeak gem:

speech =
speech.speak # invokes espeak
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download