Class: Motion::Speech::Speaker
- Inherits:
-
Object
- Object
- Motion::Speech::Speaker
- Defined in:
- lib/motion/speech/speaker.rb
Constant Summary collapse
- MultipleCallsToSpeakError =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#events ⇒ Object
readonly
Returns the value of attribute events.
-
#utterance ⇒ Object
readonly
Returns the value of attribute utterance.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(speakable, options = {}, &block) ⇒ Speaker
constructor
A new instance of Speaker.
- #message ⇒ Object
- #pause(boundary) ⇒ Object
- #paused? ⇒ Boolean
- #resume ⇒ Object
- #speak ⇒ Object
- #speaking? ⇒ Boolean
- #stop(boundary) ⇒ Object
- #synthesizer ⇒ Object
Constructor Details
#initialize(speakable, options = {}, &block) ⇒ Speaker
Returns a new instance of Speaker.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/motion/speech/speaker.rb', line 12 def initialize(speakable, ={}, &block) @events = EventBlock.new @utterance = Utterance.new(speakable, ) @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 |
Instance Attribute Details
#events ⇒ Object (readonly)
Returns the value of attribute events.
4 5 6 |
# File 'lib/motion/speech/speaker.rb', line 4 def events @events end |
#utterance ⇒ Object (readonly)
Returns the value of attribute utterance.
4 5 6 |
# File 'lib/motion/speech/speaker.rb', line 4 def utterance @utterance end |
Class Method Details
.speak(*args, &block) ⇒ Object
8 9 10 |
# File 'lib/motion/speech/speaker.rb', line 8 def self.speak(*args, &block) new(*args, &block).speak end |
Instance Method Details
#message ⇒ Object
56 57 58 |
# File 'lib/motion/speech/speaker.rb', line 56 def utterance. end |
#pause(boundary) ⇒ Object
36 37 38 |
# File 'lib/motion/speech/speaker.rb', line 36 def pause(boundary) synthesizer.pauseSpeakingAtBoundary boundary_from_symbol(boundary) end |
#paused? ⇒ Boolean
48 49 50 |
# File 'lib/motion/speech/speaker.rb', line 48 def paused? synthesizer.paused? end |
#resume ⇒ Object
44 45 46 |
# File 'lib/motion/speech/speaker.rb', line 44 def resume synthesizer.continueSpeaking end |
#speak ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/motion/speech/speaker.rb', line 28 def speak raise MultipleCallsToSpeakError if @spoken synthesizer.speakUtterance utterance @spoken = true self end |
#speaking? ⇒ Boolean
52 53 54 |
# File 'lib/motion/speech/speaker.rb', line 52 def speaking? synthesizer.speaking? end |
#stop(boundary) ⇒ Object
40 41 42 |
# File 'lib/motion/speech/speaker.rb', line 40 def stop(boundary) synthesizer.stopSpeakingAtBoundary boundary_from_symbol(boundary) end |
#synthesizer ⇒ Object
60 61 62 |
# File 'lib/motion/speech/speaker.rb', line 60 def synthesizer @synthesizer ||= AVSpeechSynthesizer.new.tap { |s| s.delegate = self } end |