Class: Vocalware::Voice
- Inherits:
-
Object
- Object
- Vocalware::Voice
- Defined in:
- lib/vocalware/voice.rb
Overview
Voice encapsulates voice parameters like engine_id
, voice_id
, lang_id
etc. And provides class method to look up voice by parameters.
Instance Attribute Summary collapse
- #description ⇒ Object readonly
- #engine_id ⇒ Object readonly
- #gender ⇒ Object readonly
- #lang ⇒ Object readonly
- #lang_id ⇒ Object readonly
- #name ⇒ Object readonly
- #voice_id ⇒ Object readonly
Class Method Summary collapse
-
.all ⇒ Array<Vocalware::Voice>
Get all voices.
-
.find(attrs) ⇒ Object
Find a voice by attributes.
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Voice
constructor
A new instance of Voice.
-
#match?(attributes) ⇒ Boolean
Verify that the voice matches the passed attributes.
Constructor Details
#initialize(attributes) ⇒ Voice
Returns a new instance of Voice.
74 75 76 77 78 79 80 |
# File 'lib/vocalware/voice.rb', line 74 def initialize(attributes) attributes.each do |attr, value| self.instance_variable_set("@#{attr}", value) end @lang_id = LANGUAGES[lang.to_sym] || raise(Error, "Unknown lang #{lang.inspect}") end |
Instance Attribute Details
#description ⇒ Object (readonly)
28 29 30 |
# File 'lib/vocalware/voice.rb', line 28 def description @description end |
#engine_id ⇒ Object (readonly)
12 13 14 |
# File 'lib/vocalware/voice.rb', line 12 def engine_id @engine_id end |
#gender ⇒ Object (readonly)
25 26 27 |
# File 'lib/vocalware/voice.rb', line 25 def gender @gender end |
#lang ⇒ Object (readonly)
15 16 17 |
# File 'lib/vocalware/voice.rb', line 15 def lang @lang end |
#lang_id ⇒ Object (readonly)
31 32 33 |
# File 'lib/vocalware/voice.rb', line 31 def lang_id @lang_id end |
#name ⇒ Object (readonly)
18 19 20 |
# File 'lib/vocalware/voice.rb', line 18 def name @name end |
#voice_id ⇒ Object (readonly)
22 23 24 |
# File 'lib/vocalware/voice.rb', line 22 def voice_id @voice_id end |
Class Method Details
.all ⇒ Array<Vocalware::Voice>
Get all voices.
36 37 38 |
# File 'lib/vocalware/voice.rb', line 36 def self.all @all ||= send(:load_all) end |
.find(attrs) ⇒ Object
Find a voice by attributes.
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/vocalware/voice.rb', line 45 def self.find(attrs) voices = all.select {|voice| voice.match?(attrs) } raise(FindVoiceError, "No voice found using #{attrs.inspect}" ) if voices.empty? raise(FindVoiceError, "More than 1 voice found using #{attrs.inspect}" ) if voices.size > 1 voices.first end |
Instance Method Details
#match?(attributes) ⇒ Boolean
Verify that the voice matches the passed attributes.
87 88 89 90 91 92 |
# File 'lib/vocalware/voice.rb', line 87 def match?(attributes) attributes.each do |attr, val| return false if send(attr).to_s != val.to_s end true end |