Class: YandexSpeechApi::Speed

Inherits:
Object
  • Object
show all
Defined in:
lib/yandex_speech/speed.rb

Defined Under Namespace

Classes: SpeedModeNotAllowed, SpeedValueNotInRange

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(speed = :standard) ⇒ Speed

Returns a new instance of Speed


36
37
38
39
40
41
42
43
44
45
# File 'lib/yandex_speech/speed.rb', line 36

def initialize(speed = :standard)
  @value = if speed.is_a? Numeric
             speed.round 2
           else
             Speed.modes[speed.downcase.to_sym]
           end

  raise SpeedModeNotAllowed, speed if @value.nil?
  raise SpeedValueNotInRange, @value unless speed_in_valid_range? @value
end

Instance Attribute Details

#valueFloat (readonly)


34
35
36
# File 'lib/yandex_speech/speed.rb', line 34

def value
  @value
end

Class Method Details

.modesFloat?

Returns numeric value for selected mode.


17
18
19
20
21
22
23
24
25
# File 'lib/yandex_speech/speed.rb', line 17

def modes
  {
    slowest:  0.1, # minimal allowed speed
    slow:     0.5,
    standard: 1.0, # default
    fast:     1.5,
    fastest:  3.0  # maximal allowed speed
  }
end