Class: FreeTTS::Voice

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

Constant Summary collapse

DEFAULT_NAME =
"kevin16"

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(voice) ⇒ Voice

Returns a new instance of Voice.



9
10
11
# File 'lib/freetts/voice.rb', line 9

def initialize(voice)
  @voice_impl = voice
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/freetts/voice.rb', line 17

def method_missing(method, *args, &block)
  method = method.to_s
  java_method_name = case method
  when /\A(.*)=\Z/
    "set_#{ $1 }"
  when /\A(.*)\Z/
    "get_#{ $1 }"
  end

  if java_method_name and @voice_impl.respond_to?(java_method_name.to_sym)
    return @voice_impl.send(java_method_name.to_sym, *args)
  else
    error_message = "undefined method #{ method } for #{ self }:Voice"
    raise NoMethodError.new(error_message)
  end
end

Class Attribute Details

.voice_managerObject (readonly)

Returns the value of attribute voice_manager.



6
7
8
# File 'lib/freetts/voice.rb', line 6

def voice_manager
  @voice_manager
end

Class Method Details

.allObject



34
35
36
# File 'lib/freetts/voice.rb', line 34

def self.all
  voice_manager.get_voices.map { |voice| voice.get_name }
end

.for_name(voice_name) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/freetts/voice.rb', line 38

def self.for_name(voice_name)
  if voice = voice_manager.get_voice(voice_name)
    voice.allocate
    Voice.new(voice)
  else
    raise "no voice found for name \"#{ voice_name }\""
  end
end

Instance Method Details

#speak(saying) ⇒ Object



13
14
15
# File 'lib/freetts/voice.rb', line 13

def speak(saying)
  @voice_impl.speak(saying)
end