motion-speech 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d7d171c14e64dd90873710ad94277b660dd6c33
4
- data.tar.gz: 4e6522282418bc358c673fc365a3ac9ed1eada5f
3
+ metadata.gz: ce4943f7503b1ee12089b77bee68f4d4b3a5648e
4
+ data.tar.gz: 184ba85dab57de0d04d9ebd0b4300e7a68895a99
5
5
  SHA512:
6
- metadata.gz: 6547b64dde2bb648db4fc586b495c019381fd4069e660114d7acd176ee6010ebeec06d53c8ed500a0f538aac0006257367b7c230e70cd3361f0e9402dd9d5bfd
7
- data.tar.gz: b6344702f82cf2570820623067cf0480f1f09dc24065dafd7e8ff3293b29983331db3a127e4d8e5562d3ef2fb1e55f4f3ae73873bb89ff37b7e015048d7e37fb
6
+ metadata.gz: 32fe0a1bb77d695f28d94878db9d30bb434cb338f2e19d1c3e87a0c3cb5dc554cdc45e496f96e38ea15df2707ae086aa93eb0f91355a11ff8dc80f3b2f34e5b1
7
+ data.tar.gz: 94a5754c16a64e878b1c2abcc249d8fe9f2f9e6d27a52b87a6f282f461f01231080ce93496021926a15bff642cfbc804b2e381b589ab90c8236666e54f5dab6f
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # motion-speech
2
2
  Provides a simpler interface to using the AVSpeechSynthesizer related classes available natively in iOS 7.
3
3
 
