Class: Voicemaker::TTSParams
- Inherits:
-
Object
- Object
- Voicemaker::TTSParams
- Defined in:
- lib/voicemaker/tts_params.rb
Overview
Provides normalized access to all parameters needed for the TTS endpoint, including the auto identification of the Engine and Language based on voice ID, and including sensible defaults.
Instance Attribute Summary collapse
- #effect ⇒ Object
-
#input_params ⇒ Object
readonly
Returns the value of attribute input_params.
- #master_pitch ⇒ Object
- #master_speed ⇒ Object
- #master_volume ⇒ Object
- #output_format ⇒ Object
- #sample_rate ⇒ Object
- #text ⇒ Object
- #voice ⇒ Object
Instance Method Summary collapse
- #api_params ⇒ Object
-
#initialize(input_params = {}) ⇒ TTSParams
constructor
A new instance of TTSParams.
- #inspect ⇒ Object
Constructor Details
#initialize(input_params = {}) ⇒ TTSParams
Returns a new instance of TTSParams.
12 13 14 |
# File 'lib/voicemaker/tts_params.rb', line 12 def initialize(input_params = {}) @input_params = input_params end |
Instance Attribute Details
#effect ⇒ Object
32 33 34 |
# File 'lib/voicemaker/tts_params.rb', line 32 def effect @effect ||= input_params[:effect] || 'default' end |
#input_params ⇒ Object (readonly)
Returns the value of attribute input_params.
8 9 10 |
# File 'lib/voicemaker/tts_params.rb', line 8 def input_params @input_params end |
#master_pitch ⇒ Object
48 49 50 |
# File 'lib/voicemaker/tts_params.rb', line 48 def master_pitch @master_pitch ||= (input_params[:master_pitch] || 0).to_s end |
#master_speed ⇒ Object
40 41 42 |
# File 'lib/voicemaker/tts_params.rb', line 40 def master_speed @master_speed ||= (input_params[:master_speed] || 0).to_s end |
#master_volume ⇒ Object
44 45 46 |
# File 'lib/voicemaker/tts_params.rb', line 44 def master_volume @master_volume ||= (input_params[:master_volume] || 0).to_s end |
#output_format ⇒ Object
28 29 30 |
# File 'lib/voicemaker/tts_params.rb', line 28 def output_format @output_format ||= input_params[:output_format] || 'mp3' end |
#sample_rate ⇒ Object
36 37 38 |
# File 'lib/voicemaker/tts_params.rb', line 36 def sample_rate @sample_rate ||= (input_params[:sample_rate] || 48000).to_s end |
#text ⇒ Object
24 25 26 |
# File 'lib/voicemaker/tts_params.rb', line 24 def text @text ||= input_params[:text] || raise(InputError, "Missing parameter: text") end |
#voice ⇒ Object
20 21 22 |
# File 'lib/voicemaker/tts_params.rb', line 20 def voice @voice ||= find_voice || raise(InputError, "Missing or invalid parameter: voice") end |
Instance Method Details
#api_params ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/voicemaker/tts_params.rb', line 52 def api_params { "Engine" => engine, "VoiceId" => voice, "LanguageCode" => language, "OutputFormat" => output_format, "SampleRate" => sample_rate, "Effect" => effect, "MasterSpeed" => master_speed, "MasterVolume" => master_volume, "MasterPitch" => master_pitch, "Text" => text } end |
#inspect ⇒ Object
16 17 18 |
# File 'lib/voicemaker/tts_params.rb', line 16 def inspect %Q[#<Voicemaker::TTSParams api_params="#{api_params}"] end |