voice 0.0.2 → 0.0.3

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/voice.rb +38 -6
  3. data/lib/voice/say.rb +45 -4
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 60927d1a2d20b277edbb700402315b0042d835d1
4
- data.tar.gz: e28cd7e131c159164079f20f07b28af958b34ae2
3
+ metadata.gz: 662cd131af461ad2e9a805f4e549b1121e2e7f94
4
+ data.tar.gz: a778a5da6aff3fe9415a2e1000614b4d6434aa9b
5
5
  SHA512:
6
- metadata.gz: c1521dee3bad4d6b0a6dd71f0f965caa1013bfc10a25126a23458fcf772a66dac1c9ebcb348d26ecf259e098be8c2bf33a90038387759e515aa39f871685381c
7
- data.tar.gz: fbd2f135cf6e2686dc748d2af36c4c6872e7a563fd774886df056d192e03ba7b1e6393b44213e7a45b2cd25579263a86485b080ae952dbab4b5ae98b4798b551
6
+ metadata.gz: 29cc0fc4a168fa79920611ecf96cbe5d264419d6abf0a6d948e7015a1650af84b7d645b27c44e89b9a04a04b0717546e660ec34665fa9b465a418f3b45767b86
7
+ data.tar.gz: b9b0929ed02dab694498c3d5eeec36be098d83a1248cd13f1c9d3247440df3bfeadc301cf3ed95b1df77c01a15b1525fad3b0ba7c492b91670e5f6618af6ae74
@@ -2,21 +2,40 @@ require 'voice/say'
2
2
 
3
3
  module Voice
4
4
 
5
- PLATFORM_IS_OSX = (Object::RUBY_PLATFORM =~ /darwin/i)
5
+ PLATFORM_IS_OSX = (
6
+ Object::RUBY_PLATFORM =~ /darwin/i ||
7
+ Object::RUBY_PLATFORM =~ /java/i # thanks jruby
8
+ )
6
9
 
7
10
  DEFAULT_VOICE = 'Kathy'
8
11
 
9
12
  NOVELTY_VOICES = ["Albert", "Bad News", "Bahh", "Bells",
10
13
  "Boing", "Bubbles", "Cellos", "Deranged", "Good News",
11
- "Hysterical", "Pipe Organ", "Trinoides", "Whisper", "Zarvox"
14
+ "Hysterical", "Pipe Organ", "Trinoids", "Whisper", "Zarvox"
12
15
  ]
13
16
 
17
+
18
+ class << self
19
+ def detect_voices
20
+ voices = []
21
+ `say -v ?`.each_line do |l|
22
+ # Each line resembles: Agnes en_US # Isn't it nice to have a computer that will talk to you?
23
+ voice = l.split('#')[0]. # Grab everything before the comment marker
24
+ strip. # Drop the extra spaces at the end
25
+ split(' ') # Split into words
26
+ voices << voice[0..-2].join(' ') # Drop the last word (locale), and join the rest with a single space
27
+ end
28
+ return voices
29
+ end
30
+ protected :detect_voices
31
+ end
32
+
14
33
  if PLATFORM_IS_OSX
15
- @@all = `say -v ? | cut -f1 -d' '`.split("\n")
34
+ @@all = Voice.detect_voices
16
35
  @@novelty = @@all.select{|v| NOVELTY_VOICES.include?(v)}
17
36
  @@all = @@all - @@novelty
18
37
  else
19
- @@all = nil
38
+ @@all = nil
20
39
  @@novelty = nil
21
40
  end
22
41
 
@@ -34,6 +53,7 @@ module Voice
34
53
  end
35
54
 
36
55
  def self.default
56
+ return nil if @@all.nil?
37
57
  return DEFAULT_VOICE if @@all.include?(DEFAULT_VOICE)
38
58
  return @@all.first
39
59
  end
@@ -41,7 +61,7 @@ module Voice
41
61
  def self.get_rand(opts={})
42
62
  return nil if @@all.nil?
43
63
  opts = {} unless opts.is_a?(Hash)
