Speech synthesis: Difference between revisions
Content deleted Content added
No edit summary |
→{{header|Ruby}}: additional operating systems |
||
Line 80:
=={{header|Ruby}}==
Using this module to encapsulate operating system lookup
<lang ruby>module OperatingSystem
require 'rbconfig'
def self.operating_system
case RbConfig::CONFIG["host_os"]
when /linux/i
:linux
when /cygwin|mswin|mingw|windows/i
:windows
when /darwin/i
:mac
when /solaris/i
:solaris
else
nil
end
end
def self.linux?; operating_system == :linux; end
def self.windows?; operating_system == :windows; end
def self.mac?; operating_system == :mac; end
end</lang>
{{libheader|win32-utils}}
Uses <code>espeak</code> on Linux, <code>say</code> on Mac, and the win32 SAPI library on Windows.
<lang ruby>require 'win32/sapi5'▼
<lang ruby>load 'operating_system.rb'
v = Win32::SpVoice.new▼
v.Speak('This is an example of speech synthesis.')</lang>▼
def speak(text)
if OperatingSystem.windows?
▲ v = Win32::SpVoice.new
v.Speak(text)
elsif OperatingSystem.linux?
IO.popen(["espeak", "-stdin"], "w") {|pipe| pipe.puts text}
elsif OperatingSystem.mac?
IO.popen(["say"], "w") {|pipe| pipe.puts text}
end
end
=={{header|Tcl}}==
|