voice 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/voice.rb +38 -6
- data/lib/voice/say.rb +45 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 662cd131af461ad2e9a805f4e549b1121e2e7f94
|
4
|
+
data.tar.gz: a778a5da6aff3fe9415a2e1000614b4d6434aa9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29cc0fc4a168fa79920611ecf96cbe5d264419d6abf0a6d948e7015a1650af84b7d645b27c44e89b9a04a04b0717546e660ec34665fa9b465a418f3b45767b86
|
7
|
+
data.tar.gz: b9b0929ed02dab694498c3d5eeec36be098d83a1248cd13f1c9d3247440df3bfeadc301cf3ed95b1df77c01a15b1525fad3b0ba7c492b91670e5f6618af6ae74
|
data/lib/voice.rb
CHANGED
@@ -2,21 +2,40 @@ require 'voice/say'
|
|
2
2
|
|
3
3
|
module Voice
|
4
4
|
|
5
|
-
PLATFORM_IS_OSX = (
|
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", "
|
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 =
|
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
|
data/lib/voice/say.rb
CHANGED
@@ -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
|
-
'
|
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
|
-
|
34
|
-
|
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}
|