Class: Voicemaker::TTSParams

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#effectObject



32
33
34
# File 'lib/voicemaker/tts_params.rb', line 32

def effect
  @effect ||= input_params[:effect] || 'default'
end

#input_paramsObject (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_pitchObject



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_speedObject



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_volumeObject



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_formatObject



28
29
30
# File 'lib/voicemaker/tts_params.rb', line 28

def output_format
  @output_format ||= input_params[:output_format] || 'mp3'
end

#sample_rateObject



36
37
38
# File 'lib/voicemaker/tts_params.rb', line 36

def sample_rate
  @sample_rate ||= (input_params[:sample_rate] || 48000).to_s
end

#textObject



24
25
26
# File 'lib/voicemaker/tts_params.rb', line 24

def text
  @text ||= input_params[:text] || raise(InputError, "Missing parameter: text")
end

#voiceObject



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_paramsObject



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

#inspectObject



16
17
18
# File 'lib/voicemaker/tts_params.rb', line 16

def inspect
  %Q[#<Voicemaker::TTSParams api_params="#{api_params}"]
end