Class: Voicemaker::Voices
- Inherits:
-
Object
- Object
- Voicemaker::Voices
- Extended by:
- Forwardable
- Defined in:
- lib/voicemaker/voices.rb
Overview
Provides easy and cached access to the list of available voices.
Instance Method Summary collapse
-
#all ⇒ Object
Returns all voices.
-
#find(id_or_webname) ⇒ Object
Returns a single voice, by Voice ID or Voice Webname.
-
#search(*queries) ⇒ Object
Returns a filtered list of voices, with all queries partially included in the voice parameter values.
Instance Method Details
#all ⇒ Object
Returns all voices
13 14 15 16 17 18 19 20 21 |
# File 'lib/voicemaker/voices.rb', line 13 def all @all ||= begin response = API.get "/list" result = response.dig 'data', 'voices_list' raise BadResponse, "Unexpected response: #{response}" unless result result.map { |voice| [voice['VoiceId'], voice] } .sort_by { |_, v| v['VoiceId'] }.to_h end end |
#find(id_or_webname) ⇒ Object
Returns a single voice, by Voice ID or Voice Webname
36 37 38 |
# File 'lib/voicemaker/voices.rb', line 36 def find(id_or_webname) all[id_or_webname] || all.find { |_, a| a['VoiceWebname'] == id_or_webname }&.last end |
#search(*queries) ⇒ Object
Returns a filtered list of voices, with all queries partially included in the voice parameter values
25 26 27 28 29 30 31 32 33 |
# File 'lib/voicemaker/voices.rb', line 25 def search(*queries) queries = nil if queries&.empty? return all unless queries all.select do |key, data| haystack = data.values.join(' ').downcase queries.all? { |query| haystack.include? query.downcase } end end |