Tyler Clemons

Ruby Speaks

by on Jun.27, 2008, under Programming, Ruby, sapi5, win32

Learned a new trick the other day. I was searching around and I found out how to make Ruby talk. So far this only works for Windows machines because the win32 files are only available in Windows… as far as my knowledge. Copy and paste the following code into any editor. It prompts the user for a file and reads it.

require “win32/sapi5”
include Win32

print “Enter Text File:”
file = gets

voice = SpVoice.new
speech = “”

File.open(file.chomp).each {| words|  speech +=words } #Automatic Close

voice.Speak(speech)
puts

Or, you could just do this:

require “win32/sapi5”
include Win32

voice = SpVoice.new
speech = “Tyler is cool, but Sharece is cooler.”

voice.Speak(speech)

:, ,

Leave a Reply

Looking for something?

Use the form below to search the site: