Class: ESpeak::Voice

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

Overview

A voice that will be used for Speech

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Voice

Returns a new instance of Voice.



8
9
10
11
12
13
# File 'lib/espeak/voice.rb', line 8

def initialize(attributes)
  @language = attributes[:language]
  @name     = attributes[:name]
  @gender   = attributes[:gender]
  @file     = attributes[:file]
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



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

def file
  @file
end

#genderObject (readonly)

Returns the value of attribute gender.



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

def gender
  @gender
end

#languageObject (readonly)

Returns the value of attribute language.



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

def language
  @language
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Class Method Details

.allObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/espeak/voice.rb', line 15

def self.all
  voices = []
  result = IO.popen('espeak --voices', &:read)
  result.each_line do |line|
    next unless line.start_with?(' ') # header

    row = line.split
    voices << Voice.new(language: row[1], gender: row[2], name: row[3], file: row[4])
  end
  voices.freeze
end

.find_by_language(lang) ⇒ Object



27
28
29
# File 'lib/espeak/voice.rb', line 27

def self.find_by_language(lang)
  all.find { |v| v.language == lang.to_s }
end