Class: Mac::TTS

Inherits:
Object
  • Object
show all
Defined in:
lib/mactts.rb

Defined Under Namespace

Classes: InvalidVoiceException, SayCommandNotFoundException

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ TTS

Initialize the class with a sane set of defaults that can be overriden with the opts hash:

opts = { :say_command  => '/path/to/say', 
         :tempfile     => 'tempfile_name',
         :voice        => :valid_voice
}


31
32
33
34
35
# File 'lib/mactts.rb', line 31

def initialize(opts = {})
  @say_command = opts[:say_command] || '/usr/bin/say'
  @tempfile    = opts[:tempfile]    || 'mactts'
  @voice       = opts[:voice]       || :fred
end

Instance Attribute Details

#say_commandObject

Returns the value of attribute say_command.



20
21
22
# File 'lib/mactts.rb', line 20

def say_command
  @say_command
end

#tempfileObject

Returns the value of attribute tempfile.



20
21
22
# File 'lib/mactts.rb', line 20

def tempfile
  @tempfile
end

#voiceObject

Returns the value of attribute voice.



20
21
22
# File 'lib/mactts.rb', line 20

def voice
  @voice
end

Class Method Details

.say(text, voice = :fred) ⇒ Object

Class method to make it easy to use the defaults to say your text.

Usage:

Mac::TTS.say('This is my text!', :alex)


42
43
44
45
# File 'lib/mactts.rb', line 42

def self.say(text, voice = :fred)
  mactts = TTS.new(:voice => voice)
  mactts.say(text)
end

.valid_voicesObject

An array of valid voice names recognized by the say command Taken from the Speech preference pane.



61
62
63
64
65
# File 'lib/mactts.rb', line 61

def self.valid_voices
  [ :alex, :fred, :bruce, :junior, :ralph, :agnes, :kathy, :princess, :vicki, :victoria,
    :albert, :bad, :bahh, :bells, :boing, :bubbles, :cellos, :deranged, :good, 
    :hysterical, :pipe, :trinoids, :whisper, :zarvox ]
end

Instance Method Details

#say(text) ⇒ Object

Use TTS to speak your text, with the voice specified in @voice.

Usage:

mactts = Mac::TTS.new
mactts.say('This is my text!')


53
54
55
56
57
# File 'lib/mactts.rb', line 53

def say(text)
  check_for_command
  validate_voice
  perform_say(text, @voice)
end