Speech synthesis: Difference between revisions
Content deleted Content added
→{{header|Ruby}}: additional operating systems |
→{{header|Ruby}}: I have espeak for OpenBSD, but this script failed because it only checked for Linux. |
||
Line 83: | Line 83: | ||
<lang ruby>module OperatingSystem |
<lang ruby>module OperatingSystem |
||
require 'rbconfig' |
require 'rbconfig' |
||
module_function |
|||
def |
def operating_system |
||
case RbConfig::CONFIG["host_os"] |
case RbConfig::CONFIG["host_os"] |
||
when /linux/i |
when /linux/i |
||
Line 97: | Line 98: | ||
end |
end |
||
end |
end |
||
def |
def linux?; operating_system == :linux; end |
||
def |
def windows?; operating_system == :windows; end |
||
def |
def mac?; operating_system == :mac; end |
||
end</lang> |
end</lang> |
||
{{libheader|win32-utils}} |
{{libheader|win32-utils}} |
||
{{works with|Ruby|1.9}} |
|||
Uses <code>espeak</code> on Linux, <code>say</code> on Mac, and the win32 SAPI library on Windows. |
Uses <code>espeak</code> on Linux, <code>say</code> on Mac, and the win32 SAPI library on Windows. |
||
<lang ruby>load 'operating_system.rb' |
<lang ruby>load 'operating_system.rb' |
||
Line 111: | Line 113: | ||
v = Win32::SpVoice.new |
v = Win32::SpVoice.new |
||
v.Speak(text) |
v.Speak(text) |
||
elsif OperatingSystem.linux? |
|||
⚫ | |||
elsif OperatingSystem.mac? |
elsif OperatingSystem.mac? |
||
IO.popen(["say"], "w") {|pipe| pipe.puts text} |
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. |
|||
⚫ | |||
end |
end |
||
end |
end |