4
+ ![Travis CI](https://secure.travis-ci.org/macfanatic/motion-speech.png?branch=master)
5
+
4
6
  ## Installation
5
7
 
6
8
  Add the following to your project's Gemfile to work with bundler:
@@ -78,6 +80,26 @@ Motion::Speech::Speaker.speak "lorem" do |events|
78
80
  end
79
81
  ```
80
82
 
83
+ ### Customizing the speech
84
+ You can pass several options directly through the speaker so that the spoken utterance is easily configured as you would like.
85
+
86
+ ```ruby
87
+
88
+ # To customize the rate
89
+ Motion::Speech::Speaker.speak "lorem", rate: :minimum # also accepts, :maximum, :default and any float between 0..1
90
+
91
+ # To customize the pitch
92
+ Motion::Speech::Speaker.speak "lorem", pitch: 2.0 # documentation specifies between 0.5 and 2.0, default being 1.0
93
+
94
+ # To customize the voice
95
+ voice_ref = AVSpeechSynthesisVoice.voiceWithLanguage("some_lang")
96
+ Motion::Speech::Speaker.speak "lorem", voice: voice_ref
97
+
98
+ # To customize the volume
99
+ Motion::Speech::Speaker.speak "lorem", volume: 0.5
100
+ ```
101
+
102
+
81
103
  ### Using methods for callbacks
82
104
  This is not unique to RubyMotion, but you can easily grab a block from a method on your class to use as a callback here too.
83
105
 
@@ -1,7 +1,7 @@
1
1
  module Motion
2
2
  module Speech
3
3
  class Speaker
4
- attr_reader :message, :options
4
+ attr_reader :events, :utterance
5
5
 
6
6
  MultipleCallsToSpeakError = Class.new(StandardError)
7
7
 
@@ -10,8 +10,8 @@ module Motion
10
10
  end
11
11
 
12
12
  def initialize(speakable, options={}, &block)
13
- @message = string_from_speakable(speakable)
14
- @options = options
13
+ @events = EventBlock.new
14
+ @utterance = Utterance.new(speakable, options)
15
15
  @spoken = false
16
16
 
17
17
  if block_given?
@@ -53,12 +53,8 @@ module Motion
53
53
  synthesizer.speaking?
54
54
  end
55
55
 
56
- def utterance
57
- return @utterance unless @utterance.nil?
58
-
59
- @utterance = AVSpeechUtterance.speechUtteranceWithString(message)
60
- @utterance.rate = options.fetch(:rate, 0.15)
61
- @utterance
56
+ def message
57
+ utterance.message
62
58
  end
63
59
 
64
60
  def synthesizer
@@ -87,18 +83,6 @@ module Motion
87
83
  events.call :resume, self
88
84
  end
89
85
 
90
- def events
91
- @events ||= EventBlock.new
92
- end
93
-
94
- def string_from_speakable(speakable)
95
- if speakable.respond_to?(:to_speakable)
96
- speakable.to_speakable
97
- else
98
- speakable
99
- end
100
- end
101
-
102
86
  def boundary_from_symbol(sym)
103
87
  case sym
104
88
  when :word
@@ -0,0 +1,54 @@
1
+ module Motion
2
+ module Speech
3
+ class Utterance < AVSpeechUtterance
4
+
5
+ def initialize(speakable, options={})
6
+ self.message = speakable
7
+ self.rate = options.fetch(:rate, 0.15)
8
+ self.pitch = options.fetch(:pitch, pitch)
9
+ self.voice = options.fetch(:voice, nil)
10
+ self.volume = options.fetch(:volume, volume)
11
+ end
12
+
13
+ def setSpeechString(speakable)
14
+ super string_from_speakable(speakable)
15
+ end
16
+
17
+ def setRate(multiplier)
18
+ super rate_for_symbol_or_float(multiplier)
19
+ end
20
+
21
+ alias_method :message, :speechString
22
+ alias_method :message=, :setSpeechString
23
+ alias_method :pitch, :pitchMultiplier
24
+ alias_method :pitch=, :setPitchMultiplier
25
+ alias_method :rate=, :setRate
26
+
27
+ private
28
+
29
+ def string_from_speakable(speakable)
30
+ if speakable.respond_to?(:to_speakable)
31
+ speakable.to_speakable
32
+ else
33
+ speakable
34
+ end
35
+ end
36
+
37
+ def rate_for_symbol_or_float(rate)
38
+ case rate
39
+ when :maximum
40
+ AVSpeechUtteranceMaximumSpeechRate
41
+ when :minimum
42
+ AVSpeechUtteranceMinimumSpeechRate
43
+ when :default
44
+ AVSpeechUtteranceDefaultSpeechRate
45
+ when Fixnum, Float
46
+ rate.to_f
47
+ else
48
+ raise ArgumentError, "invalid rate given: '#{rate}'"
49
+ end
50
+ end
51
+
52
+ end
53
+ end
54
+ end
@@ -1,5 +1,5 @@
1
1
  module Motion
2
2
  module Speech
3
- VERSION = "0.0.1"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -12,17 +12,6 @@ describe Motion::Speech::Speaker do
12
12
  speaker.message.should.be.equal "lorem"
13
13
  end
14
14
 
15
- it "accepts an options hash" do
16
- speaker = Motion::Speech::Speaker.new "lorem", key: :value
17
- speaker.options.should.be.equal key: :value
18
- end
19
-
20
- it "calls #to_speakable on sentence if supported" do
21
- sentence = Speakable.new("lorem")
22
- speaker = Motion::Speech::Speaker.new sentence
23
- speaker.message.should.be.equal sentence.to_speakable
24
- end
25
-
26
15
  it "raises exception if you make multiple calls to #speak" do
27
16
  speaker = Motion::Speech::Speaker.new "lorem"
28
17
  speaker.speak
@@ -39,19 +28,7 @@ describe Motion::Speech::Speaker do
39
28
  end
40
29
 
41
30
  it "returns an AVSpeechUtterance instance" do
42
- @speaker.utterance.should.be.instance_of AVSpeechUtterance
43
- end
44
-
45
- describe '#rate' do
46
-
47
- it "sets the speech rate to a reasonable default" do
48
- @speaker.utterance.rate.should.be.equal 0.15
49
- end
50
-
51
- it "allows me to override the rate" do
52
- speaker = Motion::Speech::Speaker.new "lorem", rate: 0.75
53
- speaker.utterance.rate.should.be.equal 0.75
54
- end
31
+ @speaker.utterance.should.be.instance_of Motion::Speech::Utterance
55
32
  end
56
33
  end
57
34
 
@@ -0,0 +1,87 @@
1
+ describe Motion::Speech::Utterance do
2
+
3
+ before do
4
+ @message = "lorem"
5
+ end
6
+
7
+ describe '#message' do
8
+ it "stores the message on initialization" do
9
+ utterance = Motion::Speech::Utterance.new(@message)
10
+ utterance.speechString.should.be.equal @message
11
+ end
12
+
13
+ it "provides a :message accessor" do
14
+ utterance = Motion::Speech::Utterance.new(@message)
15
+ utterance.message.should.be.equal @message
16
+
17
+ utterance.message = "change the message"
18
+ utterance.message.should.be.equal "change the message"
19
+ end
20
+
21
+ it "calls :to_speakable" do
22
+ sentence = Speakable.new("lorem")
23
+ utterance = Motion::Speech::Utterance.new(sentence)
24
+ utterance.message.should.be.equal sentence.to_speakable
25
+ end
26
+ end
27
+
28
+ describe '#pitch' do
29
+ it "provides a #pitch accessor" do
30
+ utterance = Motion::Speech::Utterance.new(@message)
31
+ utterance.pitchMultiplier.should.be.equal utterance.pitch
32
+ end
33
+
34
+ it "allows customization on initialization" do
35
+ utterance = Motion::Speech::Utterance.new(@message, pitch: 0.5)
36
+ utterance.pitch.should.be.equal 0.5
37
+ end
38
+ end
39
+
40
+ describe '#rate' do
41
+ it "provides a default rate" do
42
+ utterance = Motion::Speech::Utterance.new(@message)
43
+ utterance.rate.should.be.equal 0.15
44
+ end
45
+
46
+ it "overrides rate" do
47
+ utterance = Motion::Speech::Utterance.new(@message, rate: 1)
48
+ utterance.rate.should.be.equal 1
49
+ end
50
+
51
+ it "accepts a symbol for :minimum" do
52
+ utterance = Motion::Speech::Utterance.new(@message, rate: :minimum)
53
+ utterance.rate.should.be.equal AVSpeechUtteranceMinimumSpeechRate
54
+ end
55
+
56
+ it "accepts a symbol for :maximum" do
57
+ utterance = Motion::Speech::Utterance.new(@message, rate: :maximum)
58
+ utterance.rate.should.be.equal AVSpeechUtteranceMaximumSpeechRate
59
+ end
60
+
61
+ it "accepts a symbol for :default" do
62
+ utterance = Motion::Speech::Utterance.new(@message, rate: :default)
63
+ utterance.rate.should.be.equal AVSpeechUtteranceDefaultSpeechRate
64
+ end
65
+
66
+ it "raises an error when passed an unrecognized symbol" do
67
+ @utterance = Motion::Speech::Utterance.new @message
68
+ ->{ @utterance.rate = :unknown }.should.raise(ArgumentError)
69
+ end
70
+ end
71
+
72
+ describe '#voice' do
73
+ it "allows customization on initialization" do
74
+ voice = AVSpeechSynthesisVoice.speechVoices.last
75
+ utterance = Motion::Speech::Utterance.new(@message, voice: voice)
76
+ utterance.voice.should.be.equal voice
77
+ end
78
+ end
79
+
80
+ describe '#volumne' do
81
+ it "allows customization on initialization" do
82
+ utterance = Motion::Speech::Utterance.new(@message, volume: 0.123)
83
+ utterance.volume.should.be.equal 0.123
84
+ end
85
+ end
86
+
87
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion-speech
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Brewer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-26 00:00:00.000000000 Z
11
+ date: 2014-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -36,10 +36,12 @@ files:
36
36
  - lib/motion-speech.rb
37
37
  - lib/motion/speech/event_block.rb
38
38
  - lib/motion/speech/speaker.rb
39
+ - lib/motion/speech/utterance.rb
39
40
  - lib/motion/speech/version.rb
40
41
  - spec/event_block_spec.rb
41
42
  - spec/helpers/speakable.rb
42
43
  - spec/speaker_spec.rb
44
+ - spec/utterance_spec.rb
43
45
  homepage: https://github.com//motion-speech
44
46
  licenses:
45
47
  - MIT
@@ -68,3 +70,4 @@ test_files:
68
70
  - spec/event_block_spec.rb
69
71
  - spec/helpers/speakable.rb
70
72
  - spec/speaker_spec.rb
73
+ - spec/utterance_spec.rb