Class: Request::TtsMessage
- Inherits:
-
Base::Event
- Object
- Base::Event
- Request::TtsMessage
- Defined in:
- lib/violet/request.rb
Overview
TtsMessage events are used to Text-To-Speach messages.
Examples
TtsMessage.new :tts => "oups!" # => #<Request::TtsMessage:0x2ab1ba3cd8e0 @h={:tts=>"oups!"}>
TtsMessage.new :tts => "allez hop !", :speed => 200, :voice => "caroline22k" # => #<Request::TtsMessage:0x2ab1ba3b8e40 @h={:tts=>"allez%20hop%20!", :speed=>200, :voice=>"caroline22k"}>
TtsMessage.new :tts => "GNU is Not Unix", :speed => 200, :pitch => 400 # => #<Request::TtsMessage:0x2ab1ba3a9580 @h={:tts=>"GNU%20is%20Not%20Unix", :speed=>200, :pitch=>400}>
Constant Summary collapse
- MIN_SPEED =
1
- MAX_SPEED =
32_000
- MIN_PITCH =
1
- MAX_PITCH =
32_000
Instance Method Summary collapse
-
#initialize(h) ⇒ TtsMessage
constructor
take an hash in parameter, with at least
:tts
key. - #to_url ⇒ Object
Methods inherited from Base::Event
Constructor Details
#initialize(h) ⇒ TtsMessage
take an hash in parameter, with at least :tts
key. the :tts
key must be a string encoded in UTF-8. Optionals parameters are :speed
and :pitch
, they must be between MIN_SPEED and MAX_SPEED (MIN_PITCH and MAX_PITCH respectively). Default values for speed/pitch is 100.
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/violet/request.rb', line 184 def initialize h raise ArgumentError.new('no :tts given') unless h[:tts] @h = h.dup [:speed,:pitch].each do |k| min = Helpers.constantize("#{self.class}::MIN_#{k.to_s.upcase}") max = Helpers.constantize("#{self.class}::MAX_#{k.to_s.upcase}") unless @h[k].to_i.between?(min,max) raise ArgumentError.new("#{k} values must be between #{min} and #{max}") else @h[k] = @h[k].to_i end if @h[k] end # to have a well formatted url @h[:tts] = URI.escape @h[:tts] @h[:nabcasttitle] = URI.escape @h[:nabcasttitle] if @h[:nabcasttitle] end |
Instance Method Details
#to_url ⇒ Object
204 205 206 207 208 209 |
# File 'lib/violet/request.rb', line 204 def to_url for key,val in @h (url ||= Array.new) << "#{key}=#{val}" if val end url.sort end |