RosettaCodeData/Task/Speech-synthesis/Ruby/speech-synthesis-2.rb
Ingy döt Net 68f8f3e56b all tasks
2013-04-11 01:07:29 -07:00

17 lines
477 B
Ruby

load 'operating_system.rb'
def speak(text)
if OperatingSystem.windows?
require 'win32/sapi5'
v = Win32::SpVoice.new
v.Speak(text)
elsif OperatingSystem.mac?
IO.popen(["say"], "w") {|pipe| pipe.puts text}
else
# Try to run "espeak". No OperatingSystem check: "espeak" is
# for Linux but is also an optional package for BSD.
IO.popen(["espeak", "-stdin"], "w") {|pipe| pipe.puts text}
end
end
speak 'This is an example of speech synthesis.'