gemmyrb 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f80e87943a486ead9bdcd3ede570b7cb164a0b46
4
- data.tar.gz: b5cb77bda55be569a5769c382abf3eae6ab61b92
3
+ metadata.gz: c85df937c8bef62c0ba555f2be7362884c68a7cd
4
+ data.tar.gz: 67c21db326658c1bed5466a90c7bfb7a11fe294e
5
5
  SHA512:
6
- metadata.gz: 53374471f968c7fbcd89050b98775b48bb3d1d0e9beca86920427605b5c826542939d4fecb2ede9f5201fa94ae4660c57fb96a65a38eda096f798a72eb3ad07f
7
- data.tar.gz: f1f5c63c5e7169bef3313dd590de806740755e21320a9385dd03b506734a818e1c2dcd8b881b912839a097992176e827a3cc0fa7d30f1f0e1cc4adb701dec395
6
+ metadata.gz: b1896357db258ea28d164afa5197a6a54f852aa85bdecac9934d715270962dbe11541521e8bd6377f30b9ad2f80901519b700e9f5550e750fbfd53c184b4bcd6
7
+ data.tar.gz: 7a3c16b87fdc64f60fe88aa224def18c57e4041665a3b1f3608530b2e13d4ac22845334be64605d978070538e825610a8e1b1bac7c55dd0de6fe0959c4808f22
@@ -1,7 +1,52 @@
1
1
  module Gemmy::Components::WordSpeaker
2
+ include ESpeak
3
+
2
4
  Gemmy.patches.each { |x| using x }
3
- def speak_sentence(sentence)
4
- byebug
5
- false
5
+
6
+ def speak_sentence(sentence, container_length=8, path: nil)
7
+ Gemmy::Components::WordSpeaker::Sentence.new(
8
+ sentence,
9
+ container_length,
10
+ ).speak(path: path)
6
11
  end
12
+
13
+ class Sentence
14
+
15
+ DefaultPitch = 1
16
+ DefaultSpeed = 250
17
+ DefaultGap = 10
18
+
19
+ %i{
20
+ sentence
21
+ sentence_syllables
22
+ container_length
23
+ }.each &m(:attr_reader)
24
+
25
+ def initialize(sentence, container_length)
26
+ @sentence = sentence
27
+ @sentence_syllables = @sentence.syllable_count.to_f
28
+ @container_length = container_length.to_f
29
+ end
30
+
31
+ def speak(path: nil)
32
+ pitch = DefaultPitch * diff_multiplier
33
+ speed = DefaultSpeed * diff_factor
34
+ gap = DefaultGap * diff_multiplier
35
+ espeak_opts = "-v english-us -p #{pitch} -s #{speed}"
36
+ if path
37
+ espeak_opts += " -w #{path}"
38
+ end
39
+ `espeak #{espeak_opts} "#{sentence}"`
40
+ end
41
+
42
+ def diff_factor
43
+ sentence_syllables / container_length
44
+ end
45
+
46
+ def diff_multiplier
47
+ 1.0 / diff_factor
48
+ end
49
+
50
+ end
51
+
7
52
  end
@@ -7,20 +7,39 @@ module Gemmy::Patches::StringPatch
7
7
 
8
8
  module InstanceMethods
9
9
 
10
+ module SyllableCount
11
+ def syllable_count
12
+ Odyssey.flesch_kincaid_re(self, true)["syllable_count"]
13
+ end
14
+ end
15
+
10
16
  module NlpSanitize
17
+ # Removes non-alphanumerics and newline
18
+ # Converts numbers to english
11
19
  def nlp_sanitize
12
20
  Gemmy.patch("string/i/alpha")
13
21
  ._alpha(self)
14
22
  .downcase
15
23
  .strip
24
+ .numbers_to_english
16
25
  .chomp
17
26
  end
18
27
  end
19
28
 
29
+ module NumbersToEnglish
30
+ # Converts a string's numbers to english words
31
+ def numbers_to_english
32
+ Gemmy.patch("string/i/numbers_to_english").numbers_to_english(self)
33
+ end
34
+ def self.numbers_to_english(string)
35
+ string.gsub(/(\d+)/) { |num| num.humanize }
36
+ end
37
+ end
38
+
20
39
  module Alpha
21
40
  def self._alpha(string, bang: false, strip_whitespace: false)
22
41
  fn = bang ? :gsub! : :gsub
23
- regex = /[^a-zA-Z#{'\s' unless strip_whitespace}]/
42
+ regex = /[^a-zA-Z0-9#{'\s' unless strip_whitespace}]/
24
43
  string.send fn, regex, ''
25
44
  end
26
45
  def alpha!(opts={})
data/lib/gemmy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Gemmy
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
data/lib/gemmy.rb CHANGED
@@ -8,6 +8,7 @@ require 'corefines'
8
8
  require 'sentence_interpreter'
9
9
  require 'engtagger'
10
10
  require 'odyssey'
11
+ require 'espeak'
11
12
 
12
13
  # Container class for all the functionality.
13
14
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemmyrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - max pleaner
@@ -170,6 +170,20 @@ dependencies:
170
170
  - - "~>"
171
171
  - !ruby/object:Gem::Version
172
172
  version: 0.2.0
173
+ - !ruby/object:Gem::Dependency
174
+ name: espeak-ruby
175
+ requirement: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - "~>"
178
+ - !ruby/object:Gem::Version
179
+ version: 1.0.3
180
+ type: :runtime
181
+ prerelease: false
182
+ version_requirements: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - "~>"
185
+ - !ruby/object:Gem::Version
186
+ version: 1.0.3
173
187
  description: ''
174
188
  email: maxpleaner@gmail.com
175
189
  executables: