Class: Azure::TTS::Voices
- Inherits:
-
Object
- Object
- Azure::TTS::Voices
- Defined in:
- lib/azure/tts/voices.rb
Instance Attribute Summary collapse
-
#all ⇒ Object
readonly
Returns the value of attribute all.
Instance Method Summary collapse
- #fetch ⇒ Object
- #find(locale: nil, gender: nil, neural: nil) ⇒ Object
-
#initialize ⇒ Voices
constructor
A new instance of Voices.
Constructor Details
#initialize ⇒ Voices
Returns a new instance of Voices.
8 9 10 |
# File 'lib/azure/tts/voices.rb', line 8 def initialize fetch end |
Instance Attribute Details
#all ⇒ Object (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
#fetch ⇒ Object
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 |