Module: Voice

Defined in:
lib/voice.rb

Constant Summary collapse

PLATFORM_IS_OSX =
(Object::RUBY_PLATFORM =~ /darwin/i)
DEFAULT_VOICE =
'Kathy'
NOVELTY_VOICES =
["Albert", "Bad News", "Bahh", "Bells",
  "Boing", "Bubbles", "Cellos", "Deranged", "Good News",
  "Hysterical", "Pipe Organ", "Trinoides", "Whisper", "Zarvox"
]
@@all =
nil
@@novelty =
nil

Class Method Summary collapse

Class Method Details

.all(opts = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/voice.rb', line 23

def self.all(opts={})
  return nil if @@all.nil?
  opts = {} unless opts.is_a?(Hash)

  if opts[:novelty] == 'only'
    @@novelty
  elsif opts[:novelty]
    @@all + @@novelty
  else
    @@all
  end
end

.defaultObject



36
37
38
39
# File 'lib/voice.rb', line 36

def self.default
  return DEFAULT_VOICE if @@all.include?(DEFAULT_VOICE)
  return @@all.first
end

.get_rand(opts = {}) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/voice.rb', line 41

def self.get_rand(opts={})
  return nil if @@all.nil?
  opts = {} unless opts.is_a?(Hash)
  
  voices = self.all(opts)

  voices[rand(voices.size)]
end

.say(text, opts = {}) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/voice.rb', line 50

def self.say(text, opts={})
  opts = {} unless opts.is_a?(Hash)
  opts[:voice] = self.get_rand(opts) if opts[:random]
  opts[:voice] ||= self.default 

  Say.say(text, opts)
  return nil
end