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) ⇒ Speed

Returns a new instance of Speed.



31
32
33
34
35
36
37
38
39
40
# File 'lib/yandex_speech/speed.rb', line 31

def initialize(speed)
  @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)

Returns In range [(0.1)..3.0].

Returns:

  • (Float)

    In range [(0.1)..3.0]



29
30
31
# File 'lib/yandex_speech/speed.rb', line 29

def value
  @value
end

Class Method Details

.modesHash

Examples:

#1

list[:slow]      # ==> 0.5

#2

list[:wrong_key] # ==> nil

Returns:

  • (Hash)


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

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