Class: Azure::TTS::Voices

Inherits:
Object
  • Object
show all
Defined in:
lib/azure/tts/voices.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeVoices

Returns a new instance of Voices.



8
9
10
# File 'lib/azure/tts/voices.rb', line 8

def initialize
  fetch
end

Instance Attribute Details

#allObject (readonly)

Returns the value of attribute all.



6
7
8
# File 'lib/azure/tts/voices.rb', line 6

def all
  @all
end

Instance Method Details

#fetchObject

Raises:



12
13
14
15
16
17
# File 'lib/azure/tts/voices.rb', line 12

def fetch
  response = Azure::TTS.api.voices.get
  raise RequestError, response unless response.success?

  @all = response.body.map { |data| Voice.new(data) }
end

#find(locale: nil, gender: nil, neural: nil) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/azure/tts/voices.rb', line 19

def find(locale: nil, gender: nil, neural: nil)
  voices = all
  voices = voices.select { |voice| voice.locale == locale } if locale
  voices = voices.select { |voice| voice.gender == gender } if gender
  voices = voices.sort_by { |voice| voice.neural? ? 0 : 1 } if neural
  voices.first
end