44
-
64
+
45
65
  voices = self.all(opts)
46
66
 
47
67
  voices[rand(voices.size)]
@@ -50,10 +70,22 @@ module Voice
50
70
  def self.say(text, opts={})
51
71
  opts = {} unless opts.is_a?(Hash)
52
72
  opts[:voice] = self.get_rand(opts) if opts[:random]
53
- opts[:voice] ||= self.default
73
+ opts[:voice] ||= self.default
54
74
 
55
75
  Say.say(text, opts)
56
76
  return nil
57
77
  end
58
78
 
79
+ =begin
80
+ attr_reader :name
81
+
82
+ def initialize(name)
83
+ @name = name
84
+ end
85
+
86
+ def say(text)
87
+ Voice.say(text, {:voice => @name})
88
+ end
89
+ =end
90
+
59
91
  end
@@ -15,23 +15,64 @@ module Say
15
15
  }
16
16
 
17
17
  EMOTICONS = {
18
- '8==D' => 'dick',
19
18
  '<3' => 'heart',
19
+ '</3' => 'broken heart',
20
20
  ':)' => 'smiley face',
21
+ ':o)' => 'smiley face',
21
22
  '=)' => 'smiley face',
22
23
  ':-)' => 'smiley face',
24
+ ':3' => 'kitty smiley face',
23
25
  ';)' => 'winkey face',
24
26
  ';-)' => 'winkey face',
25
27
  '=D' => 'excited smiley face',
26
28
  ':D' => 'excited smiley face',
27
- '8==D~~' => 'dick with sperm shooting out'
29
+ ':(' => 'sad face',
30
+ '=(' => 'sad face',
31
+ ':-(' => 'sad face',
32
+ '>:(' => 'angry face',
33
+ 'D=' => 'horrors face',
34
+ 'D:' => 'horrors face',
35
+ 'o_O' => 'shock face',
36
+ 'o.O' => 'shock face',
37
+ ':O' => 'shock face',
38
+ ':o' => 'shock face',
39
+ '=O' => 'shock face',
40
+ '=o' => 'shock face',
41
+ ':P' => 'sticks tounge out face',
42
+ ':p' => 'sticks tounge out face',
43
+ '=P' => 'sticks tounge out face',
44
+ '=p' => 'sticks tounge out face',
45
+ ':*' => 'kiss face',
46
+ 'O:)' => 'angel face',
47
+ '0:)' => 'angel face',
48
+ '>:)' => 'evil face',
49
+ '>:-)' => 'evil face',
50
+ '=/' => 'meh face',
51
+ ':/' => 'meh face',
52
+ ':|' => 'no expression face',
53
+ '\o/' => 'yay',
54
+ 'o/\o' => 'high five',
55
+ '*\o/*' => 'cheerleader',
56
+ '@}-;-' => 'rose',
57
+ '=^_^=' => 'cat',
58
+ '8==D' => 'dick',
59
+ '8===D' => 'dong',
60
+ # sometimes phonetics helps a voice say dong more accurately
61
+ # which is super important, obviously
62
+ '8====D' => 'duh ong',
63
+ '8==D~~' => 'dick with sperm shooting out',
64
+ '8===D~~' => 'dong with sperm shooting out',
65
+ '8====D~~' => 'duh ong with sperm shooting out'
28
66
  }
29
67
 
30
68
  def self.say(text, opts={})
31
69
  return if text.empty?
70
+ opts = {} unless opts.is_a?(Hash)
32
71
 
33
- for key in EMOTICONS.keys.sort{|a,b| b.length <=> a.length}
34
- text.gsub!(key, " #{EMOTICONS[key]} ")
72
+ unless opts[:no_emoticons]
73
+ for key in EMOTICONS.keys.sort{|a,b| b.length <=> a.length}
74
+ text.gsub!(key, " #{EMOTICONS[key]} ")
75
+ end
35
76
  end
36
77
 
37
78
  for key in DICT.keys.sort{|a,b| b.length <=> a.length}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: voice
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Davy Stevenson