Class Request::TtsMessage
In: lib/violet/request.rb
Parent: Base::Event
Event Action AudioStream Choregraphy TtsMessage IdMessage SetEarsPosition EventCollection Enumerable Query GET_EARS_POSITION Base Request dot/f_8.png

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}>

Methods

new   to_url  

Constants

MIN_SPEED = 1
MAX_SPEED = 32_000
MIN_PITCH = 1
MAX_PITCH = 32_000

Public Class methods

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.

[Source]

     # File lib/violet/request.rb, line 184
184:     def initialize h
185:       raise ArgumentError.new('no :tts given') unless h[:tts]
186:       @h = h.dup
187: 
188:       [:speed,:pitch].each do |k|
189:         min = Helpers.constantize("#{self.class}::MIN_#{k.to_s.upcase}")
190:         max = Helpers.constantize("#{self.class}::MAX_#{k.to_s.upcase}")
191: 
192:         unless @h[k].to_i.between?(min,max)
193:           raise ArgumentError.new("#{k} values must be between #{min} and #{max}")
194:         else
195:           @h[k] = @h[k].to_i
196:         end if @h[k]
197:       end
198: 
199:       # to have a well formatted url
200:       @h[:tts]          = URI.escape @h[:tts]
201:       @h[:nabcasttitle] = URI.escape @h[:nabcasttitle] if @h[:nabcasttitle]
202:     end

Public Instance methods

[Source]

     # File lib/violet/request.rb, line 204
204:     def to_url
205:       for key,val in @h
206:         (url ||= Array.new) << "#{key}=#{val}" if val
207:       end
208:       url.sort
209:     end

[Validate]