class Motion::Speech::Speaker
Constants
- MultipleCallsToSpeakError
Attributes
events[R]
utterance[R]
Public Class Methods
new(speakable, options={}, &block)
click to toggle source
# File lib/motion/speech/speaker.rb, line 12 def initialize(speakable, options={}, &block) @events = EventBlock.new @utterance = Utterance.new(speakable, options) @spoken = false if block_given? if block.arity == 0 events.finish &block elsif block.arity == 1 block.call events else raise ArgumentError, 'block must accept either 0 or 1 arguments' end end end
speak(*args, &block)
click to toggle source
# File lib/motion/speech/speaker.rb, line 8 def self.speak(*args, &block) new(*args, &block).speak end
Public Instance Methods
message()
click to toggle source
# File lib/motion/speech/speaker.rb, line 56 def message utterance.message end
pause(boundary)
click to toggle source
# File lib/motion/speech/speaker.rb, line 36 def pause(boundary) synthesizer.pauseSpeakingAtBoundary boundary_from_symbol(boundary) end
paused?()
click to toggle source
# File lib/motion/speech/speaker.rb, line 48 def paused? synthesizer.paused? end
resume()
click to toggle source
# File lib/motion/speech/speaker.rb, line 44 def resume synthesizer.continueSpeaking end
speak()
click to toggle source
# File lib/motion/speech/speaker.rb, line 28 def speak raise MultipleCallsToSpeakError if @spoken synthesizer.speakUtterance utterance @spoken = true self end
speaking?()
click to toggle source
# File lib/motion/speech/speaker.rb, line 52 def speaking? synthesizer.speaking? end
stop(boundary)
click to toggle source
# File lib/motion/speech/speaker.rb, line 40 def stop(boundary) synthesizer.stopSpeakingAtBoundary boundary_from_symbol(boundary) end
synthesizer()
click to toggle source
# File lib/motion/speech/speaker.rb, line 60 def synthesizer @synthesizer ||= AVSpeechSynthesizer.new.tap { |s| s.delegate = self } end
Private Instance Methods
boundary_from_symbol(sym)
click to toggle source
# File lib/motion/speech/speaker.rb, line 86 def boundary_from_symbol(sym) case sym when :word AVSpeechBoundaryWord when :immediate AVSpeechBoundaryImmediate when Fixnum sym end end
speechSynthesizer(s, didFinishSpeechUtterance: utterance)
click to toggle source
# File lib/motion/speech/speaker.rb, line 66 def speechSynthesizer(s, didFinishSpeechUtterance: utterance) events.call :finish, self end